ACC2002: PDFWriter not working like Access2000 w/Win2000

T

Tony

I am trying to print an Access 2002 report (Windows XP OS)
as a PDF. I had success with Access 2000 in a Windows 2000
environment, but as soon as I bring the code over to
Access 2002 with Windows XP, the code does not work as
expected.

I am using VBA to manipulate the Windows Registry settings
for the Default Printer, so that instead of printing to a
local or network printer, the Access report will print to
the PDFWriter printer instead. Under Access 2000 and
Windows 2000, everything worked great. But now, under
Access 2002 and WinXP, whenever I set the default printer
to PDFWriter with VBA, the report still wants to print to
a local/network printer, unless I manually go into my
Printers and "fiddle" with my Default Printer from my
network printer to the PDFWriter printer and back again .

When my code gets to the "DoCmd.OpenReport sReportName,
acViewNormal" line, it always prints to a local printer,
even though the default printer in the registry is the
PDFWriter.

Anyone have any ideas why this is happening?

My sample code steps from my PrintToPDF function, are
listed below (I have omitted my custom functions that
Read/Write to the Registry; dhReadRegistry and
dhWriteRegistry):

' ******** STEP #1
' Read the current default printer and save the value - we
will need this later when we reset the Default Printer
sMyDefPrinter = dhReadRegistry
(HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device")

' ******** STEP #2
' Change the default printer to the PDF Writer
If Not dhWriteRegistry
(HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device", "Acrobat
PDFWriter,winspool,LPT1:") Then
GoTo Err_RunReport
End If

' ******** STEP #3
' Setting the value for PDFFileName in the registry Prints
the Report without the dialog box from appearing
If Not dhWriteRegistry
(HKEY_CURRENT_USER, "Software\Adobe\Acrobat
PDFWriter", "PDFFileName", "C:\Temp\MyReport.pdf") Then
GoTo Err_RunReport
End If
' Set the bExecViewer property so that the report will not
show after it is created
If Not dhWriteRegistry
(HKEY_CURRENT_USER, "Software\Adobe\Acrobat
PDFWriter", "bExecViewer", 0) Then
GoTo Err_RunReport
End If

' ******** STEP #4
' Open the Report so it will print it
DoCmd.OpenReport sReportName, acViewNormal

' ******** STEP #5
' Change the Printer from PDF Writer back to the default
printer
dhWriteRegistry
HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device", sMyDefPrinter
 
A

Albert D. Kallal

If you want, you can give my printer change a code a try..and see if it
works. I notice you don't send a command to windows to "refresh" the
printers...and you need to do this. I have some example code that does this
here:

However BEFORE YOU do that.....Note that access XP does have built
in the ability to switch printers. So,
while my code *should* work, you do NOT need it in a2002.

You can use:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

The above means you don't need my code.

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current defualt printer.
strDefaultPrinter = Application.Printer.DeviceName

' swtich to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever.

Swtich back.

Set Application.Printer = Application.Printers(strDefaultPrinter)

You can grab my code (that you don't need!) at:

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html
 
T

Tony

SOLVED!!!!

Albert, thank you for the help. I was unaware of the new
Access 2002 Printers Collection object. By switching to
use this instead of the Registry Entries, everything
worked as planned.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top