By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,316 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,316 IT Pros & Developers. It's quick & easy.

How do I set path and name of report printed to virtual printer?

P: 26

I've installed a virtual printer that allows me to save access reports as .pdf files. Within Access (using VBA) I'm using the DoCmd.OpenReport action to send the file to be printed. When I do this a pop up box appears asking me for the path and name of the file to be saved.

Since I'm trying to automate this process, how do I set these parameters programatically in VBA?

Below is an excerpt of the code I have so far.

Expand|Select|Wrap|Line Numbers
  1. Function CutReports()
  2. Dim rsContacts As New ADODB.Recordset
  3. Dim RPTPAN As Access.Report
  4. Dim strName As String
  6. rsContacts.ActiveConnection = CurrentProject.Connection
  7. rsContacts.Open "QRY12MoReviewNewMIPNo"
  9. Do While Not rsContacts.EOF
  11. 'Send data for this active record to Report and save as PAN.pdf
  12. strName = rsContacts!EEFullName 
  13. DoCmd.OpenReport "RPTPAN", acViewNormal, , "[EEFullName] = '" & strName & "'"
  14. ‘Here is where I’m stuck.  I need to dictate where and under what name to save the file.
  16. DoCmd.Close acReport, "RPTPAN", acSaveNo
  19. 'Move to the next person in the recordset
  20. rsContacts.MoveNext
  22. Loop
Apr 20 '09 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 489
You could try the SendKeys function. I don't use it myself but I played with it a bit and this is how I got it to work. I had to use the forms timer to delay the sendkey function to give the save dialog enough time to open.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "RPTPAN", acViewNormal, , "[EEFullName] = '" & strName & "'"
  2. Me.TimerInterval = 500
  4. Private Sub Form_Timer()
  5. SendKeys "DocumentName.pdf" & "{enter}", True
  6. Me.TimerInterval = 0
  7. End Sub
Apr 20 '09 #2

Expert Mod 15k+
P: 31,707
Ingenious solution Don :)

The simple answer is that there is no programmatic access to it as such. As far as Access (therefore your code) is aware, it is sending a report to a printer. The PDF builder part of the driver you're sending it to is entirely non-standard.

Having said that, it is possible that the provider of the software has released a separate API that you could use to control it directly. This depends on who the provider is of course. It may be worth a look (Google, or contact them directly).

Good luck with your project.
Apr 21 '09 #3

P: 26
Will do. Thanks to all for checking it out.
Apr 21 '09 #4

Expert Mod 15k+
P: 31,707
No worries.

Good luck with your project :)
Apr 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.