0
votes

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
1
Is this all of the code associated with the Click Event of the button? I am looking for a DoCmd.PrintOut but I don't see it. That tells me there must be something else getting involved.Mark C.
@newbie Yes that is all the code associated with it. The Exit_cmdPrintReport_click I believe is what is executes the print.M Mayer
Exit_cmdPrintReport_Click is a label, like a line marker used to tell the code where to execute next when you use a GoTo statement. It does nothing unto itself.Brad
you are opening the report twice here. Is there something in the report's open even that prints automatically?Brad

1 Answers

0
votes

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.