Professional Web Applications Themes

Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000 - Adobe Acrobat Windows

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 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 ...

  1. #1

    Default Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000

    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 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.

    When it 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 is below (I have omitted my custom functions that Read/Write to the Registry; dhReadRegistry and dhWriteRegistry):

    ' 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")

    ' 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

    ' 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

    ' Open the Report so it will print it
    DoCmd.OpenReport sReportName, acViewNormal

    ' Change the Printer from PDF Writer back to the default printer
    dhWriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", sMyDefPrinter
    Tony_VBACoder Guest

  2. #2

    Default Re: Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000

    Setting the default printer may be an API call. Do Microsoft endorse
    this registry method? If not, they probably changed the underlying
    methods in XP.

    Aandi Inston
    Aandi_Inston@adobeforums.com Guest

  3. #3

    Default Re: Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000

    Yes, it is an API call to Read/Write from the Registry; to Read you call the RegQueryValueEx API and to Write you call the RegSetValueEx API.

    What I am trying to get answered is, is it Acrobat or Microsoft Access that is having a problem reading the Default Printer that is set in the Registry? When I manually change my Default Printer, I can see in the Registry where the value in HKEY_CURRENT_USER in the folder "Software\Microsoft\Windows NT\CurrentVersion\Windows" in the key "Device" changes from my default printer to "Acrobat PDFWriter,winspool,LPT1:" and then back to my default network printer when I switch it back. Also, if I manually change my default printer to the Acrobat PDFWriter (by going into Control Panel/Printers) and then open my report in Access, the report gets converted to a PDF, however, if I try and do this using VBA, the report tries to print to my network printer.

    Am I missing something different for Windows XP?
    By the way...I am using Acrobat 5.0.5
    Tony Guest

  4. #4

    Default Re: Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000

    My problem has been solved thanks to a suggestion in the Microsoft Newsgroups. Access 2002 has a new Printer's Collection object, which I used to change my default printer to the Acrobat PDFWriter when I wanted to print my Access report as a PDF, and everything worked great.
    Tony Guest

Similar Threads

  1. problems access an MS Access 2000 DB using ASP
    By Brad Pears in forum ASP Database
    Replies: 2
    Last Post: July 21st, 09:16 PM
  2. Automate printing 100 pdf files from Access 2000/2002 VBA
    By Jennifer_Lee_Lorton@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 30th, 02:59 AM
  3. Replies: 9
    Last Post: September 11th, 05:45 PM
  4. Conversion problem from Access 97 to Access 2002
    By paul in forum Microsoft Access
    Replies: 0
    Last Post: July 25th, 02:46 AM
  5. Access 2000 / 2002 errors - urgent
    By Later in forum Microsoft Access
    Replies: 0
    Last Post: July 11th, 10:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139