Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling printers from VBA

Status
Not open for further replies.

handlebars

Technical User
Feb 18, 2003
270
GB
I have created an automation routine in VBA to print a number of documents to various specifications, some needing dublex printing, some on letter head etc.

Unfortunately, some of these setting are not available thru VBA, so I have got around it by creating multiple instances of the same network printer, but changed the settings so that one is defaulted to duplex, one to letterhead, etc.

I have given them appropriate names and forced the printers by using the activeprinter = \\fredsrv01\bother HL 4200, etc.

This appears to work ok, but can anyone suggest any major flaws in this approach?

I have read some info on sendkeys, but am not sure if this would be a better solution?

Any views would be appreciated.

Andrew
 
Hi

Which version of Access are you using?, Access 2003 has a printers collection which allows you to manipulate printers much more easily than in previous versions

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Using a mixture of 2k and xp (that is 2003 or is it?)

I have basically used features available from word vba macros, and have noticed that there is a default tray option and also a duplex option.

Do you see anything inherently wrong with my solution?

Andrew
 
Hi

Now XP is 2002

I do not see anything 'wrong' in your solution, given the tools you have at your disposal. There is a PrtDev option in Access VBA which allows you to tinker with printer settings, this has been available since A97 at least, but it is complex to use. The only thing which I do not like about your solution is that you are at the mercy of anyone who reconfigures the available printers, but as I say, given what you have to work with it as workable having complex code to manipulate the available printer option in the versions of access you are using

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
I am trying to do a similar thing at the moment from Excel - I would suggest looking at the following thread
The SendKeys code seems to work quite well - my main handicap has been that the photocopier that I am working with has broken - dont suppose I can blame that on the code provided though :)

Elise
 
I am trying to do something similar. I am working in Access 2003 and trying to print a report to another printer. I don't want the user to choose because they tend to forget. I have looked at the help files and microsoft's knowledge base, but when I try to apply them I get an invalid call or procedure. I tried using the following:

<code>
With AppStat.Printers

sCurPrinter = .ActivePrinter 'Store current printer.
.ActivePrinter = "NewPrinter" ' Change Printers.
ActiveDocument.PrintOut 'Print the active document.
.ActivePrinter = sCurPrinter ' Set printer back to current.
End With
<\code>

Access tells me that it does not recognize the .ActivePrinter. I have tried looking through the Object browser to find it and was not able to. I have looked to see if I am missing any references, but I don't really know what to look for.

Then I tried to do this another way:
<code>
dim rpt as Report
dim prt as Printer
DoCmd.OpenReport "MyReport", acViewPreview
sCurPrinter = Application.Printer.DeviceName
Set rpt = Reports("MyReport")
Set prt = Application.Printers("NewPrinter")
Set Application.Printer = prt
rpt.Printer = prt
DoCmd.Close acReport, "MyReport", acSaveNo
<\code>

I am able to get the name of my original default printer, but the code gives me an invalid procedure or call on the line where I try to set rpt.

Any suggestions are welcome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top