Select a special printer by VBA code

  • Thread starter Thread starter BrunoKP
  • Start date Start date
B

BrunoKP

Just before the below code, I want to select another printer then the default
printer.
How can I select another printer in the code, and afterwards make sure that
the default printer is set back?
The special printer is a datacard printer, which I don't want to be used for
Word docs. :-)


stDocName = "etkDataCard"
stLinkCriteria = "[IDWAutoLbnr]= " & FirstNewLbnr
DoCmd.OpenReport stDocName, , , stLinkCriteria
Kind regards Bruno
 
If you *always* want to use that printer for this report, just open the
report in design view, open the Page Setup dialog, and specify a "specific
printer."

To programmatically specify a printer in Access 2002 or later, use:
Set Printer = Printers("xx")
where xx is the device name of the printer. To find that exact name, use:
Debug.Print Printers(1).DeviceName

To reset the printer again to the Windows default:
Set Printer = Nothing

If you want the end user to be able to select one of their printers (perhaps
even one you don't have), and have the report remember to use that printer,
see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

That link also contains links for versions of Access earlier than 2002.
 
I have tried:
Debug.Print Printers(2).DeviceName
' Set Printer = Printers("Datacard Printer")
Set Printer = Printers(2)
so I am quit sure that "Datacard Printer" is the exact name.
I have also selected "Datacard Printer" in the design view Page setup dialog.
Nevertheless I still get the report in the other HP Laserjet printer.
It is Access 2007.

"Allen Browne" skrev:
If you *always* want to use that printer for this report, just open the
report in design view, open the Page Setup dialog, and specify a "specific
printer."

To programmatically specify a printer in Access 2002 or later, use:
Set Printer = Printers("xx")
where xx is the device name of the printer. To find that exact name, use:
Debug.Print Printers(1).DeviceName

To reset the printer again to the Windows default:
Set Printer = Nothing

If you want the end user to be able to select one of their printers (perhaps
even one you don't have), and have the report remember to use that printer,
see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

That link also contains links for versions of Access earlier than 2002.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

BrunoKP said:
Just before the below code, I want to select another printer then the
default
printer.
How can I select another printer in the code, and afterwards make sure
that
the default printer is set back?
The special printer is a datacard printer, which I don't want to be used
for
Word docs. :-)


stDocName = "etkDataCard"
stLinkCriteria = "[IDWAutoLbnr]= " & FirstNewLbnr
DoCmd.OpenReport stDocName, , , stLinkCriteria
Kind regards Bruno
 
If this is Access 2007, you need to apply Service Pack 1 from:
http://office.microsoft.com/search/redir.aspx?AssetID=DC102486291033&Origin=HH102511011033&CTT=5
and also the March 31 hotfix from:
http://support.microsoft.com/kb/950488
Otherwise the new version doesn't retain the printer dialog settings.

Setting the printer programmatically must happen *before* the report opens,
i.e. you can't do it in Report_Open (at least, not in acViewNormal.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

BrunoKP said:
I have tried:
Debug.Print Printers(2).DeviceName
' Set Printer = Printers("Datacard Printer")
Set Printer = Printers(2)
so I am quit sure that "Datacard Printer" is the exact name.
I have also selected "Datacard Printer" in the design view Page setup
dialog.
Nevertheless I still get the report in the other HP Laserjet printer.
It is Access 2007.

"Allen Browne" skrev:
If you *always* want to use that printer for this report, just open the
report in design view, open the Page Setup dialog, and specify a
"specific
printer."

To programmatically specify a printer in Access 2002 or later, use:
Set Printer = Printers("xx")
where xx is the device name of the printer. To find that exact name, use:
Debug.Print Printers(1).DeviceName

To reset the printer again to the Windows default:
Set Printer = Nothing

If you want the end user to be able to select one of their printers
(perhaps
even one you don't have), and have the report remember to use that
printer,
see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

That link also contains links for versions of Access earlier than 2002.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

BrunoKP said:
Just before the below code, I want to select another printer then the
default
printer.
How can I select another printer in the code, and afterwards make sure
that
the default printer is set back?
The special printer is a datacard printer, which I don't want to be
used
for
Word docs. :-)


stDocName = "etkDataCard"
stLinkCriteria = "[IDWAutoLbnr]= " & FirstNewLbnr
DoCmd.OpenReport stDocName, , , stLinkCriteria
Kind regards Bruno
 
The SP1 was already installed, but I can't find a link from
http://support.microsoft.com/kb/950488 to make the installation of the hotfix.

Bruno Pedersen

"Allen Browne" skrev:
If this is Access 2007, you need to apply Service Pack 1 from:
http://office.microsoft.com/search/redir.aspx?AssetID=DC102486291033&Origin=HH102511011033&CTT=5
and also the March 31 hotfix from:
http://support.microsoft.com/kb/950488
Otherwise the new version doesn't retain the printer dialog settings.

Setting the printer programmatically must happen *before* the report opens,
i.e. you can't do it in Report_Open (at least, not in acViewNormal.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

BrunoKP said:
I have tried:
Debug.Print Printers(2).DeviceName
' Set Printer = Printers("Datacard Printer")
Set Printer = Printers(2)
so I am quit sure that "Datacard Printer" is the exact name.
I have also selected "Datacard Printer" in the design view Page setup
dialog.
Nevertheless I still get the report in the other HP Laserjet printer.
It is Access 2007.

"Allen Browne" skrev:
If you *always* want to use that printer for this report, just open the
report in design view, open the Page Setup dialog, and specify a
"specific
printer."

To programmatically specify a printer in Access 2002 or later, use:
Set Printer = Printers("xx")
where xx is the device name of the printer. To find that exact name, use:
Debug.Print Printers(1).DeviceName

To reset the printer again to the Windows default:
Set Printer = Nothing

If you want the end user to be able to select one of their printers
(perhaps
even one you don't have), and have the report remember to use that
printer,
see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

That link also contains links for versions of Access earlier than 2002.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Just before the below code, I want to select another printer then the
default
printer.
How can I select another printer in the code, and afterwards make sure
that
the default printer is set back?
The special printer is a datacard printer, which I don't want to be
used
for
Word docs. :-)


stDocName = "etkDataCard"
stLinkCriteria = "[IDWAutoLbnr]= " & FirstNewLbnr
DoCmd.OpenReport stDocName, , , stLinkCriteria
Kind regards Bruno
 
You have to ask Microsoft to send this to you.
Use the first link at the top of the page.
 
Back
Top