Passing arguments to report

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

Guest

I am using Access 2000, and am trying to set the .visible property of a label
on a report from the code. Is this possible? If so, does anyone have an
example?

Thanks.
 
I should also add that I access the report from different forms. So,
depending on which form I have open determines what label I want visible.
 
I should also add that I access the report from different forms. So,
depending on which form I have open determines what label I want visible.

Great, except that it would be good to know which version of Access
you are using.

If your version has the OpenArgs argument as part of the
DoCmd.OpenReport method, you can pass the form name to the report:
DoCmd.OpenReport "ReportName", , , , , , Me.Name

Then code the Report's Report Header format event:
If Me.OpenArgs = "FormA" Then
Me!LabelName.Visible = false
Elseif Me.OpenArgs = "FormB" Then
Me!OtherLabel.Visible = false
Else
Me!ThirdLable.Visible = false
End If

If you are using an earlier version post back.
 
Thanks for the reply,

I thought I had mentioned the version in the first post. Sorry. I am using
Access 2000 which I do not beleive has the OpenArgs Method for reports.

Thanks again.
 
Thanks for the reply,

I thought I had mentioned the version in the first post. Sorry. I am using
Access 2000 which I do not beleive has the OpenArgs Method for reports.

Thanks again.

I use Access 2002, and I don't remember if Access 2000 has it or not.
You can check rather easily.
Open any code window and type OpenReport (don't space after the "T")
Press the F1 key and the Help window will open on the OpenReport
method.
Look at the available arguments.
It will be the last argument listed.
expression.OpenReport(ReportName, View, FilterName, WhereCondition,
WindowMode, OpenArgs)

If you don't have it, then you can use something like this.
Note: Do NOT close the calling form (FormA or FormB) when running the
report.

Code the Report's Report Header Format event:
If CurrentProject.AllForms("FormA").IsLoaded Then
Me!LabelName.Visible = false
ElseIf CurrentProject.AllForms("FormB").IsLoaded Then
Me!OtherLabel.Visible = false
Else
Me!ThirdLable.Visible = false
End If

Close the form (You can close a form without error, even if it's not
open) in the Report's Close event:
DoCmd.close acForm, "FormA"
DoCmd.close acForm, "FormB"
DoCmd.close acForm, "FormC"
etc.
 
Back
Top