Create a form with two buttons and assign the "On Click" code as follows. This drives the OpenArgs to the report (which is only available on an 'on open' event.
Code:
Private Sub PrintButton_RptSObyProductLevel0_Click()
DoCmd.OpenReport "Rpt - SO by Product2", acViewPreview, , , , "Level0"
End Sub
Code:
Private Sub PrintButton_RptSObyProductLevel1_Click()
DoCmd.OpenReport "Rpt - SO by Product2", acViewPreview, , , , "Level1"
End Sub
Then, within the "On Open" of the given Report, enter the following:
Code:
Private Sub Report_Open(Cancel As Integer)
If OpenArgs = "Level0" Then
Me.Section(0).Visible = False
Else
Me.Section(0).Visible = True
End If
End Sub
Errors out in the old report, works like a charm in a direct copy of the report with a "2" appended to the name.
And yes, I'm in the process of removing my report name spaces
So delete the old report, rename the second to that and work from there?
Perhaps corrupted, but in all the time I have use Access, I have never had a corrupted object that I can remember?
Just lucky there, as I would not consider myself lucky really.
Private Sub Report_Load()
Me.Auto_Header0.Caption = Me.OpenArgs & " Report"
End Sub
Same applies to a Form
Code:
Private Sub Form_Load()
' Add which period we are showing to form title label
If Not IsNull(Me.OpenArgs) Then
Me.lblTitle.Caption = Me.lblTitle.Caption & Me.OpenArgs
Me.RecordSource = "qry" & Me.OpenArgs
Me.cmdReport.Visible = True
Else
Me.cmdReport.Visible = False
End If
DoCmd.GoToRecord acDataForm, Me.Name, acLast
End Sub