?
Solved

Print report to pdf using vba

Posted on 2005-04-19
9
Medium Priority
?
1,787 Views
Last Modified: 2008-01-09
Hi all.
I'm trying to print a Access report to pdf using vba.
I have code that works fine, except that it promps me for a file name.
Is there any way to set the filename so the user don't have to?

This is the code I have so far:

  Dim stDocName As String
  stDocName = "myReport"  
  'print to pdf
  Set Application.Printer = Application.Printers("Adobe PDF")
  DoCmd.OpenReport stDocName, acViewNormal
  Application.Printer = Nothing

Regards,
John
0
Comment
Question by:JohnModig
9 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 13813832
Hi John,
Short of using Sendkeys or building an API I don't think there's a way to do what you want

Good Luck!

Gary
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 13813932
I think you can set that somewhere in the printer properties.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 13813965
Havea look at:
www.mvps.org/access/reports/rpt0011.htm


Also, here are some other useful links for you:

Outputting reports to PDF:
http://www.mvps.org/access/reports/rpt0011.htm

Sending e-mails with attachments:
http://www.granite.ab.ca/access/email.htm
http://support.microsoft.com/default.aspx?scid=kb;en-us;209948

A (commercial) library which will make doing both much easier, the PDF and E-Mail Class Library:
http://ourworld.compuserve.com/homepages/attac-cg/
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 11

Author Comment

by:JohnModig
ID: 13814146
>> Havea look at:
>> www.mvps.org/access/reports/rpt0011.htm

Seen that page and method already. The problem with it is that it requires win.ini to be modified. This will obviously is not very user-friendly - lets say when moving the db to another users computer, if that user is not fully informed and/or do not have the right skills, the function will not work. What I am looking for is something that I can put in the db code.
Thanks anyway.
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 13814192
As I understood it your problem isn't printing to Pdf,I can give you plenty of code to do that.
Your problem is to stop  the prompt for the file...Right?

Gary
0
 
LVL 11

Author Comment

by:JohnModig
ID: 13816375
Correct.
I want to stop the prompt for the file and give it a name programaticly, if possible.
0
 
LVL 46

Accepted Solution

by:
tbsgadi earned 2000 total points
ID: 13831304
Hi John,
After researching for the last few days ..here are my conclusions.
There was good code that you'll find a million times here that used to work on Acrobat 5 that now doesn't seem to do the trick on Acrobat 6.(It doesn't change the name of the saved file)
This is how to proceed.

1) In acrobat, change the preference to not prompt for file name.
2) If you want to save a report to different names/locations, Create it in the default loacation & then move it to your location (Using the  FileSystemObject if you want).

Alternatively you can use the Acrobat Distiller SDK but that seems a lot more complicated.

Good Luck!

Gary





0
 
LVL 11

Author Comment

by:JohnModig
ID: 13831861
Thank you, tbsgadi.
I had a feeling that Acrobat 6 messed things up for me. On the other hand, to save as default, then move and rename using FileSystemObject is a good enough workaround.
Thanks again, keep up the good work!

John
0
 
LVL 46

Expert Comment

by:tbsgadi
ID: 13831872
Thanks...You too!

Gary
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question