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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a network printer?

Status
Not open for further replies.

btt423

Programmer
Jan 28, 2002
31
US
I'm working on an application that needs the capability to poll a database for items to be printed, and then print to one of several printers that are listed in a database table.

How would I go about doing this in vb?

Any help would be appreciated!

Thanks, Brinson
 
Within VB there is a Printers collection. The following code snippet loads all of the available printers into a combobox, from which the user may select the desired printer.
Code:
Dim lPrn_AvailPrinter   As Printer
Dim lInt_DefaultIndex   As Integer
Dim lStr_DefPrtName     As String   

Printer.TrackDefault = True
lStr_DefPrtName = Printer.DeviceName
cboPrinters.Clear
' Load the default printer first
cboPrinters.AddItem lStr_DefPrtName

For Each lPrn_AvailPrinter In Printers
' skip the default printer since its already loaded
   If (lPrn_AvailPrinter.DeviceName <> lStr_DefPrtName) Then
      cboPrinters.AddItem lPrn_AvailPrinter.DeviceName
   End If
Next
Once the user has selected a printer from the combo box, set the Printer object to the selected printer.
Code:
Dim lStr_PrinterName    As String
Dim lPrn_AvailPrinter   As Printer
   
lStr_PrinterName = cboPrinters.Text
For Each lPrn_AvailPrinter In Printers
   If (lPrn_AvailPrinter.DeviceName = lStr_PrinterName) Then
      Set Printer = lPrn_AvailPrinter
...
and proceed with your program Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top