473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing Printers in VB

147 100+
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
7 4313
ChipR
1,287 Expert 1GB
What's going wrong when you run the code?
Feb 25 '09 #2
DAHMB
147 100+
I get a runtime error 5, invalid procedure call or argument
Feb 25 '09 #3
ADezii
8,834 Expert 8TB
@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
DAHMB
147 100+
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
ChipR
1,287 Expert 1GB
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
3,532 Expert 2GB
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
DAHMB
147 100+
I got it!! Apparently it is case sensative when it comes to the printers name. Thanks everyone.
Feb 26 '09 #8

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

Similar topics

5
by: Aaron_TekRecycle.com | last post by:
Someone must have done this before?!? I have VBS code that will Enumerate all the Printers in the AD and Add the Printer Connection to the client... I'm just not a web developer so I need some...
1
by: Vanessa | last post by:
Hi, I'm trying to loop through all the printers in my computer system using WMI. However, I found out that it doesn't really get the correct number of printers in my system. I have 16...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
7
by: trint | last post by:
How can I add all the network printers to a combobox? Thanks, Trint
6
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be...
6
by: rquintana | last post by:
How can I change by program the default printer in VB.net if I have two printers connected in one computer? I want to print diferents reports in diferents printers connected in one computer and I...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
0
by: Ravigwipro | last post by:
Hi, I m able to get the printers object to know what are the printers had been installed and all. here my requirement is i have to write a data from VB to MS Word. for the page setup i have to...
4
by: Frank Rizzo | last post by:
I basically need a list of printers that's returned by the Find Printers dialog ( http://www.sqleffects.com/mystuff/findPrinters.png ). I've tried the path of DirectoryEntry entry = new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.