?
Solved

Print Reports Automatically

Posted on 2014-01-30
6
Medium Priority
?
323 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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