CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    changing the system default printer

    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?


  2. #2
    Join Date
    Aug 1999
    Location
    Srilanka
    Posts
    25

    Re: changing the system default printer

    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


  3. #3
    Guest

    Re: changing the system default printer

    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.


  4. #4
    Guest

    Re: changing the system default printer

    If you haven't found your answer yet, you may want to look at Microsoft KB article #Q135387


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured