473,756 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOWTO: Automate Printing of Access Reports to PDF files

This is the approach I used to automate printing of Microsoft Access
reports to PDF format i.e. unattended and without annoying "Save As..."
dialogs, and - more importantly - without having to use a commercial
program such as Adobe Acrobat and its associated API.

The technique uses Ghostscript and Redirection Port Monitor - two free
programs for creating PDF documents provided free by Russell Lang. The
actual automation requires VBA coding using the FileSystemObjec t,
WScript.Network (the Windows Script Host Network Object) and Access
automation.
INSTRUCTIONS:

1) Install Ghostscript
- An interpreter for the Postscript language and PDF
http://www.cs.wisc.edu/~ghost/

2) Install RedMon - Redirection Port Monitor
- Redirects a special printer port to a program (such as
Ghostscript)
http://www.cs.wisc.edu/~ghost/redmon/

3) Set up virtual PDF printer using Ghostscript and Redmon
- Here are two web pages that explain how to install the
above tools:
http://masterdev.dyndns.dk/know/freepdf.html
http://stat.tamu.edu/~henrik/GSWriter/GSWriter.html

4) Configure the RedMon printer port used by the PDF virtual printer in
the following mannter:
- Output: "Program handles output"
- The new PDF file should always save to the same file i.e.
C:\temp\output. pdf

Use this for the "Program Arguments" setting:
@c:\gs\pdfconf. txt -sOutputFile="C: \temp\output.pd f" -c .setpdfwrite
-f -

(Note the literal filepath instead of the "%1")

5) Write your own Visual Basic code that prints the report to the pdf
and then uses FileSystemObjec t to copy it to a name/location of your
chosing. Use the WScript.Network object to change the default printer
from your usual default printer to the PDF printer and back again.

Example Code (Access Visual Basic):

Sub PrintReportToPD F(strReport as String, _
strOutputPath as String)

Const PDF_PRINTER as String = "PDF Printer"
Const ORIGINAL_PRINTE R as String = "\\OFFICE\HP132 0"
Const TEMP_PATH as String = "C:\temp\output .pdf"

Dim net as WScript.Network
Dim fso as Scripting.FileS ystemObject

Set net = new WScript.Network
net.setDefaultP rinter PDF_PRINTER

DoCmd.OpenRepor t strReport

Set fso = New Scripting.FileS ystemObject
fso.CopyFile TEMP_PATH, strOutputPath, True
fso.DeleteFile TEMP_PATH
Set fso = Nothing

net.setDefaultP rinter ORIGINAL_PRINTE R
Set net = Nothing

End Sub

For the preceding code to work inside Access 2000, you have to add
references to Microsoft Scripting Runtime and Windows Script Host
Object Model.

My experience so far is that the subroutine DoCmd.OpenRepor t() finishes
outputting the report to PDF very quickly...howev er, if you have a very
large report the output.pdf might be there when the FileSystemObjec t
goes to move/rename it. Therefore, you might want to use the Windows
API Sleep() function.
See < http://support.microsoft.com/kb/q162150/ >

Writing a routine that prints out multiple reports is left as an
exercise to the reader. Personally, I prefer to keep my reports in a
table called "Settings_Repor ts" rather than hardcoding the report names
into my VBA modules.
ADDITIONAL TIPS:

- Use DoCmd.SendObjec t() automate the emailing of the newly-created
reports to managers.

- Use the PDF Toolkit to merge disparate PDF reports into one file
URL: http://www.accesspdf.com/pdftk
This can also be automated using the VBA Shell() function, or in
VBScript via the WScript.Shell.R un() method

- Use VBScript to automate Access, just like Excel or Word.
See the following Microsoft KB article:
ACC: Using Microsoft Access as an Automation Server
http://support.microsoft.com/kb/q147816/

Code fragment (VBScript):

dim acc
set acc = CreateObject("A ccess.Applicati on")
with acc
..OpenCurrentDa tabase "C:\Reports\Sal es.mdb"

' Call the customer subroutine we defined earlier
..Run("PrintRep ortToPDF", "rptSalesFigure s_Monthly", _
"N:\Marketing\R eports\SalesSum mary" _
& Year(Date()) & Format(Month(Da te()),"00")

[Etc...]

Needless to say, there is a lot that can be done with the approach.
And the best part is that you don't have to learn another API (other
than the standard Windows Script Host and Microsoft Scripting Runtime
libraries, which you really should know anyway). And best of all it's
completely free!
SETTING UP THE PDF PRINTER:
Here are more detailed instructions for installing and configuring the
virtual PDF printer - cribbed from:
< http://masterdev.dyndns.dk/know/freepdf.html >

1. Install Ghostscript to C:\
<http://www.ghostscript .com/doc/AFPL/index.htm>

2. Create a text file (c:\gs\pdfconf. txt) and add the following text:

-Ic:\gs\gs8.11\l ib;c:\gs\fonts
-sDEVICE=pdfwrit e
-dNOPAUSE
-dSAFER

Note that the first line points to version 8.11 of Ghostscript. If
you have a different version or installed it to a different
location, make the appropriate changes.

3. Download, unpack, and Install RedMon (Redirection PortMonitor)
<http://www.cs.wisc.edu/~ghost/redmon/index.htm>
* When you run setup.exe you will only see a message box.

4. Go to Printers/Faxes menu under the Start button in Windows and
add a new printer.
* The driver for the printer must be for a /color postscript/
printer. I chose HP Color Laserjet 4550 PS
* Set the printer port to RPT1: (the redirected port)

5. Configure the port
Redirect Port to: "C:\gs\gs8.11\b in\gswin32c.exe "
(Update this line to reflect your version and location of
Ghostscript, if different)

Arguments for this program are:
@c:\gs\pdfconf. txt -sOutputFile="%1 " -c .setpdfwrite -f -

Output: "Prompt for filename"
Run: "Normal"

6. Try printing something in color to this printer. If everything works
right, you will be prompted for a filename that the PDF file will be
saved under (Don't forget to add the .PDF extension).
'
Hope this helps someone!

Cy******@gmail. com

Nov 13 '05
16 48885
Saintor wrote:

Well you don't need to.
http://www.freeware995.com/misc/vbacode.txt


Something interesting I learned about PDF995 from looking at that bit
of code:

PDF995 creates its PDFs using...GhostSc ript.

Contents of the file C:\PDF995\res\p df995.bat

chdir c:\pdf995\res\c onvert
gswin32c.exe -sDEVICE=pdfwrit e -q -dPDFSETTINGS=/prepress
-dCompatibilityL evel=1.3 -dNOPAUSE -dBATCH -sOutputFile="[SOME FILENAME
HERE]" -c save pop -f "c:\pdf995\temp .ps"

If you didn't know, "gswin32c.e xe" is the GhostScript executable.

Aside from using GhostScript, I noticed that PDF995 installs an
unconfigurable printer port called "PDF995 Port." This can only be
their version of RedMon. So it appears that they are using free tools
for their software and charging $9.95 a pop...except that the end user
can't configure your Redirected Monitor port like you can if you use
the pure GhostScript/RedMon solution...amon g other things.

We can conclude that PDF995 works by dynamically creating &/or editing
the pdf995.bat and *.ini files with each printing session. However, I
should mention that the linked VBA code, which attempts to modify the
PDF995 *.ini files itself, didn't work for me (using Windows XP/Acc2K).
This is *probably* because GetPrivateProfi leString() changed for
Windows XP (see next paragraph), or perhaps because I am using the
"sponsored" version of PDF995.

Now at this point, if I wanted the to work, I would have to spend an
unknown amount of time researching GetPrivateProfi leString(), trying to
figure out how it changed for Windows XP. I went through something
similar several months back, trying to get my wrapper class for
GetOpenFileName () to work after I upgraded to XP. Not a lot of fun.

So for those reading this thread who are still trying to decide which
solution to persue, I still recommend: GhostScript + RedMon +
FileScriptingOb ject + WScript.Network .SetDefaultPrin ter()

If you use a solution like PDF995, you'll actually be doing the exact
same solution as the one I describe...exce pt you'll be paying $10 for
it and puzzling over Win32 API calls to get it to work.

Nov 13 '05 #11
Access 2003 has the option to send PDF to email. I don't have Outlook
installed, but when I selected the option, it created a PDF file.

How do I access that function to save as PDF programmaticall y? If
Access 2003 can create a pdf file for email, surely there is a way to
just create a pdf file

Nov 13 '05 #12
I find this an interesting juxtaposition - reading this thread
via Google, I see the following note at the top:

Note: The author of this message requested that it not be archived.
This message will be removed from Groups in 6 days (Mar 4, 10:18 am).

And then in the post itself, Greg Strong wrote:
If you do not have the original posting to this thread, then
see Google's archive at

[snip path]
Do as I say, not as I do? Or are people not aware that they have
X-No-Archive (or whatever that flag is) set?

--
Martha Palotay
don't google to email

Nov 13 '05 #13
On 25 Feb 2005 12:30:54 -0800, "Martha" <mp************ @yahoo.com> wrote:
Do as I say, not as I do? Or are people not aware that they have
X-No-Archive (or whatever that flag is) set?


No I wasn't aware of the "X-No-Archive: yes" header being set, or at least I
don't recall setting it. No disrespect intended.

--
Regards,

Greg Strong
Nov 13 '05 #14
Yes, I did read the whole thread.

My question is how to access Access 2003's ability to create pdfs.

I have none of the above tools installed in my computer, yet when I
select File | Send to | Send PDF in email, Access 2003 is able to
create a PDF file.

Nov 13 '05 #15
Bri
You must have something extra installed. I just checked my version of
AC2003 and that option isn't there. There is an e-mail w/ attachment
option, but if I select that I get options like Text, Rich Text, Excel,
etc but no PDF.

--
Bri

So******@gmail. com wrote:
Yes, I did read the whole thread.

My question is how to access Access 2003's ability to create pdfs.

I have none of the above tools installed in my computer, yet when I
select File | Send to | Send PDF in email, Access 2003 is able to
create a PDF file.


Nov 13 '05 #16
Ghostscript with Redmon works great. I've used it before, but some of my
clients have found the PDF995 product to be easier, and still vastly more
affordable than the Adobe PDF applications.

As for making sure the file exists before you try to copy it, it turns out
that placing a DoEvents call right after the DoCmd.OpenRepor t will cause
Access to wait until the entire report is done printing before continuing to
the next statement.

On 8 Jan 2005 23:20:54 -0800, cy******@gmail. com wrote:
This is the approach I used to automate printing of Microsoft Access
reports to PDF format i.e. unattended and without annoying "Save As..."
dialogs, and - more importantly - without having to use a commercial
program such as Adobe Acrobat and its associated API.

The technique uses Ghostscript and Redirection Port Monitor - two free
programs for creating PDF documents provided free by Russell Lang. The
actual automation requires VBA coding using the FileSystemObjec t,
WScript.Networ k (the Windows Script Host Network Object) and Access
automation.
INSTRUCTIONS :

1) Install Ghostscript
- An interpreter for the Postscript language and PDF
http://www.cs.wisc.edu/~ghost/

2) Install RedMon - Redirection Port Monitor
- Redirects a special printer port to a program (such as
Ghostscript)
http://www.cs.wisc.edu/~ghost/redmon/

3) Set up virtual PDF printer using Ghostscript and Redmon
- Here are two web pages that explain how to install the
above tools:
http://masterdev.dyndns.dk/know/freepdf.html
http://stat.tamu.edu/~henrik/GSWriter/GSWriter.html

4) Configure the RedMon printer port used by the PDF virtual printer in
the following mannter:
- Output: "Program handles output"
- The new PDF file should always save to the same file i.e.
C:\temp\output .pdf

Use this for the "Program Arguments" setting:
@c:\gs\pdfconf .txt -sOutputFile="C: \temp\output.pd f" -c .setpdfwrite
-f -

(Note the literal filepath instead of the "%1")

5) Write your own Visual Basic code that prints the report to the pdf
and then uses FileSystemObjec t to copy it to a name/location of your
chosing. Use the WScript.Network object to change the default printer
from your usual default printer to the PDF printer and back again.

Example Code (Access Visual Basic):

Sub PrintReportToPD F(strReport as String, _
strOutputPat h as String)

Const PDF_PRINTER as String = "PDF Printer"
Const ORIGINAL_PRINTE R as String = "\\OFFICE\HP132 0"
Const TEMP_PATH as String = "C:\temp\output .pdf"

Dim net as WScript.Network
Dim fso as Scripting.FileS ystemObject

Set net = new WScript.Network
net.setDefault Printer PDF_PRINTER

DoCmd.OpenRepo rt strReport

Set fso = New Scripting.FileS ystemObject
fso.CopyFile TEMP_PATH, strOutputPath, True
fso.DeleteFi le TEMP_PATH
Set fso = Nothing

net.setDefault Printer ORIGINAL_PRINTE R
Set net = Nothing

End Sub

For the preceding code to work inside Access 2000, you have to add
references to Microsoft Scripting Runtime and Windows Script Host
Object Model.

My experience so far is that the subroutine DoCmd.OpenRepor t() finishes
outputting the report to PDF very quickly...howev er, if you have a very
large report the output.pdf might be there when the FileSystemObjec t
goes to move/rename it. Therefore, you might want to use the Windows
API Sleep() function.
See < http://support.microsoft.com/kb/q162150/ >

Writing a routine that prints out multiple reports is left as an
exercise to the reader. Personally, I prefer to keep my reports in a
table called "Settings_Repor ts" rather than hardcoding the report names
into my VBA modules.
ADDITIONAL TIPS:

- Use DoCmd.SendObjec t() automate the emailing of the newly-created
reports to managers.

- Use the PDF Toolkit to merge disparate PDF reports into one file
URL: http://www.accesspdf.com/pdftk
This can also be automated using the VBA Shell() function, or in
VBScript via the WScript.Shell.R un() method

- Use VBScript to automate Access, just like Excel or Word.
See the following Microsoft KB article:
ACC: Using Microsoft Access as an Automation Server
http://support.microsoft.com/kb/q147816/

Code fragment (VBScript):

dim acc
set acc = CreateObject("A ccess.Applicati on")
with acc
.OpenCurrentDa tabase "C:\Reports\Sal es.mdb"

' Call the customer subroutine we defined earlier
.Run("PrintRep ortToPDF", "rptSalesFigure s_Monthly", _
"N:\Marketing\ Reports\SalesSu mmary" _
& Year(Date()) & Format(Month(Da te()),"00")

[Etc...]

Needless to say, there is a lot that can be done with the approach.
And the best part is that you don't have to learn another API (other
than the standard Windows Script Host and Microsoft Scripting Runtime
libraries, which you really should know anyway). And best of all it's
completely free!
SETTING UP THE PDF PRINTER:
Here are more detailed instructions for installing and configuring the
virtual PDF printer - cribbed from:
< http://masterdev.dyndns.dk/know/freepdf.html >

1. Install Ghostscript to C:\
<http://www.ghostscript .com/doc/AFPL/index.htm>

2. Create a text file (c:\gs\pdfconf. txt) and add the following text:

-Ic:\gs\gs8.11\l ib;c:\gs\fonts
-sDEVICE=pdfwrit e
-dNOPAUSE
-dSAFER

Note that the first line points to version 8.11 of Ghostscript. If
you have a different version or installed it to a different
location, make the appropriate changes.

3. Download, unpack, and Install RedMon (Redirection PortMonitor)
<http://www.cs.wisc.edu/~ghost/redmon/index.htm>
* When you run setup.exe you will only see a message box.

4. Go to Printers/Faxes menu under the Start button in Windows and
add a new printer.
* The driver for the printer must be for a /color postscript/
printer. I chose HP Color Laserjet 4550 PS
* Set the printer port to RPT1: (the redirected port)

5. Configure the port
Redirect Port to: "C:\gs\gs8.11\b in\gswin32c.exe "
(Update this line to reflect your version and location of
Ghostscript, if different)

Arguments for this program are:
@c:\gs\pdfconf .txt -sOutputFile="%1 " -c .setpdfwrite -f -

Output: "Prompt for filename"
Run: "Normal"

6. Try printing something in color to this printer. If everything works
right, you will be prompted for a filename that the PDF file will be
saved under (Don't forget to add the .PDF extension).
'
Hope this helps someone!

Cy******@gmail .com


Nov 13 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1318
by: John | last post by:
Hi all, I would like to use the Report building and printing capabilities of the MSAccess DB. I have a ASP.NET page which does calculations based on data in a MSSQL Server and once done will need to have the abiliity to print from IE. The results can be over 1000 rows or greater, therefore using a datagrid, even with paging set to on, is a cumbursome way for the users to print all of the data. Is there a way to create the reports in...
2
4565
by: Sigurd Bruteig | last post by:
Hi all! I have a problem printing multiple reports. The code i use is: Dim stDocName As String stDocName = "rptInvoice" DoCmd.OpenReport stDocName, acNormal, , " = date()" The problem is that invioce details is printed several times on the same invoice and only the first page is shown as first page, even if all reports have only one page. I gess I have to loop trough the code, but I can't figure out how to.
3
10440
by: gudia | last post by:
I want to Programatically generate Access reports in the pdf format using some tool and then email them to people in the same code. Right now I am trying to do this with pdf995 using VBA (emailing is a separate issue, which pdf995 does not addresses). I downloaded pdf995. It controls printing via pdf995.ini file. In the VBA code, I have DoCmd.OpenReport "Report2", acViewNormal. I am having the following problems right now. (a) I do...
11
2466
by: IC_Clearly | last post by:
I'm running Server 2003 and wonder how well WTS works when printing an Access report to a client. Any suggestions would be appreciated. Thanks. IC
5
2863
by: Steven Taylor | last post by:
Hope someone can help. I have an application whereby in order to create one document type I effectively print out 3 or 4 access reports in correct order. So the user goes to the printer, collects the report and has no idea that 3 or 4 reports were actually created in order to produce the printed copy. I now have a need to send that same report to a 'Snapshot' file. Is there a way to combine separate Access reports and have them...
3
1246
by: narayanaRCG | last post by:
Hi, I am printing the reports in VB.Net. It's working fine. But, I wan't to print the current records data only. My report is printing all the data available in it. But, I wan't to print the current data only. For example, from frontend I am storing the student details into backend. and I am preparing report for it. When the next time I give the studetn id it should print only that details with the student id given by me. Can any body tell me...
3
1663
by: charvi | last post by:
can i generate more than 1 excel sheets when a command button is clicked for eg i search for 2 names of audit dept and click print command button where records will be printed in excel again if i search for other 2 names and if i click print command button reports will not be printed.and gives error i have to close the program and load the program again
4
1877
by: MLH | last post by:
How do I ensure my reports are being printed in max resolution of 1200dpi ? That is, can Access control the setting?
0
2337
by: Qtip23 | last post by:
Hello All, So I have a my database information placed on a SharePoint site now that there is an immediate need for a web-based application in my division. I am able to print Access Reports from SharePoint but this annoying non-breaking space mark -- &nbsp -- keeps printing out as well. Is there a way to handle or suppress that from occuring when printing out Access reports? Thanks,
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.