• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2560
  • Last Modified:

Control printer tray from Access vba when printing word documents

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
Else
  If strtray = "M" Then
    wordapp.ActiveDocument.PageSetup.FirstPageTray = wdPrinterMiddleBin
    wordapp.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterMiddleBin
  Else
    wordapp.ActiveDocument.PageSetup.FirstPageTray = wdPrinterLowerBin
    wordapp.ActiveDocument.PageSetup.OtherPagesTray = wdPrinterLowerBin
  End If
End If

I'm I missing something ?
0
EWHTLC
Asked:
EWHTLC
  • 5
  • 4
1 Solution
 
Barry CunneyCommented:
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?
0
 
Barry CunneyCommented:
If you manually go into Page Setup in a Word document can you get the document to print to the different trays?
0
 
EWHTLCAuthor Commented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Barry CunneyCommented:
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
0
 
EWHTLCAuthor Commented:
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)
0
 
Barry CunneyCommented:
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
.FirstPageTray
.OtherPagesTray

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
0
 
EWHTLCAuthor Commented:
Will do ...I'll try that...Thanks
0
 
EWHTLCAuthor Commented:
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.

0
 
Barry CunneyCommented:
Great Stuff EW
Glad to hear that you are now sorted

Cheers
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now