Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2008
    Posts
    114

    Unanswered: Print to PDF and printer?

    Hello..
    I want to send a report to a printer and/or a PDF file.

    The code I am using for PDF is:
    Private Sub PrintPDF_Click()
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "QA Issues"
    strWhere = "[ClientID]=" & Me!ClientID
    DoCmd.OpenReport strDocName, acViewNormal, , strWhere
    End Sub
    And to print:
    Private Sub PrintQA_Click()
    Dim strDocName As String
    Dim strWhere As String
    strDocName = "QA Issues"
    strWhere = "[ClientID]=" & Me!ClientID
    DoCmd.OpenReport strDocName, acViewNormal, , strWhere
    End Sub
    As you can see they are both the same. And they both output to PDF files.
    How can I tell the Print button to send it to the printer and the PDF button to make a PDF file??

    Any help would be great, as always

    Thanks
    Tracy

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I believe your code is just printing to your default printer. So if your default printer is set to a PDF printer then you will get a PDF. Otherwise it should print to a physical printer.

    There is code on the internet (RunReportAsPDF google it you are interested) that will print a report to a PDF. But the code is fairly advanced. This is the code I use to get a report to print to an Adobe PDF. The code uses the registry to store the filename so the user does not have to enter one.

    But another possibility (not the best) is to have two copies of the report. Then design the report, go into File/Page Setup and set the report to print to a specific printer. You can select the PDF printer or another physical printer. Then save the report.

    If you have two copies of the report you can set each to print to a different destination. But when you make changes to the report you will need to remember to update the copy. That is why I don't think this is a very good approach.

  3. #3
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    I use this to send a report via a .pdf email attachement.You could alter it to send to a printer.

    Code:
    DoCmd.OpenReport stReport, acViewPreview, , stWhere, acWindowNormal
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", stEmailadd, stEmailCC, stEmailBCC, stSubject, stEmailMessage, True, ""
    In the last part of the SendObject is the variables that contain the email addresses, subject, and body for the email.

    HTH
    "Things are only impossible until they are not." ~Jean Luc Picard

  4. #4
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by Gwyar View Post
    Hello..
    I want to send a report to a printer and/or a PDF file.

    The code I am using for PDF is:


    And to print:


    As you can see they are both the same. And they both output to PDF files.
    How can I tell the Print button to send it to the printer and the PDF button to make a PDF file??

    Any help would be great, as always

    Thanks
    Tracy
    Tracy,

    What version of Access are you using?

    If you are using Access 2002 or later, you can set the printer with VBA code.

    See: Programming Printer Settings in Microsoft Access 2002
    This applies to Access 2002 and later. This new feature is one of the reasons why I recommend to my client to upgrade to 2002/2003 or later.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  5. #5
    Join Date
    Jan 2008
    Posts
    114
    Hi Raptorfish...
    Thanks for your suggestion..
    I tried it and kept getting errors, little things like stReport instead of strDocName
    Anyway I whittled away at it and eventually got it to go straight to the print preview of the report, then I get an error in the following line..
    DoCmd.SendObject acSendReport, strDocName, "PDFFormat(*.pdf)"

    I don't know enough about it to figure out whats going on...

    I havent tried the email thing yet, I really hope that will work, that would save me a lot of time,,, When the email code was in there there were errors on each of the following
    stEmailadd, stEmailCC, stEmailBCC, stSubject, stEmailMessage, True, ""

    Thanks for your input
    Tracy

    Running Access 2007

  6. #6
    Join Date
    May 2010
    Posts
    601
    Tracy,

    What is the windwos default priner? Is is a PDF write/driver?

    Since you have Acess 2007 you can:

    1) send a report to PDF using Acess 2007 leaving the Windows default printer set to you actual printer.

    2) Set the Windows default printer to where you want to print and then just print the report.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  7. #7
    Join Date
    Aug 2009
    Location
    Franklin, OH
    Posts
    44
    Quote Originally Posted by Gwyar View Post

    stEmailadd, stEmailCC, stEmailBCC, stSubject, stEmailMessage, True, ""
    Tracey, all the things in the code that start with "st____" are variables I setup to hold the strings for email addresses and report names. You should just delete the stuff you do not need and replace them with the ones you do need.
    "Things are only impossible until they are not." ~Jean Luc Picard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •