Results 1 to 3 of 3
  1. #1
    jaeapla is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Location
    Atlanta, GA
    Posts
    12

    How do I output a report to PDF using VBA, Access 2010, Win 7


    I generate a report which happens to be a member directory. It is totally formatted in the report, so I need to do 2 things:
    a. run (3) separate queries to set up the info for the report, then (4), print the report. I am stuck here. I have tried the following code to save the file as a pdf. It generates the pdf and displays it to screen, but does not save it to my directory, and does not zap a temporary table I used to generate the printed report (which is called "Membership_List_Directory". Also, no one ever mentions where you put the code and how do you specifically actuate it. I started with a macro and did a macro conversion to VBA. I would appreciate any help I can get, as I am the "DB Manager" for a charitable organization.

    Code:
    Option Compare Database
    
    '------------------------------------------------------------
    ' Publish_Directory
    '
    '------------------------------------------------------------
    Function Publish_Directory()
    On Error GoTo Publish_Directory_Err
    
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "(1)_Membership_List_Directory_Create_Table_Query", acViewNormal, acEdit
        DoCmd.OpenQuery "(2)_Membership_List_Directory_Import_Data_Query", acViewNormal, acEdit
        DoCmd.OpenQuery "(3)_Directory-update_for_Print", acViewNormal, acEdit
        DoCmd.OpenReport "(4)_Publish_Membership_Directory", acViewPreview, "", "", acNormal
        DoCmd.OutputTo acOutputReport, "(4)_Publish_Membership_Directory", acFormatPDF, "C:\Users\sam-smith\Documents\FCREA Membership Directory_files\MONTHLY DIRECTORY UPDATE\Publish_Membership_Directory.pdf", ShowPdf, "", 0, acExportQualityPrint
    Publish_Directory_Exit:
        Exit Function
    
    Publish_Directory_Err:
        MsgBox Error$
        Resume Publish_Directory_Exit
    
    End Function

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, from the code above this is what I am interpreting your actions:

    1) Open Query "(1)_Membership_List_Directory_Create_Table_Query"
    2) Open Query
    "(2)_Membership_List_Directory_Import_Data_Que ry"
    3) Open Query
    "(3)_Directory-update_for_Print"
    4) Open Report
    "(4)_Publish_Membership_Directory"
    5) Export Report
    "(4)_Publish_Membership_Directory" to PDF

    From the sounds of it you want to print the report
    "(4)_Publish_Membership_Directory". Have you tried DoCmd.PrintOut command? I would add another line of code using that command to actually print the report.


  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Try
    Code:
    DoCmd.OpenReport "YourReportName", acViewPreview
    CommandBars.ExecuteMso "PublishToPdfOrEdoc"
    DoCmd.Close acReport, "YourReportName"
    The above will open File>Save dialogue wherein you can change file name and location to save.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Output a report to pdf
    By TOMMY.MYERS668 in forum Programming
    Replies: 6
    Last Post: 02-25-2013, 09:00 PM
  2. Output Report to Excel using MACROS
    By taimysho0 in forum Programming
    Replies: 1
    Last Post: 02-22-2012, 03:49 PM
  3. Access 2010 Report
    By kowen091010 in forum Access
    Replies: 3
    Last Post: 12-12-2011, 03:36 PM
  4. .txt output from report
    By dhopper in forum Reports
    Replies: 1
    Last Post: 08-05-2011, 12:01 PM
  5. Output Report to Excel
    By BLD21 in forum Reports
    Replies: 5
    Last Post: 04-26-2011, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums