Link to home
Start Free TrialLog in
Avatar of looper8
looper8

asked on

Understanding vba control of printer bins

I'm trying to get vba code that I can use to specify which printer bin is used for printing (to get some things to print on headed paper).  When I'm printing a report I've been using the code below (called from a button using Call PrintPages(Me.cboReportList, Me.cboFirstPage)).  I've tested all the possible Access constants on the relevant printer and they all printed out via the default tray (i.e. don't seem to be understood), except the Cassette constant which worked.  On another printer I got the middle tray working using the Upper tray constant!  Is there any way to use these constants in a less hit and miss way?

Then I found code of how to find what bins (names & numbers) are available on a certain machine.  This returned a list of about 25 bins for my main printer, with numbers from 15 to 1257.  I don't undestand how to use these.  Are they perhaps for use when controlling the printing of a Word document rather than an Access report?

Private Sub PrintPages(strReport As String, _
 PaperBin As AcPrintPaperBin)
   
    Dim rpt As Report
 
    On Error GoTo HandleErrors
 
    DoCmd.OpenReport strReport, acViewPreview, WindowMode:=acIcon
    Set rpt = Reports(strReport)
    rpt.Printer.PaperBin = PaperBin
   
    ' Unfortunately, you have to select the
    ' report in order to print it. Who wrote
    ' the PrintOut method this way, anyway?
    DoCmd.SelectObject acReport, strReport
    DoCmd.PrintOut acPages, 1, 1
   
ExitHere:
    DoCmd.Close acReport, strReport, acSaveNo
    Exit Sub

HandleErrors:
    MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
    Resume ExitHere
End Sub

Avatar of looper8
looper8

ASKER

OK, so since I posted I've discovered that the list of about 25 numbers I got can be use in the following way.  When printing out a Word document from Access you can do something like this:

With m_objWord.ActiveDocument
        .Save
    ' First page goes to letterhead, others to plain
        .PageSetup.FirstPageTray = 263
        .PageSetup.OtherPagesTray = 262
        .PrintOut
    End With

So if it's a Word doc looks like I'm OK ... but I'm principally needing to print Access reports!
Avatar of rockiroads
what if u output your report to Word then do your word auto like u have demonstrated?
Avatar of looper8

ASKER

Thanks rockiroads.  I ought to give that a try.  I initially dismissed it because I assumed that it would change the report layout too much ... but my assumptions aren't always right to say the least!

Got a couple of days off now (hallelujah) so will get back to you after the weekend.
Nice, have a good weekend then

Mine is just an alternative option, there may be better ways, I don't know
Avatar of looper8

ASKER

For once my assumption was correct - Word changes the report formatting quite considerably.  So I'm stuck with trying to output using the Access constants (acPRBNAuto etc etc ... do a find on 'paperbin' in Object Browser).  Also a good relevant chapter on printing in the Access Cookbook.

Seems to vary from printer to printer as to how these constants work.  Bit hit and miss as to which constant is understood in which way by which printer - in a good number of cases the printer doesn't understand at all and just uses the default paper tray.  Anyhow I think I can do enough on one of our printers to keep the users happy.
Avatar of looper8

ASKER

I've gone with the following.  I've changed the printer for each relevant report to the specific one I can manage to control with acPRBNLower.  And  it'll be fine unless that printer goes down!  I've given the users a combo box to change their Access default printer to any other installed printer, but I think that will be overridden by the specific printer specified in the reports.  I'll see how it goes!

'Open and print the report
   
    strLinkCriteria = " a.AllegationID = " & Me.txtAllegationID        
    DoCmd.OpenReport strReport, acViewPreview, , strLinkCriteria, WindowMode:=acIcon    
    Set rpt = Reports(strReport)
   
    'Even though this says Lower for the paper bin, it prints out from the upper bin of the HPLJ212 in SPU/CAT!!
    rpt.Printer.PaperBin = acPRBNLower
   
    DoCmd.SelectObject acReport, strReport
    DoCmd.PrintOut acPages, 1, 1
   
End If
   
ExcludeLetter_Exit:
    DoCmd.Close acReport, strReport, acSaveNo
Exit Sub
Sorry I couldnt of been more help

I just had another look

I found this though, it does refer to Word VBA, but u may be able to make use of it
http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=101

and this  http://support.microsoft.com/?kbid=279506
which is basically what u have done
Avatar of looper8

ASKER

Thanks rockiroads, I'd actually already seen those docs.  Of course one thing we didn't mention was to set each report's properties to print to a specific printer.  But I think that gives the same options as we've already had.  Something else I'm going to try is to install a second copy of a particular printer I want to control onto the server, and then play around with the settings (thus not interfering with day-to-day print jobs).  Maybe it'll be useful ...
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial