Solved

Printer tray selection problem

Posted on 2004-04-15
15
3,188 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
  • 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now