[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Print Reports Automatically

Posted on 2014-01-30
6
Medium Priority
?
325 Views
Last Modified: 2014-01-30
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"
    DoEvents
    If strRptEmail <> "0" Then
        SendReport
    Else
        'Do Nothing
    End If
    DeletePDF
    rst.MoveNext
Loop

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

Open in new window

0
Comment
Question by:Lawrence Salvucci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
Bill Ross earned 2000 total points
ID: 39820494
Hi,

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

to
Docmd.OpenReport acOutputReport <nothing more>

Comment out lines 14-18 and  21-35

Regards,

Bill
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39820512
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?
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39820519
Hi,

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.

Regards,

Bill
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39820529
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.
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39820577
Docmd.OpenReport acOutputReport

Sends the report to the default printer.  Do you have a default printer installed?
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39820819
You should use
DoCmd.OpenReport "Clinic Daily Summary - Email", acViewNormal

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question