Pass a variable to a report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how I can pass a variable from a subroutine to an unbound field on a report? The subroutine is triggered by the on click event of a control button on a form.

This is my code so far where I have attempted to declare a variable within a module.

Firstly, for the control button on the form:

Private Sub Preview_Click()
ReportName = "Countsheet"
StoreClass = Me.Frame13
VarToReport
DoCmd.OpenReport _
ReportName:=ReportName, _
View:=acViewPreview, _
WhereCondition:="SC<=" & Me.Frame13 & "AND Department='" & Me.Frame28 & "'"
End Sub

Secondly, for a module entitled "Variables":

Function VarToReport()
VarToReport = StoreClass
End Function

The control source for the text box on the report has been set to VarToReport, however, it merely produces an "Enter Parameter Value" dialog box for VarToReport. (Due to my lack of experience, I guess the answer may well be something quite simple...!).
 
Try making the variable StoreClass a Global, set its
value, then in the textbox call the Function VarToReport
(). I think that should work 4 u.

-----Original Message-----
Does anyone know how I can pass a variable from a
subroutine to an unbound field on a report? The
subroutine is triggered by the on click event of a control
button on a form.
This is my code so far where I have attempted to declare a variable within a module.

Firstly, for the control button on the form:

Private Sub Preview_Click()
ReportName = "Countsheet"
StoreClass = Me.Frame13
VarToReport
DoCmd.OpenReport _
ReportName:=ReportName, _
View:=acViewPreview, _
WhereCondition:="SC<=" & Me.Frame13 & "AND
Department='" & Me.Frame28 & "'"
End Sub

Secondly, for a module entitled "Variables":

Function VarToReport()
VarToReport = StoreClass
End Function

The control source for the text box on the report has
been set to VarToReport, however, it merely produces
an "Enter Parameter Value" dialog box for VarToReport.
(Due to my lack of experience, I guess the answer may well
be something quite simple...!).
 
-----Original Message-----
Does anyone know how I can pass a variable from a
subroutine to an unbound field on a report? The
subroutine is triggered by the on click event of a control
button on a form.
This is my code so far where I have attempted to declare a variable within a module.

Firstly, for the control button on the form:

Private Sub Preview_Click()
ReportName = "Countsheet"
StoreClass = Me.Frame13
VarToReport
DoCmd.OpenReport _
ReportName:=ReportName, _
View:=acViewPreview, _
WhereCondition:="SC<=" & Me.Frame13 & "AND
Department='" & Me.Frame28 & "'"
End Sub

Secondly, for a module entitled "Variables":

Function VarToReport()
VarToReport = StoreClass
End Function

The control source for the text box on the report has
been set to VarToReport, however, it merely produces
an "Enter Parameter Value" dialog box for VarToReport.
(Due to my lack of experience, I guess the answer may well
be something quite simple...!).

in the control source fo the text box don't forget the "()"

= VarToReport()
 
Back
Top