Here is my situation: I have a multi-user access application. These users have several different network printers available to them. I want to store a printer name and paper tray in a settings table, and have all users print using those settings on certain reports.
My problem comes when I try to set the paper source. How can I set the printer paper source from within code?
Here is what I have already done to try to do this:
I have tried using the Printer.PaperBin property (on both application.Printer and <Report>.Printer), but using different constants (such as acPRBNAuto or acPRBNMiddle) had no effect on the actual paper source.
Research on the web suggested that the built in constants for tray selection may not cover the actual options provided by the printer, and that I should enumerate the available trays using the DeviceCapabilities API. I added some code to do this, as in
however, there is one tray whose number is 15, and the rest (the ones I want) are numbered 257+, and the PaperBin property only accepts values under 256.
I then added a routine to change the paper source using the SetPrinter API, using the code from http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21622398.html
I have the same problem as the linked question; the final call to SetPrinter is returning 0. Of course, my code already implements the accepted solution.
I added a error routine to look at Err.LastDLLError, and the final Setprinter call is returning error code 5, which is "Access is denied." http://support.microsoft.com/?kbid=230743
has some info concerning printer permission, and I assume that this is the same sort of issue. Changing use permissions or creating a local print driver as suggested in that article is not an option however. There must be a way to change the paper source without changing permissions, as Access successfully chooses trays from its printing dialog box.