Control printer tray from Access vba when printing word documents

Posted on 2007-08-02
Last Modified: 2008-01-09
I'm trying to print a word document using VBA from Access 2003
All is working fine, however I want to be able to control the tray from which the document is printed.
Typically, one tray holds plain paper used for forms, and another has pre-printed staionary for letters.
I suppose I would also like to be able to control the manual feed as well.
I have a letter xref table which has a tray indicator in it.
I use the following code to try to control the trays but it just doesn't seem to work.
(I've tried Upper and middle of the 'M' option)

'check which tray to print from
If strtray = "U" Then
  wordapp.ActiveDocument.PageSetup.FirstPageTray = wdPrinterManualFeed
  wordapp.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterManualFeed
  If strtray = "M" Then
    wordapp.ActiveDocument.PageSetup.FirstPageTray = wdPrinterMiddleBin
    wordapp.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterMiddleBin
    wordapp.ActiveDocument.PageSetup.FirstPageTray = wdPrinterLowerBin
    wordapp.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterLowerBin
  End If
End If

I'm I missing something ?
Question by:EWHTLC
    LVL 17

    Expert Comment

    by:Barry Cunney
    Hi EW
    Is it a case that nothing prints or it just prints to the default tray all the time

    When you debug it does execution go into the correct if clause

    Do the constants wdPrinterMiddleBin etc have valid values behind them?
    LVL 17

    Expert Comment

    by:Barry Cunney
    If you manually go into Page Setup in a Word document can you get the document to print to the different trays?

    Author Comment

    Hmm interesting thoughts.
    At the moment it always prints to the lower tray regardless of the setting of thre strtray field.
    I have checked the contents so the sorrect part of the if clause is being processed, it jst appears to ignore the settings I'm trying to make.

    With regards your other question, yes, the first, and other page settings are available via the 'page setup' from within the word doc.
    LVL 17

    Expert Comment

    by:Barry Cunney
    Hi Ew,
    Can you manually select Middle Tray(Tray 2 or whatever) in Page Setup and then manually print the document to the middle tray. Does the document physically print out to the selected tray?

    We have to prove that this works manually first coz if it does not how can it possibly work in code.
    The code is really just automating a manual process

    Author Comment

    Hi there.

    Firstly, I forgot to thank you for helping me.

    I have checked and yes I can select the approriate tray and it will print.
    However, my printer (which is an HP 2430 dtn) has 3 trays.
    TRAY 1  (which is the manual feed)
    TRAY 2  (which in my case is alwas plain paper)
    TRAY 3  (which is always pre printed letterhead paper. This is an additional tray to the standard purchase)

    So when I select the wsprinterlowerbin it seems to work as the default for the printer is tray 2, but it still comes out on tray 3.
    So it looks like for some reason it doesn't like wdprintermiddlebin.
    Do I have any other options (i.e wdprintertray2bin)
    LVL 17

    Accepted Solution

    In MS Word open a document to print and Record a new macro.
    Then go through the manual steps of selecting a particular tray in Page Setup and then print the document.
    Then stop recording the macro.
    Make a note of which tray the document came out from

    Then Go Into Word Tools | Macro | Visual Basic Editor find the VBA macro that was recorded and look at the settings for

    They should be equal to some number.

    You see wdPrinterMiddleBin etc. are just word constants for a certain number which point to a tray.

    But you can just explicitly specify the number once you can fully confirm the number for the tray.

    I recorded a macro here and  part of the automatically produced VBA is
            .FirstPageTray = 260
            .OtherPagesTray = 260

    So try recording the macro and see if you can establish what numbers represent which tray

    Author Comment

    Will do ...I'll try that...Thanks

    Author Comment

    You sir, are a steely eyed Apps man.
    I managed to get there via the macro route. I had another problem in that my additional tray was not actually identified as being 'installed' and therefore not an option on the page setup. My old (soon to be replaced) software used to get round this by assigning the default tray as being the bottom one on the actual printer. Everything else was automatically sent there by default unless explicitly changed by a windows application..

    I now have a new system which needs to be specific.

    So thank you very much. You have helped not only to solve my problem, but also to understand the existing set up.

    LVL 17

    Expert Comment

    by:Barry Cunney
    Great Stuff EW
    Glad to hear that you are now sorted


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    In a previous video Micro Tutorial here at Experts Exchange (, I explained how to get a free, one-month trial of Office …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    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

    10 Experts available now in Live!

    Get 1:1 Help Now