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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing printer in VBA Access 2000

Status
Not open for further replies.

killercelery

Programmer
May 29, 2003
4
CA
Hi,
I'm trying to change the printer on witch to print a report depending on multiple variables. The printer selection must occur in the code. I considered using APIs such as OpenPrinter, StartDocPrinter, StartPagPrinter, WritePrinter, EndPagePrinter, EndDocPrinter and ClosePrinter, as well as using prtDevMode and prtDevNames, and even writing in Win.ini with WriteProfileString.

The problems are:
for prtDevNames/prtDevMode properties:
I don't have the required information to fill the structs (anybody knows where Windows keeps the printer name, version, driver name...)

for the APIs:
VBA doesn't support pointers, and all the APIs require pointer. I found OpenPrinter witch returns a pointer to the printer, but I can't find anything for a pointer to the report i want to print and for the data to be printed.

for the .ini:
I can write in Win.ini, but it doesn't seem to work thus far, maybe the section or key or value isn't right. Anyway, my boss doesn't want to push this way...

Thanks for any help!!
 
Here is a litle piece of code that will give you the Printer, Driver and Port for each printer on your system.

Dim prtLoop As Printer

For Each prtLoop In Application.Printers
With prtLoop
MsgBox "Device name: " & .DeviceName & vbCr _
& "Driver name: " & .DriverName & vbCr _
& "Port: " & .Port
End With
Next prtLoop

when you need to print to a certain printer you can use

Set Application.Printer = Application.Printers(0)
Where Printers (0) is the index number of the desired printer iin the printers collection.

 
The Printers collection does not exist in Access 2000, I believe it was added in Access XP.
 
Hi,

had the same problem with Access 2000. I tracked it all the way down. Finding any printer and choosing a tray is no problem but when it comes to select the new printer you are in serious trouble. Background: You have to fill out a API Structure with the new printer. The memory (extra mem) for this structure is allocated by Access, so you can't change the size. When you are filling in a network printer with a long name . . . Bang!

Public Type DEVNAMES
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
Extra(98) As Byte
End Type

Replacing the structure would mean to have a memory handle and to set a memory handle.

heres the solution for access 2k:

Select printer in your form or whatever. Shortly before printing set the default printer to your selected printer.
print form (att: form has to be setup to default printer in page setup!) and change default printer back. While printing you can change the PrtDevMode properties for tray, etc.

Hope it helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top