I have a macro that opens a report in print preview, with the current record displayed. The report pulls information from the same form that this print preview button is on.
The problem is, sometimes the print button works and prints the single report record, other times it prints every single record in the form format.
Here is the code linked to a button in the form:
Private Sub Print_Record_Click()
'Save and print record
On Error GoTo Err_Msg
CurrentDb.Execute "qryOrderQty", dbFailOnError
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "rptWorkOrder", acViewPreview, , "Prod_Num = " & Me!Prod_Num
Exit Sub
Err_Msg:
MsgBox Err.Description
End Sub
Not sure if it helps, but here are some circumstances that I think lead to whether or not the error occurs. We'll call the report and form above Report1 and Form1, respectively.
Report prints as expected:
- User opens database on front page
- Clicks button on front page to open Form1 and enters information
- Clicks Print Preview button, activating macro above
- Clicks Print button in ribbon, Report1 prints single record
Form prints all records:
- User opens database on front page
- Clicks button on front page to open Form2 and enters information
- Clicks button on Form 2 to open Form1 and enters information
- Clicks Print Preview button, activation macro above
- Clicks Print button in ribbon, Form1 prints ALL records