Solved

Print Reports Automatically

Posted on 2014-01-30
6
311 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
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
Bill Ross earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:Lawrence Salvucci
Comment Utility
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
Comment Utility
Docmd.OpenReport acOutputReport

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

Expert Comment

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

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now