# Use VBA in Access module to control Print Dialog box



## Eutychus (Jan 31, 2008)

I am on a Windows XP machine using Access 2002-2003 writing an Access program for a Vista machine using Access 2003. I need to click a button on a form that will run a report, print the report set up to print using the "Adobe PDF" virtual printer, set the file name and the file path to something I control each time I run the report, and close the dialog boxes when done. All this should happen automatically. I don't want to use the Access report Snapshot view, but want to create a PDF file of the report. I want to be able to control the values on the Print and Save As dialog windows to give the report the name and to specify the path where the file will be saved. 
I was able to "sort of" get some of what I wanted done with the following code in the OnClick event of the report button, but it was not consistent even then and failed sometimes. This code probably needs to be replaced with something better. Here it is . . .
stDocName = "MyFutureReport"
DoCmd.OpenReport stDocName, acViewPreview
SendKeys "{TAB}", Wait
SendKeys "{TAB}", Wait
SendKeys "{ENTER}"
SendKeys MyFileName
SendKeys "{ENTER}"
DoCmd.RunCommand (acCmdPrint)
DoCmd.Close
This does not control where the report is saved (the path). The report itself in page setup was set to print to a specific printer that was the "Adobe PDF" printer. 
Any help and specific code examples of something like the above will be greatly appreciated!!!


----------

