By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,790 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,790 IT Pros & Developers. It's quick & easy.

Changing Printers in VB

100+
P: 147
Why won't this work? I am using access 2007.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnPrint_Click()
  2. Dim strDefaultPrinter As String
  3.  
  4. ' get current default printer.
  5. strDefaultPrinter = Application.Printer.DeviceName
  6.  
  7. ' switch to printer of your choice:
  8.  
  9. Set Application.Printer = Application.Printers("Oce cm6520")
  10. DoCmd.PrintOut acPrintAll
  11.  
  12. '   Swtich back.
  13.  
  14. Set Application.Printer = Application.Printers(strDefaultPrinter)
  15.  
  16. End Sub
  17.  
Feb 25 '09 #1
Share this Question
Share on Google+
7 Replies


Expert 100+
P: 1,287
What's going wrong when you run the code?
Feb 25 '09 #2

100+
P: 147
I get a runtime error 5, invalid procedure call or argument
Feb 25 '09 #3

ADezii
Expert 5K+
P: 8,623
@DAHMB
Try replacing Line #14 with:
Expand|Select|Wrap|Line Numbers
  1. 'Reset the Default Printer back to the way it was 
  2. Set Application.Printer = Nothing 
Feb 25 '09 #4

100+
P: 147
I tried what you said and it did not work. I get the same error and when I click debug it highlights line 9.
Feb 25 '09 #5

Expert 100+
P: 1,287
Are you sure the device name is correct? You can list them all with the code in How to: Retrieve a List of Installed Printers.
Feb 25 '09 #6

missinglinq
Expert 2.5K+
P: 3,532
I believe that being unable to switch from the Default Printer to another printer is a known bug in 2007. Here's a link for the hotfix:

http://support.microsoft.com/kb/950488

Linq ;0)>
Feb 25 '09 #7

100+
P: 147
I got it!! Apparently it is case sensative when it comes to the printers name. Thanks everyone.
Feb 26 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.