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!

Control of Printers with Access

Status
Not open for further replies.

trainman319

Programmer
Mar 22, 2003
16
US
I am sure that others have had the need for this functionality. I have an access application that needs to print to two different printers.

Currently, the user selects the printer they want to print to via Windows. The user then has to remember to reset the default printer or the next print job might be printed on the wrong stock.

I have managed with Access code to set the default printer, but what is really needed is for Access to send its output to a selected printer which may or may not be the default printer and then return to the previous printer setting when printing is complete.

Any ideas? I am Open to any and all suggestions.
 
Access2002/2003 not too difficult.
Earlier than that quite difficult to almost impossible.

Which version?

 
Thisis the sort of code you can use:
It uses a combo box (cboPrinters) on the user form to hold a list of available printers. Initially the combo shows the current default printer and stores the index of that printer.

The user picks one from the list and the system changes the default printer.
After the open report statement you need to reset the default printer to its original setting.


Dim OrigPrtIndex As Long

Private Sub Form_Load()

Dim prt As Printer
For Each prt In Application.Printers
cboPrinters.AddItem prt.DeviceName
Next prt
Me.cboPrinters = Application.Printer.DeviceName
OrigPrtIndex = Me.cboPrinters.ListIndex

End Sub

Private Sub cboPrinters_AfterUpdate()
Dim prtIndex As Long
prtIndex = Me.cboPrinters.ListIndex
Set Application.Printer = Application.Printers(prtIndex)
End Sub

'Put this immediately after your openreport statement to reset the printer to the original default.
Set Application.Printer = Application.Printers(OrigPrtIndex)
 
Wow - I can't belive its that simple. I will give it a try and let you know.

Thanks
 
Well it worked great on 2002.

Just for fun, I tried to run the same form on Access 2000. It turns out that it doesn't understand what a printer is. I am sure this is what you were referring to.

I would be interested to see how to do this in the older versions.

Thanks again.

 
There is no Printer object in earlier versions. The code for A2000 runs into hundreds of lines but you'll find it on Google somewhere if you search. I don't have it here.
 
Thank you. I don't need it now, but I was curious. When I have some extra time (ha!), I will try to find it.

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top