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

Changing Printer Properties

Status
Not open for further replies.

GaryRW

Programmer
Mar 8, 2002
67
0
0
GB
I have developed a very annoying problem...

For background, I am using Access to load and run Word and then run mailmerges in word using info from Access. For each merged document, I need to print one copy on headed paper, one copy on plain. This was working fine, and I had originally recorded a macro to print both copies, by changing the paper source property (FirstPageTray, OthersPageTray)

My Network administrator has changed the printer settings on the printer that I am using, so that now, instead of naming the tray, you name the paper type that you want (plain or LetterHead) and has now gone on holiday for two weeks.

The problem is that I can't change the paper type setting in VBA code from Word. I have tried recording a macro, but any changes to the paper type are ignored by the macro (presumably because they are printer settings for all applications, not just Word).

Can anyone give me any pointers as to how you change the printer properties from Access or Word VBA. Any help would be very much appreciated
 
I think I posted the above when any clever americans would have been asleep, so hopefully by adding this to the bottom, it might bring it to the attention of someone who can help me (worth a try...)

Thanks everyone
 
Hi,

Try the following code in the Form_Load event. The code will display the device name of each printer attached to the system. You can explore the properties and methods of the Printer object ( prn, in this case ) and modify the code to suit your needs.

Dim prn As Printer
Dim prns As Variant
Set prns = Printers
For Each prn In prns
MsgBox prn.DeviceName
Next prn Hope it helps. Let me know what happens.
With regards,
PGK
 
Thanks PGK

I'm getting a "User-defined type not defined" error.

I'm hoping that this is just that I haven't got a specific object library referenced - any ideas which one covers the Printer Object? (I'm assuming that once I have the library referenced, I can try your hint from Word just as well as Access?)

Cheers
 
Hi,
The code that I posted was in VB. I am not 100% sure if it work there in Access. Hope it helps. Let me know what happens.
With regards,
PGK
 
Ahhh,

Nope, didn't work. I tried referencing any object libraries that looked vaguely likely to contain the Printer object, but I kept getting the above error message.

(Oh - just done some searching on general web and I think that a downfall of Access VBA is that it doesn't include the Printer Property like VB)

Thanks for the help though - any other approaches I can try?

 
Hi,
There are some API calls like GetPrinter the decalarations of which I found. You will ahve use these calls to get the info. This is the maximum I can do for you since I am not well versed with API calls.

Public Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long

Public Declare Function GetPrinterData Lib "winspool.drv" Alias "GetPrinterDataA" (ByVal hPrinter As Long, ByVal pValueName As String, pType As Long, pData As Byte, ByVal nSize As Long, pcbNeeded As Long) As Long

Public Declare Function GetPrinterDriver Lib "winspool.drv" Alias "GetPrinterDriverA" (ByVal hPrinter As Long, ByVal pEnvironment As String, ByVal Level As Long, pDriverInfo As Byte, ByVal cdBuf As Long, pcbNeeded As Long) As Long

Public Declare Function GetPrinterDriverDirectory Lib "winspool.drv" Alias "GetPrinterDriverDirectoryA" (ByVal pName As String, ByVal pEnvironment As String, ByVal Level As Long, pDriverDirectory As Byte, ByVal cdBuf As Long, pcbNeeded As Long) As Long

You could try out the API forum in Tek-Tips. Hope it helps. Let me know what happens.
With regards,
PGK
 
Cheers PGK - Will do, though it may take some time, my knowledge of API is nil, but at least it's a start...
 
I also had this problem, but Microsoft seem to have sold it in Access 2002 where you can use the printer object.

If you have Access 2002, search for printer object in the help in VB.

Although this didn't seem to help very much at first, i basically change the printer setting on each machine, installing one printer to default to letterhead and the other to plain paper. I then just told access which of the 2 printers to use to make it print correctly.

It worked quite nicely, apart from i adandon it because access 2002 runtime programme seems to cause more problesm than it solved

Hope that was some help

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top