I am setting up a button on a form to print a group of of records which have been filtered by the form's underlying query. For test purposes the number of records has been limited to two. The report comprises two pages. The intention is that the procedure will call the report, print the first record, close the report, loop to the next record, recall the report, print the second record and stop having reached the end of the file. Longer term the idea is to include within the "Do" loop the selection of specific reports to print different record types which are stored in a common table - but I need to get this one working first.
The code used is shown below. I have tried three versions of the reporting section two of which are commented out.
Private Sub cmdElectInspBulkPrint_Click()
On Error GoTo Err_cmdElectInspBulkPrint_Click
Dim rst As Recordset
Dim stDocName As String
Set rst = Me.RecordsetClone
rst.MoveFirst
Do
stDocName = "rptElecInspEN"
'Version 1
DoCmd.OpenReport stDocName, acViewNormal, , , , "[ID]=" & Me![ID]
DoCmd.PrintOut acPages, 1, 2, , , -1
'Version 2
'DoCmd.OpenReport stDocName, acViewNormal
'Version 3
'DoCmd.SelectObject acReport, stDocName, True
'DoCmd.PrintOut acPrintAll, 1, 2
DoCmd.Close acReport, stDocName, acSaveNo
Debug.Print rst!Equipment
rst.MoveNext
Loop Until rst.EOF
Exit_cmdElectInspBulkPrint_Click:
Exit Sub
Err_cmdElectInspBulkPrint_Click:
MsgBox Err.Description
Resume Exit_cmdElectInspBulkPrint_Click
End Sub
Version 1 - Believes the report is 4 pages long, loops after printing the two records on the 4 pages plus an additional 2 page print of the form itself and then gives me another set of 6 pages.
Version 2 - Has done best but also believes it has a 4 page report to print. However it has provided a 4 page report with record 1 on pages 1 & 2 and record 2 on pages 3 & 4. It then loops and repeats this.
Version 3 - Also believes it has a 4 page report but has given me two prints of the first record only.
Has anyone got any ideas?
The code used is shown below. I have tried three versions of the reporting section two of which are commented out.
Private Sub cmdElectInspBulkPrint_Click()
On Error GoTo Err_cmdElectInspBulkPrint_Click
Dim rst As Recordset
Dim stDocName As String
Set rst = Me.RecordsetClone
rst.MoveFirst
Do
stDocName = "rptElecInspEN"
'Version 1
DoCmd.OpenReport stDocName, acViewNormal, , , , "[ID]=" & Me![ID]
DoCmd.PrintOut acPages, 1, 2, , , -1
'Version 2
'DoCmd.OpenReport stDocName, acViewNormal
'Version 3
'DoCmd.SelectObject acReport, stDocName, True
'DoCmd.PrintOut acPrintAll, 1, 2
DoCmd.Close acReport, stDocName, acSaveNo
Debug.Print rst!Equipment
rst.MoveNext
Loop Until rst.EOF
Exit_cmdElectInspBulkPrint_Click:
Exit Sub
Err_cmdElectInspBulkPrint_Click:
MsgBox Err.Description
Resume Exit_cmdElectInspBulkPrint_Click
End Sub
Version 1 - Believes the report is 4 pages long, loops after printing the two records on the 4 pages plus an additional 2 page print of the form itself and then gives me another set of 6 pages.
Version 2 - Has done best but also believes it has a 4 page report to print. However it has provided a 4 page report with record 1 on pages 1 & 2 and record 2 on pages 3 & 4. It then loops and repeats this.
Version 3 - Also believes it has a 4 page report but has given me two prints of the first record only.
Has anyone got any ideas?