Print Reports Automatically

I have the following code that I use to create PDF's for individual customers and then it emails the report to them as an attachment. What I want to do now is print these reports automatically as a different function. I want to use the same code but just change the output part to print the reports instead. Can this be done easy enough? If so how would I go about it?

Here's the code I'm using for the PDF creation and email. This loops through each customer and creates a PDF of the report. I want the same thing but instead of creating and emailing the PDF's I want to just print the access report to my default printer.

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As QueryDef
Dim sDate As String
Dim MyPath As String

MyPath = DLookup("LocalDrive", "tblDatabaseSettings", "RecordID = 1")
Set db = CurrentDb
Set qdf = db.QueryDefs("qryClinicDailySummaryEmails")         'My Parameter Query
qdf.Parameters(0) = [Forms]![frmReports]![txtStartDate] 'Form Control
Set rst = qdf.OpenRecordset
sDate = Me.txtStartDate

Do While Not rst.EOF
    strRptFilter = "[RecordID] = " & rst.Fields("RecordID")
    strRptEmail = Nz(rst.Fields("ClinicEmail"), 0)
    strRptFileName = rst.Fields("ClinicCode") & "-" & Format(sDate, "mmddyyyy") & ".pdf"
    strRptClinicName = rst.Fields("ClinicName")
    DoCmd.OutputTo acOutputReport, "Clinic Daily Summary - Email", acFormatPDF, MyPath & rst.Fields("ClinicCode") & "-" & Format(sDate, "mmddyyyy") & ".pdf"
    If strRptEmail <> "0" Then
        'Do Nothing
    End If

Set rst = Nothing
Set qdf = Nothing
Set db = Nothing
MsgBox "All Emails have been sent."

Open in new window

Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?
Bill RossConnect With a Mentor Commented:

Change line 20 from:
DoCmd.OutputTo acOutputReport....

Docmd.OpenReport acOutputReport <nothing more>

Comment out lines 14-18 and  21-35


Lawrence SalvucciInformation Technology ManagerAuthor Commented:
And that will print each customer on a separate report? I thought the "Do While Not rst.EOF" was there to loop through each report?
Bill RossCommented:

If the report is designed correctly it should be fine.  You can add the loop back in if you want but that would usually not be necessary as the loop is "filtering" to get the PDF.  The printed copy will do that automatically in a single print job.

Give it a try.  Without having the report available and knowing what you expect I can't be sure.


Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Ok I tested it but I got the popup window to select the output format. I just want to run it directly to the printer.
Bill RossCommented:
Docmd.OpenReport acOutputReport

Sends the report to the default printer.  Do you have a default printer installed?
You should use
DoCmd.OpenReport "Clinic Daily Summary - Email", acViewNormal

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.