Pass a variable to a report

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...!).
 
N

none

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...!).
 
G

Guest

-----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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top