Question

I have a custom form and report in Access and I have a 'Print Report' button on my form that takes the current record for the database and prints out the Report I created for it. My problem is the code I have does a quick print on the Report. Once I press the "Print report" button I created, it pops up the Print Preview but then automatically prints the report. I want to be able to look at the preview before the report prints, open the print dialog and be able to select which printer I want to use, instead of it going to Quick Print and using the default printer. My code is below for the current format, I'm not sure where or how to make this adjustment. Thanks in advance for any assistance!

Private Sub cmdPrintReport_Click()
  Dim strReportName As String
  Dim strCriteria As String

  strReportName = "rptDrillReclamation"
  strCriteria = "[HoleNumber]='" & Me![HoleNumber] & "'"
  DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

On Error GoTo Err_cmdPrintReport_Click

  Dim stDocName As String

  stDocName = "rptDrillReclamation"
  DoCmd.OpenReport stDocName, acNormal

Exit_cmdPrintReport_Click:
  Exit Sub

Err_cmdPrintReport_Click:
  MsgBox Err.Description
  Resume Exit_cmdPrintReport_Click

End Sub
Was it helpful?

Solution

You are opening the report twice! Two lines of code starting with DoCmd.OpenReport.

The first time the View parameter is set to acViewPreview so it shows up (=previews) on the screen without printing. The second time the View parameter is set to acNormal (= no preview) so it prints directly to the printer without showing on the screen.

BTW The second time you are printing all the records because the criteria are not sent!

Remove the second Docmd.OpenReport.... It is unnecessary and is what is causing your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top