Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to selecting multiple printers with code

Status
Not open for further replies.

wcwolff

Technical User
Aug 3, 2004
13
US
I am writing an invoicing application that will print 3 different forms on 3 different printers [sequentially] when the user finalizes the invoice. All the printers are dedicated to a particular form. I don't want the user to have control over selecting the printer but rather select the printer with code (no dialog).

I can change the default printer, print the job, change the default printer, print again and so on. This seems an rather inefficient way to print.

Is there a way to select a printer for printing via code without a printdialog or using multiple changes to the default printer for each form printed.

Flow Chart is like this:
Finalize Invoice > Print Invoice Form > Print Shipping Label > Print Barcode > Finished

Thanks in advance for any help!
 
Hi,
i do not either allow a user to select a printer from a dialog box. Below the routine will show the available printers.

With PrinterSettings.InstalledPrinters
For i As Integer = 0 To .Count - 1
Listbox1.Items.Add( Item(i) )
Next
End With

If you know the printer's name (you do!) just do:

PrinterSettings.PrinterName = "HP LaserJet blah
 
Thanks for the reply.

I tried the above code and get several exceptions and could not get it to work. I am using the following code to read available printers.


Dim P As Integer
Dim AvailablePrinters As String
For P = 0 To System.Drawing.Printing.PrinterSettings. _
InstalledPrinters.Count - 1
AvailablePrinters = System.Drawing.Printing.PrinterSettings. _
InstalledPrinters.Item(P)
ListBox1.Items.Add(AvailablePrinters)
Next


Then when using the final step:
PrinterSettings.PrinterName = "HP LaserJet blah" - I get an "reference to a non-shared member requires an object reference."

Thanks. Any more suggestions?
 
The last was an example.
If you allow the user to select the printer then you do: printersettings.printername=listbox1.text
If not, then you must assign the exact same name (like i said in the example with the hp printer).

As for the error: What program prints? (excel, a printdocument.. what?)
 
Thanks for the quick reply. I guess I was still asleep when using the code you suggested. I'm using printdocument as the print program.

PrintDocument1.PrinterSettings.PrinterName = "Printer Name" - is what I didn't do. It works fine now.

Thanks very much for your help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top