• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3218
  • Last Modified:

Printer tray selection problem

I am using VB 5.0 on Windows XP home. I have a HP Laserjet 2300L, with an extra paper tray (2 paper trays and 1 manual feed), connected to the Parallel port using a bi-directional cable. The BIOS is set for ECP for the parallel port. I am trying to send a print job by first selecting a paper tray using the printer.paperbin=1, 2 or 3. I have also tried selecteing a paper tray using the printer.paperbin=vbPRBNUpper, vbPRBNLower and vbPRBNMiddle command. I get a run-time error 380, Invalid property value, when I select the paper try. I am able to use all other print commands successfully. I am using the HP PCL6 driver. I have tried the HP PCL5 driver, with the same result. Can you suggest another a method of tray selection?
0
villartech
Asked:
villartech
  • 6
  • 4
  • 3
  • +2
1 Solution
 
bingieCommented:
0
 
villartechAuthor Commented:
Those examples you pointed me to don't help. I have tried using printer.paperbin 0-7 without success. If have tried using printer.PRBNx without success. I don't understand the third code example that user was trying to print a Word document. I want to just select a tray and then print string data.
0
 
hesCommented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
villartechAuthor Commented:
The article refers to:
When using the Printer object, you cannot change any page settings after using the NewPage method. This includes Orientation, Height, Width, PaperSize, PrintQuality, and PaperBin.

I am not using a newpage statement. Is there an API call that could change the paper source?
0
 
DabasCommented:
Hi villartech,
I suggest you Add printers to your list of printers. One printer for each tray
It will be exactly like the printer you already have, just with a different tray selected

In VB, just choose the suitable printer from the printer list and print to it.

Dabas
0
 
DhaestCommented:
villartech: I have done a project where I needed to print specific documents on a specific printer and tray.
The only solution there is, is already mentioned by dabas.

For each tray, you'll have to make a printer.
At the settings of the printer, you'll be able to set the tray's available for that printer. Just set the tray you need to use and disable all the other trays.
When you now print to that printer, it will take the paper out of the tray you wanted.
0
 
villartechAuthor Commented:
I am a novice and am not sure how to add a printer for each tray. Could you supply a code example.
0
 
DabasCommented:
villartech:
No code at all. Just click no the start button, control panel, Printers.
Then click on the Add Printer button and add an identical printer to the one you already have, but set to a different tray

Dabas
0
 
villartechAuthor Commented:
How do create a list of printers in VB from the ones installed in Windows and how would I select which one to print to?
0
 
DhaestCommented:
' List all your pirnters in a combobox:
Dim x As Printer
Dim sDriverName As String

For Each x In Printers
  cmbPrinter.add X
next X

' Print a a specific printer (the one selected in the combobox)
Printer.DeviceName = cmbprinter.text
0
 
villartechAuthor Commented:
I was able to populate a combo box with all of the printers that are installed in Windows. When I use your code example to select a printer - printer.devicename=cmbprinter.text, I get the following error message "wrong number of arguments or invalid property assignment".
0
 
DhaestCommented:
To select the correct printer:  

 sPrinterName = MyDialog.cbbPrinter.Text
    Dim X As Printer
    For Each X In Printers
        If UCase(X.DeviceName) = UCase(sPrinterName) Then
            'Set printer as system default.
            Set Printer = X
            'Stop looking for a printer.
            Exit For
        End If
    Next

By the way ? Why just a c-grade ?
0
 
DabasCommented:
villartech:
This was definitely an A grade answer!

Please refer to:
http://www.experts-exchange.com/help.jsp#hi73
What's the right grade to give?


Dabas
0
 
villartechAuthor Commented:
This code example did not work:
For Each x In Printers
  cmbPrinter.add X
next X

This code example did not work:
' Print a a specific printer (the one selected in the combobox)
Printer.DeviceName = cmbprinter.text

I really appreciate the help, but you need to provide correct information.
0
 
DhaestCommented:
Here a complete piece of code out of my application where I select a specific printer...

Private Sub Form_Load()
'## The Form_Load is triggered when the user opens the form for the first time. _
    It will load all the available printers, configured in windows settings in a combobox.
On Error GoTo FormLoadError
    Dim iCurrentPrinter As Integer

    ModalResult = -1
    cbbPrinter.Clear
    iCurrentPrinter = 0
    Dim X As Printer
    For Each X In Printers
        cbbPrinter.AddItem (X.DeviceName)
        If Printer.DeviceName = X.DeviceName Then iCurrentPrinter = cbbPrinter.ListCount - 1
    Next
    cbbPrinter.ListIndex = iCurrentPrinter
    Exit Sub
FormLoadError:
    ReportError "frmMyDialog-FormLoad", Err.Number, Err.Description
    Resume Next
End Sub

And somewhere else in my code I use the selected printer as next:

    sPrinterName = MyDialog.cbbPrinter.Text
    Dim X As Printer
    For Each X In Printers
        If UCase(X.DeviceName) = UCase(sPrinterName) Then
            'Set printer as system default.
            Set Printer = X
            'Stop looking for a printer.
            Exit For
        End If
    Next
    DoEvents
    'Printer gevonden ?
    If Not (UCase(Trim(Printer.DeviceName)) = UCase(Trim(sPrinterName))) Then
        MsgBox "Printer niet gevonden"
        PrintDialog = False
        Exit Function
    End If
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now