Pass a variable to a report

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

Guest

Does anyone know how I could 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

Thanks in advance.
 
Hi there
Does anyone know how I could 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.

You can use OpenArgs. To open the report passing an argument, use:

DoCmd.OpenReport "MyReport", acViewPreview, , , , "My argument"

To access it inside the unbound text field, use:

=[OpenArgs]

which in the above case will show the text "My argument"


Cheers,
Martin
 
Declare a public variable in a module, eg. MyVar. At the
end of your subroutine set its value to the calculated
value.

Write a simple function in a module, like:
Function Var_To_Report()
Var_To_Report = MyVar
End Function

In your report, set the control source property of the
field to Var_To_Report. The job is done, and works which
ever way you open the report.

HTH,
Nikos
-----Original Message-----
Hi there
Does anyone know how I could 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.

You can use OpenArgs. To open the report passing an argument, use:

DoCmd.OpenReport "MyReport", acViewPreview, , , , "My argument"

To access it inside the unbound text field, use:

=[OpenArgs]

which in the above case will show the text "My argument"


Cheers,
Martin


.
 
Hi Martin

Thanks for your help. Unfortunately, there doesn't appear to be an OpenArgs option for the OpenReport command

Regards

Jared
 
Hi Jared
Unfortunately, there doesn't appear to be an OpenArgs option for the
OpenReport command.

Which version of Access are we talking about? At least starting with
Access XP (2002) there is such an option...


All the best,
Martin

Jedster said:
Hi Martin,

Thanks for your help. Unfortunately, there doesn't appear to be an
OpenArgs option for the OpenReport command.
 
Hi Nikos

Please excuse my lack of experience, but I'm also having problems with your approach. This is my code so far which, perhaps, you could kindly check out for me

For the control button on the form

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

For the module entitled "Variables"

Function VarToReport(
VarToReport = StoreClas
End Functio

With the control source for the text box on the report set to VarToReport as suggested, it merely throws up an "Enter Parameter Value" dialog box for VarToReport

I'm starting to sense the likelihood that I've missed something remarkably simple with horrendous embarrassment to ensue...!
 
If I get this right, you want to somehow pass the value of Frame13 on the
form to the control in the report?
If that's the case, then you are very close:
Line 2 of your Private Sub Preview_Click() assigns variable StoreClass the
current value of Frame13.
Control source for the text box on the report set to =VarToReport () (make
sure you have the = at the beginning and the () at the end!)
Variable StoreClass needs to be declared as public in the declarations
section of a general module, say "Variables": Public StoreClass as String
(or whatever).

Regards,
Nikos



Jedster said:
Hi Nikos,

Please excuse my lack of experience, but I'm also having problems with
your approach. This is my code so far which, perhaps, you could kindly
check out for me:
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

For the module entitled "Variables":

Function VarToReport()
VarToReport = StoreClass
End Function

With the control source for the text box on the report set to VarToReport
as suggested, it merely throws up an "Enter Parameter Value" dialog box for
VarToReport.
I'm starting to sense the likelihood that I've missed something remarkably
simple with horrendous embarrassment to ensue...!
 
Back
Top