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