Click to See Complete Forum and Search --> : changing the system default printer


September 20th, 1999, 01:49 PM
In VB, you can change the default printer by reassigning the Printer object. However, that only changes the default printer for that application. I am creating an Active X control to be used with other applications (such as Access) that allows changing the default printer. However, reassigning the Printer object no longer works. More precisely, it works inside the control, but not outside the control. The question is, how can I make the control change the system printer for the application using the control?

Here is an example to demonstrate what I'm talking about:

'the following is code inside the control
debug.print Printer.DevName 'displays name of default printer, "printer1"
set Printer = Printers(2) 'changes the default printer to printer number 2
debug.print Printer.DevName 'displays name of default printer, "printer2"
'now exit control code
'execute code of containing program, such as Access or a VB app
debug.printer Printer.DevName 'displays original printer name, "pritner1"




One solution for this is to change the default printer for the entire system. Users can do this manually (e.g., in the control panel), but I need to do it programmatically. Only I can't find an API for this. Anyone got a clue?

Amendra
September 22nd, 1999, 01:32 AM
Dear user
This is not a great idea but might work. why don't you set the printer back to what it was after doing your job, through code.

Amendra

September 22nd, 1999, 12:08 PM
Thanks, but I think you're missing the point... I can't figure out how to make it happen.

The original idea was to have an Active X control that could change the current printer for the application calling the control. Let's say you have an inventory system that runs in Access and you need to print invoices on a dot matrix printer, labels on an inkjet, and reports on a laster printer. There is not automatic way to do this within Access. The idea with the control is that you could write VBA code in Access that says "control, change the current printer to printer #2", and so on. Ideally, the current printer gets reset when you leave the application (in this case, Access), so that it doesn't affect printing from other applications.

This is a great idea, but it doesn't work. When you set the current printer inside a control, it becomes current only for printing from inside the control. So in my scenario above, when you tell the control to change printers, it does, but when you print (from Access), it only prints to the original default printer (printer #1).

Failing this, the next idea was to change the system default printer for Windows. Yes, this is dangerous, and you would have to be careful to change it back when you're done. But in some cases -- and I have a client with such a case -- it would still be useful.

So now I'm back to my original two questions:
1. How do I chang the system default printer?
2. Or is there a way to change the application Printer object from inside a control?

Thanks for replying, anyway.

October 6th, 1999, 03:16 PM
If you haven't found your answer yet, you may want to look at Microsoft KB article #Q135387