473,383 Members | 1,880 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,383 software developers and data experts.

Print report to specific printer from combobox containing installed printers

convexcube
Hello Everyone,

I have a form setup with a combo box that displays a list of the installed printers using code from this article. On a button called cmdPrint I have placed code in the OnClick event from the same article to print to a specific printer. The specific printer being the one chosen in the combo box. In the line:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers("Acrobat PFDWriter")
I have replaced "Acrobat PFDWriter" with the name of my combo box - "cbxPrinters" (without the quotes).
Clicking cmdPrint yields this error:
"Run-time error '5': Invalid Call or Argument"
When I type in the name of the printer it works.

I'd be grateful if someone (ADezii?) could help me nut this one out? Its fairly urgent as I am installing the finished product on Monday.

Kind Regards,
Ken Farrawell
Jan 31 '08 #1
6 4866
ADezii
8,834 Expert 8TB
Hello Everyone,

I have a form setup with a combo box that displays a list of the installed printers using code from this article. On a button called cmdPrint I have placed code in the OnClick event from the same article to print to a specific printer. The specific printer being the one chosen in the combo box. In the line:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers("Acrobat PFDWriter")
I have replaced "Acrobat PFDWriter" with the name of my combo box - "cbxPrinters" (without the quotes).
Clicking cmdPrint yields this error:
"Run-time error '5': Invalid Call or Argument"
When I type in the name of the printer it works.

I'd be grateful if someone (ADezii?) could help me nut this one out? Its fairly urgent as I am installing the finished product on Monday.

Kind Regards,
Ken Farrawell
Try this Syntax, and let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim rpt As Report
  2.  
  3. If IsNull(Me![cbxPrinters]) Then Exit Sub
  4.  
  5. DoCmd.OpenReport "<Your Report Name>", View:=acViewPreview, WindowMode:=acHidden
  6.  
  7. Set rpt = Reports("<Your Report Name>")
  8. Set rpt.Printer = Application.Printers(Me![cbxPrinters])
  9.  
  10. DoCmd.OpenReport "<Your Report Name>", acViewNormal
  11. DoCmd.Close acReport, "<Your Report Name>"
Jan 31 '08 #2
Try this Syntax, and let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim rpt As Report
  2.  
  3. If IsNull(Me![cbxPrinters]) Then Exit Sub
  4.  
  5. DoCmd.OpenReport "<Your Report Name>", View:=acViewPreview, WindowMode:=acHidden
  6.  
  7. Set rpt = Reports("<Your Report Name>")
  8. Set rpt.Printer = Application.Printers(Me![cbxPrinters])
  9.  
  10. DoCmd.OpenReport "<Your Report Name>", acViewNormal
  11. DoCmd.Close acReport, "<Your Report Name>"
Thanks for your response Adezii,

I have tried the code you suggested:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "rptComplaint", View:=acViewPreview, WindowMode:=acHidden
  2. Set rpt = Reports("rptComplaint")
  3. Set rpt.Printer = Application.Printers(Me![cbxPrinters])
  4. DoCmd.OpenReport "rptComplaint", acViewNormal
  5. DoCmd.Close acReport, "rptComplaint"
Unfortunately the result is the same error. Any other ideas?

Kind Regards,
Ken Farrawell
Jan 31 '08 #3
Hi Adezii,

I've got an update. I was able to avoid the error by using the Cstr function:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers(CStr(Me![cbxPrinters]))
  2.  
Thanks for your efforts though.

Kind Regards,
Ken Farrawell
Jan 31 '08 #4
ADezii
8,834 Expert 8TB
Hi Adezii,

I've got an update. I was able to avoid the error by using the Cstr function:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers(CStr(Me![cbxPrinters]))
  2.  
Thanks for your efforts though.

Kind Regards,
Ken Farrawell
Nice fix, my next suggestion was something along the lines of:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers("'" & Me![cbxPrinters] & "'")
Jan 31 '08 #5
Nice fix, my next suggestion was something along the lines of:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers("'" & Me![cbxPrinters] & "'")
That was actually the first thing I tried, but it didn't work either & neither did:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers(Chr(34) & Me![cbxPrinters] & Chr(34))
Kind Regards,
Ken Farrawell
Jan 31 '08 #6
ADezii
8,834 Expert 8TB
That was actually the first thing I tried, but it didn't work either & neither did:
Expand|Select|Wrap|Line Numbers
  1. Set rpt.Printer = Application.Printers(Chr(34) & Me![cbxPrinters] & Chr(34))
Kind Regards,
Ken Farrawell
The only logical assumption is that it must be specifically Data Typed as String. A Variant (Sub Type of String) would be returned by Me![cbxPrinters], but I guess that isn't good enough.
Feb 1 '08 #7

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

Similar topics

2
by: Nikolay Seksenov | last post by:
I am developing VB.Net Web application to be used in our department intranet. I created a web-based report using Crystal Reports. I would like to print the report from the web server instead of...
1
by: Maileen | last post by:
Hi, We have a little problem in 1 of our ASP page :( on this page, we can add new printers (local or network) and to print a report on a selected (by default) printer. We we do the test on a...
4
by: William LaMartin | last post by:
I have a vb.net win form where I want to output some text to a printer. Everything works fine when printing to my laser or inkjet printers. However when I print to the Acrobat PDFWriter printer...
2
by: Gidi | last post by:
Hello, I've created a Document which i want to print using the PrintDocument class. In the document i draw some strings, and lines. When I PrintPreviewing my document (using the PrintPreview...
7
by: Mark | last post by:
Hi, I am creating application in VB 2005. and when I print report it adds extra 0.45 cm margin on left and top, and the reason for this is physical margins of printer. Is it possible to change...
3
by: Santosh | last post by:
Hii.. i am printing crystal reports in asp.net for that purpose i am using PrintTo Printer method but for that it is needed me to pass printer name which is installed on my local computer but...
5
by: Carl Witte | last post by:
Hello. I'm stuck. I've got a form I need to print to a manual feeder on a shared laser printer. This will get me to the printer but I can't seem to figure out how to print it to a specific bin. ...
0
AllusiveKitten
by: AllusiveKitten | last post by:
Hi kind and helpful people... At work I am creating a database and reports that will be used by multiple people. What I need is for my reports to print to a specific colour printer and be manual...
10
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.