Changing Windows Default Printer

  • Thread starter Thread starter XcelSoft
  • Start date Start date
X

XcelSoft

Is there some VB code to change the windows default
printer from within an Access 2k database???

Thanks,
 
Thanks Steve,

This is what I was looking for. The only problem is I'm
having a problem with the code re-setting the Default
printer. Therefore after the PDF file is created Windows
acts like there is know default printer selected.

I have included the following to no avial.

Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0,
ByVal "windows")

Thanks,

ET Sherman
 
ET,

Using Albert's code, you need to do four steps in your print code:
1. Use GetDefaultPrinter() to hold the name of the original default
printer in a string variable.
2. Use SetDefaultPrinter() to change to your PDF driver.
3. Print the document, presumably using DoCmd.OpenReport
4. Use SetDefaultPrinter() to change back to the original printer.
 
Steve,

Thanks for the reply. That's exactly what I'm doing.
See below.

Private Sub Command79_Click()
Dim strCurrentPtr As String
strCurrentPtr = GetDefaultPrinter
Call SetDefaultPrinter("DocuCom PDF Driver")
DoCmd.OpenReport "WorkOrder_Report", acViewNormal
Call SetDefaultPrinter(strCurrentPtr)
End Sub

I am running XP and Access 2k. I asked Albert and he
said it was designed to work with Win 98. Apparently
it's not compatible with XP. I just need it to reset the
default printer back and I'm done, but it just doesn't
work.

I've tried some other code from the Knowledge Base to no
avial. All seems to be compatible with Win95 or NT.

Sure would be nice if Windows just included the PDF
driver. Sure would make life a lot smoother.

Any help will be appreciated.

Xcelsoft
 
OK Steve, I think I can make it work. Actually, it is
resetting the printer back to the original default
printer. It's just the little check box that is not
displayed in the printers window (no big deal) so I was
thinking the default was not being set. If I open Word,
Excel, Etc. after running the code and just hit the print
icon the document will print to the original default
printer. Some print dialog boxes at first like in Excel
may show blank for the printer name but that's not a big
problem.

Many thanks for your help.

Xcelsoft
 
OK, well it seems you have got it working, anyway. I knew Albert's code
would not be compatible with Access 2002 or Access 2003, but I was not
aware that there was an issue with different Windows versions.
 
Back
Top