Solved

Printer tray selection problem

Posted on 2004-04-15
15
3,199 Views
Last Modified: 2013-12-25
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
Comment
Question by:villartech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 11

Expert Comment

by:bingie
ID: 10834527
0
 

Author Comment

by:villartech
ID: 10835715
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
 
LVL 20

Expert Comment

by:hes
ID: 10835820
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!

 

Author Comment

by:villartech
ID: 10836309
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10839502
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 10839888
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
 

Author Comment

by:villartech
ID: 10842395
I am a novice and am not sure how to add a printer for each tray. Could you supply a code example.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10845333
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
 

Author Comment

by:villartech
ID: 10859862
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
 
LVL 53

Accepted Solution

by:
Dhaest earned 250 total points
ID: 10861196
' 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
 

Author Comment

by:villartech
ID: 10907898
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 10918846
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
 
LVL 27

Expert Comment

by:Dabas
ID: 10922001
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
 

Author Comment

by:villartech
ID: 10922119
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 10925342
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question