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

Printer PaperBin Property Is Not Working - Why? 2

Status
Not open for further replies.

TripleJHJO

Programmer
Jan 10, 2003
76
0
0
US
OK! I am about to beat my head into a wall.
This seems sooooo simple, yet I am missing something here.
When I try to set the .PaperBin property, I am getting an Invalid Property error. This printer (HP4300) has an envelope feeder and should be accepting this command, but it is not. All other lines of code execute, except the PaperBin.
Do I need additional code?
I am including my example code:
Code:
    On Error GoTo Cancel_It
    
    cmdbPRINT.PrinterDefault = False
   
    cmdbPRINT.Flags = cdlPDReturnDC + cdlPDNoPageNums
    If txtAddress.SelLength = 0 Then
        cmdbPRINT.Flags = cmdbPRINT.Flags + cdlPDAllPages
    Else
        cmdbPRINT.Flags = cmdbPRINT.Flags + cdlPDSelection
    End If
    
    cmdbPRINT.Orientation = cdlLandscape
    Printer.PaperSize = vbPRPSEnv10
    Printer.PaperBin = vbPRBNEnvelope
    cmdbPRINT.ShowPrinter
    txtAddress.SelPrint cmdbPRINT.hDC
   
Cancel_It:

End Sub
 
Could be a quirk in the driver for the HP4300 I suppose.
The vbPRBNEnvelope constant equates to 5. Have you tried values for PaperBin other than 5 (i.e. 1-4 and beyond).
 
Yes I have tried many values. Each one gives the same result.
 
I found a link that might be helpful, although it's in French:
There are three posts. My French is passable so I'll see if I can explain them. The first post describes exactly the same problem that you're having, but for a HP LJ 2300N.

The second poster basically says that Microsoft documentation says that sometimes the values provided aren't accurate, and that other values are acceptable. So, it's a good idea to test other values in case HP provides the wrong ones.

The next fellow says that he tried looping through values 1 through 65535, with the following numbers working:

15 bac 3
257 bac 1
259 bac 3
260 bac 2
261 bac 1
262 bac 3
1002 bac 1 papier transparent
1257 bac 1 papier rugueux
1258 bac 1 enveloppe
1259 bac 1 carton
1260 bac 1 papier couleur
1261 bac 1 papier recyclé
1262 bac 1 papier A4
1263 bac 1 etiquettes
1264 bac 1 papier perforé
1265 bac 1 papier à entête
1266 bac 1 papier pré-imprimé
1267 bac 3
1268 bac 3

where "bac" is bin. I'm not quite clear on why there appear to be all different types of paper in bin 1, but the value 1258 looks interesting here.

Perhaps what to take from this is to try more numbers.

HTH

Bob
 
Well Bob, you are on the right track. I tested a couple of numbers and they are certainly not generating the error. The 1258 did not pull from the envelope feeder, but it did pull from a plain paper tray. Would you have any suggestions as to how to test through the other values without printing a bunch of paper?

Thanks for getting me this far.

J. Jensen
 
Nice, Hugh! JJ, I'll be interested to know if it works.
 
I had saw this article a few days ago as well and tried it, however, I am not sure how the 'activeprinter' variable is filled or what the value should be. I am currently trying to work through it. I will let you know what I find.

Jeff
 
ActivePrinter appears to be a literal string(because it is not declared and stringy things are being done to it) so I guess it just has to be replaced with one of the names listed in the OSs Printer window e.g. "hp deskjet 6127" taken from mine.
 
Well, I have been trying several variations of printer/port naming with no success. The DeviceCapabilities call with in the GetBinNames procedure keeps returning a fail code (-1) with an error number of "1801-Invalid printer name". I agree that this code will probably give me the bin names/#'s that I need, but I can't seem to get this example to work.
If someone has some success in executing this, please let me know how you accomplished it.

Thanks,

J. Jensen
 
I seem to have both routines working for the Default Printer like this;

I'm not quite sure what is supposed to be going on with the sPort and sCurrentPrint variables in the original code.


Public Function GetBinNumbers() As Variant

'Code adapted from Microsoft KB article Q194789
'HOWTO: Determine Available PaperBins with DeviceCapabilities API
Dim iBins As Long
Dim iBinArray() As Integer
Dim sPort As String
Dim sCurrentPrinter As String

'Get the printer & port name of the current printer
' sPort = Trim$(Mid$(ActivePrinter, InStrRev(ActivePrinter, " ") + 1))
' sCurrentPrinter = Trim$(Left$(ActivePrinter, _
InStr(ActivePrinter, " on ")))

'Find out how many printer bins there are
iBins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
DC_BINS, ByVal vbNullString, 0)

'Set the array of bin numbers to the right size
ReDim iBinArray(0 To iBins - 1)

'Load the array with the bin numbers
iBins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
DC_BINS, iBinArray(0), 0)

'Return the array to the calling routine
GetBinNumbers = iBinArray
End Function
 
Right on Hughlerwell. That worked like a champ.

Many Thanks!!!!
 
For what it's worth: I had this same problem over the last couple weeks while trying to print Word documents from my VB6 app. The biggest part of the problem was that using the PaperBin property to set the output tray on the printer just plain didn't work, neither did trying to specify the tray via winspool.

I ended up discovering the Word Application.Options.DefaultTrayID property. It worked perfectly when I tested it on my IBM 1125, but failed miserably when trying to use an IBM 1332.

A variation of HughLerwill's GetBinNumbers function allows the program to determine the available tray numbers at program initialization and successfully address the trays during execution - regardless which printer is being used. (The 1125 reports 1 & 2 as the ID for Tray 1 and Tray 2 respectively, but the 1332 uses 256 & 257 for them.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top