Printing multiple reports

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

Guest

How can I print 2 reports from the same command button on a form? I have a
command button that currently filters to the specific record on the screen
and then prints the report that I have coded in my command button. Say I want
to add another report to also print at the same time and using the same
filter, how would I set that up in my command button?
 
It depends how the report is 'filtered'. If its by having a query which
references a control on the form as a parameter as its RecordSource property
then the second report would also need to be based on a query with the same
parameter. If, on the other hand, its filtered by means of the
WhereCondition of the OpenReport method then you just call the OpenReport
method twice in the button's Click event procedure, e.g.

Dim strCriteria As String

strCriteria = "MyID = " & Me.MyID

' first make sure current record is saved
RunCommand acCmdSaveRecord
' then print both reports
DoCmd.OpenReport "MyReport1", WhereCondtion:=strCriteria
DoCmd.OpenReport "MyReport2", WhereCondtion:=strCriteria

Ken Sheridan
Stafford, England
 
Squirrel,

Presumably the code behind your button has a line that is some
variation of the following:

DoCmd.OpenReport "MyReport", acNormal, , "RecordID=" & Me!RecordID

You should be able to print the 2nd report by finding that line,
copying it, and modifying the copy to print the 2nd report:

DoCmd.OpenReport "MyReport", acNormal, , "RecordID=" & Me!RecordID
DoCmd.OpenReport "MyReport2", acNormal, , "RecordID=" & Me!RecordID

It would be better programming structure to put the filter in a
variable, instead of duplicating the expression:

Dim sFilter as String

sFilter = "RecordID=" & Me!RecordID
DoCmd.OpenReport "MyReport", acNormal, , sFilter
DoCmd.OpenReport "MyReport2", acNormal, , sFilter

Jerry
 
Ken,
Here is what I have behind that command button. How should I add the second
report to it?

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
stDocName = "rptCorrectiveActionForm"
DoCmd.OpenReport stDocName, acPreview, "qryRMAFilter"
DoCmd.RunCommand acCmdFitToWindow

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
MsgBox err.Description
Resume Exit_cmdPreview_Click
End Sub
 
Providing the qryRMAFilter query can apply the necessary filter to both
reports you need to reassign the second report's name to the stDocName
variable and call the open report method again:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
stDocName = "rptCorrectiveActionForm"
DoCmd.OpenReport stDocName, acPreview, "qryRMAFilter"
DoCmd.RunCommand acCmdFitToWindow

stDocName = "YourSecondReportName"
DoCmd.OpenReport stDocName, acPreview, "qryRMAFilter"
DoCmd.RunCommand acCmdFitToWindow

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
MsgBox err.Description
Resume Exit_cmdPreview_Click
End Sub

Ken Sheridan
Stafford, England
 
Worked like a charm! Thanks Ken!

Ken Sheridan said:
Providing the qryRMAFilter query can apply the necessary filter to both
reports you need to reassign the second report's name to the stDocName
variable and call the open report method again:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
stDocName = "rptCorrectiveActionForm"
DoCmd.OpenReport stDocName, acPreview, "qryRMAFilter"
DoCmd.RunCommand acCmdFitToWindow

stDocName = "YourSecondReportName"
DoCmd.OpenReport stDocName, acPreview, "qryRMAFilter"
DoCmd.RunCommand acCmdFitToWindow

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
MsgBox err.Description
Resume Exit_cmdPreview_Click
End Sub

Ken Sheridan
Stafford, England
 
Back
Top