Second thoughts: if you need to open the report in preview mode or if you
need to open the report with or without an argument, then here's the
replacement code:
1. For the report's class module:
Private mstrFooterText As String
Private Sub Report_Open(Cancel As Integer)
' Capture the OpenArgs string in the report's Open event,
' converting a missing argument to a zero-length string:
mstrFooterText = Nz(Me.OpenArgs)
End Sub
Private Function GetFooterText() As String
' Call this function from the txtFooter control's
' ControlSource property, using the syntax:
' =GetFooterText()
GetFooterText = mstrFooterText
End Function
2. And for the standard module:
Public Sub PreviewReport1_WithoutArgument()
DoCmd.OpenReport "Report1", acViewPreview
End Sub
Public Sub PreviewReport1_WithArgument()
Dim objRPT As Access.Report
Dim fIsOpen As Boolean
Dim I As Integer
' Open report in Preview mode, using the OpenArgs
' argument to pass string to report:
DoCmd.OpenReport "Report1", acViewPreview, , , , "Home Office Copy"
WasteTimeWhileHomeOfficeCopyIsOpen:
fIsOpen = False
For Each objRPT In Access.Reports
If objRPT.Name = "Report1" Then
fIsOpen = True
Exit For
End If
Next
If fIsOpen Then
DoEvents
For I = 1 To 1000
' Waste time.
Next
GoTo WasteTimeWhileHomeOfficeCopyIsOpen
End If
' If we're here, the report has been closed.
' Open report again in Preview mode with new argument:
DoCmd.OpenReport "Report1", acViewPreview, , , , "Head Office Copy"
End Sub
Public Sub PrintReport1_WithoutPreview()
DoCmd.OpenReport "Report1", , , , , "Home Office Copy"
DoCmd.OpenReport "Report1", , , , , "Head Office Copy"
End Sub
Geoff