1
votes

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:

  1. User opens database on front page
  2. Clicks button on front page to open Form1 and enters information
  3. Clicks Print Preview button, activating macro above
  4. Clicks Print button in ribbon, Report1 prints single record

Form prints all records:

  1. User opens database on front page
  2. Clicks button on front page to open Form2 and enters information
  3. Clicks button on Form 2 to open Form1 and enters information
  4. Clicks Print Preview button, activation macro above
  5. Clicks Print button in ribbon, Form1 prints ALL records
1
Is there any different between the 2 in Print Preview? - Mark C.
No, the report is displayed the same from print preview. - trourke

1 Answers

0
votes

Since you write that all records are getting printed in form format, it seems quite obvious that 'Form1' has the focus when you press the print button on the ribbon.

You could avoid that by

  • Closing 'Form1' when opening the report
  • Using the right click menu of the report to press the print button
  • Creating a separate print button on 'Form1' that sends the report to the printer without previewing it