Solved

Print Reports Automatically

Posted on 2014-01-30
6
319 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 500 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

737 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