Results 1 to 14 of 14
  1. #1
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42

    Print to other than default printer with code

    I am working with A2007. I am trying to print a form with a printer that is not the default printer. I have found several things on the Google, including some answers in this forum. The only one that worked is a very complex one that opens a form that displays a choice of printers. I would like to just click the print button and have the printer print page 1 of a form with a certain printer, not the default one.



    Most codes I found include an expresson “Application.Printer etc.---. I always get an error message when the code reaches that line. Why? Is it 2007 vs 2003 or do I have to select a library item? (Admittedly, some examples may just have been beyond my ability to understand what to substitute in the given expression for my particular needs.)

    Can someone please give me the code for A2007? I am an amateur, so, unfortunately, need more than just a general suggestion. I am going nuts on this, so much appreciate any help.

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    the code in this link pretty much does what you want

    https://www.accessforums.net/code-re...nter-7745.html

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    Thanks for reply. I actually tried this site before The first example at the site leaves so much out that can't even get started. The 2nd one is better, but doesn't work. It may be that I didn't substitute my items properly, but tried about everything. I enjoy working with Access, but can't understand how on earth they could make something as simple as choosing a printer so complicated.


    Quote Originally Posted by Ajax View Post
    the code in this link pretty much does what you want

    https://www.accessforums.net/code-re...nter-7745.html

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    I don't call five lines of code complicated, and one of those is the actual print command which you would need anyway and the other is a declaration

    Define object as printer: Dim PRT As Printer
    get current default printer (so it can be reset as default): Set PRT = Application.Printer
    set printer to the one you want to use: Set Application.Printer = Application.Printers("\\AMD_XP\Brother MFC-240C USB Printer (Copy 1)")
    Print to 'new' printer: ' DoCmd.PrintOut TablA 'uncomment to print on the revised printer
    Reset to default printer: Set Application.Printer = prt 'uncomment to restore the previous default printer

    How much more uncomplicated could it be?

    Any other program would have to go through all these steps, so it is not an Access issue

  6. #6
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    It is not complicated-it just doesn't work. As I said in the original posting, I get an error signal whenever code gets to the to the Set Application line. Specifically: "Error 5 Invalid procedure or argument." Does it have something to do with the "\\AMD_XP\ ?- I have no idea what that is for and tried code with and without that and have no idea what to substitute for it if needed. Not sure what the (copy 1) is about either. I also tried with and without it.

    If you could just give me an example of that code line assuming my printer is "PrinterName", it would be much appreciated.

  7. #7
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    just replace (\\AMD_XP\Brother MFC-240C USB Printer (Copy 1)) with the equivalent for your printer

    if you don't know the name of your printer run this bit of code in a module

    Code:
    Sub FindPrinter()
    Dim PRT As Printer
     
       for each PRT in Application.Printers
           debug.print PRT.name
       next PRT
    
    end sub

  8. #8
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    I have done that already. Every time code gets to "Set Application.Printer = Application.Printers("CANON MG3500 SERIES PRINTER")" , I get error 5 message described earlier.

    I tried your other find printer code and got a compile error when code got to " Debug.Print PRT.Name" . Name was highlighted. Am I missing some library item?



    Quote Originally Posted by Ajax View Post
    just replace (\\AMD_XP\Brother MFC-240C USB Printer (Copy 1)) with the equivalent for your printer

    if you don't know the name of your printer run this bit of code in a module

    Code:
    Sub FindPrinter()
    Dim PRT As Printer
     
       for each PRT in Application.Printers
           debug.print PRT.name
       next PRT
    
    end sub

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Try:

    Debug.Print PRT.DeviceName

    Should not need another library reference. The intellisense popup tips should show the available properties.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    the #5 error indicates you are not spelling the name of your printer correctly so run the routine to find out the names

  11. #11
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    I found condensed some code from a sprinter search example that seems to work. Thanks for all the time that you spent on this. It is amazing that we can get help like this for free. I have learned a lot.
    Function SetPrinter(PrinterName As String) As Boolean
    Dim ptr As Printer
    Dim UsePrinter As Printer '
    'try and find this printer
    For Each ptr In Application.Printers
    If ptr.DeviceName = PrinterName Then
    Set UsePrinter = ptr
    End If
    Next
    Set Application.Printer = UsePrinter
    DoCmd.OpenForm "FormName"
    DoCmd.PrintOut , 1, 1
    End Function

  12. #12
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I would still like to know how to make your suggested code work. Have you tried it? I am nervous that the code I am using doesn't reset to the default printer and would like to use the code you led me to. I didn't misspell the printer name. ("pdf995")

  13. #13
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    You are undoubtedly getting tired of this. I gave it one more pass and this time just copied your code with all the commentary and then removed the commentary, and, it works! For some reason, the code that I copied from the referred site bombs out on the Set Application.Printer = Application.Printers("PDF995") line, even though identical. Strange, but I I'll take it. Thanks again.

  14. #14
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    You are undoubtedly getting tired of this
    No, but I have a living to make and sometimes I don't have time to respond. Glad you got it sorted

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Select Default Printer
    By pkstormy in forum Code Repository
    Replies: 4
    Last Post: 03-10-2015, 09:26 AM
  2. Setting Default Printer Properties with VBA Cocde
    By EddieN1 in forum Programming
    Replies: 2
    Last Post: 12-04-2014, 11:02 AM
  3. Replies: 3
    Last Post: 02-25-2014, 11:46 AM
  4. Print to Default Printer
    By bsc0617 in forum Access
    Replies: 7
    Last Post: 10-10-2013, 07:46 AM
  5. Trying to Change Default printer
    By sims.anderson2010 in forum Programming
    Replies: 2
    Last Post: 03-08-2012, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums