Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Piscataway, New Jersey, USA
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    set default printer to Adobe PDF (2003/XP)

    Hi everybody:

    This is driving me nuts!

    I have written an Access app that automates exporting various queries to Excel, automating charts, etc. and then is supposed to hide a bunch of data sheets and then print out the rest to Adobe. Problem is the Adobe part. I can use Application.ActivePrinter to save whatever printer the user was printing on and reset it afterward, but Application.ActivePrinter = "Adobe PDF" doesn't work unless I can supply the NE number, which is changeable.
    When I record a macro to set the Excel printer to Adobe at different times (from the same PC), I get various answers, i.e.,
    ActivePrinter:="Adobe PDF on Ne04"
    ActivePrinter:="Adobe PDF on Ne03"
    ActivePrinter:="Adobe PDF on Ne13"
    So, I thought there must be some way to get which printer port Windows is finding Adobe on from the API.
    Sure enough, in regedit, I can see the pesky NE number under the Data column in
    HKEY_CURRENT_USERSoftwareMicrosoftWindows NTCurrentVersionPrinterPorts

    I tried using an API call SetDefaultPrinter on Lib "winspool.drv" , but it doesn't work (too bad, because the call is so simple: SetDefaultPrinter = "Adobe PDF"). I also tried downloading some code from the Ozgrid website that uses API calls GetPrinter and OpenPrinter to return the port name, but instead of returning the NE number (as I can see in regedit), it returns "My Documents*.pdf", which is apparently Adobe's default location in Windows. This doesn't work either, and I am getting frustrated.

    Has anyone found a bullet-proof solution to this? I really don't want to have to resort to having the user do this manually. Alternatively, I suppose I could export the registry to a text file and do a search, but that seems like a very inelegant solution.

    Thank you, in advance, for your help.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: set default printer to Adobe PDF (2003/XP)

    I can't test at the moment, but does Visual Basic(Microsoft) Win32API - Printer Names in Combo Box help?

  3. #3
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Piscataway, New Jersey, USA
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set default printer to Adobe PDF (2003/XP)

    Thank you, but no, I tried that. I can return the printers collection, but it doesn't give me the pesky NE number.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: set default printer to Adobe PDF (2003/XP)

    That thread also contains code to loop through Ne01, Ne02 etc until you find a valid printer.

  5. #5
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Piscataway, New Jersey, USA
    Posts
    171
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: set default printer to Adobe PDF (2003/XP)

    Thank you, Hans.

    I just had to dig a little deeper in the thread. The error handler looping through Ne numbers worked once I got rid of the second on error goto statement, which Excel 2003 ignored even though I had set my options to break in class modules. Using this methodology, I did not require the API code.

    I turned it into a little function, which works great:

    Function fnSetAdobePrinter() As Boolean
    Dim strNE As String, blnWrongNe As Boolean, i As Integer
    DoCmd.SetWarnings False
    On Error GoTo err_fnSetAdobePrinter
    Application.ActivePrinter = "Adobe PDF on Ne00:"
    If blnWrongNe = -1 Then
    blnWrongNe = 0
    For i = 1 To 99
    If i < 10 Then
    strNE = "Ne0"
    Else
    strNE = "Ne"
    End If
    Application.ActivePrinter = "Adobe PDF on " & strNE & i & ":"
    If Not blnWrongNe Then
    fnSetAdobePrinter = -1
    Exit Function
    End If
    blnWrongNe = 0
    Next i
    End If
    err_fnSetAdobePrinter:
    blnWrongNe = -1
    Err.Clear
    Resume Next
    End Function

    Appreciate your help!

Posting Permissions

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