Solved

Understanding vba control of printer bins

Posted on 2006-06-28
10
771 Views
Last Modified: 2009-11-06
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

0
Comment
Question by:looper8
  • 5
  • 3
10 Comments
 
LVL 1

Author Comment

by:looper8
ID: 17002239
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!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17002320
what if u output your report to Word then do your word auto like u have demonstrated?
0
 
LVL 1

Author Comment

by:looper8
ID: 17012831
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.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17013388
Nice, have a good weekend then

Mine is just an alternative option, there may be better ways, I don't know
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Author Comment

by:looper8
ID: 17035773
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.
0
 
LVL 1

Author Comment

by:looper8
ID: 17043882
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17045917
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
0
 
LVL 1

Author Comment

by:looper8
ID: 17071138
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 ...
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17076277
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

920 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

13 Experts available now in Live!

Get 1:1 Help Now