Select Printer Before Executing Print Command

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I used the Application.Printers("PrinterDeviceNameOfDesiredPrinter") function
and it worked fine. However, is there a way to have the desired printer be
obtained from a user selected combo box on a form? I tried using
Application.Printers([Device Name]) but I get an error. [Device Name] being
the field name on the form.

I have a continous form where users can select multiple line items than
select a command button to print/export. I would like the print command to
print to the selected printer with no print dialog box appearing.

Bernie
 
Bernie, here's how I do it:

Application.Reports(strDocName).Printer =
Application.Printers(strPrinter)

HTH
UpRider
 
Sorry...I'm still somewhat new to VBA...how would this be included in my code?

stDocName = “BOM Reportâ€
Set Application.Printer = Application.Printers(“Adobe PDFWriterâ€)
DoCmd.OpenReport stDocName, acViewPreview
Set Application.Printer = Nothing
 
See:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

The article gives you a sample database that lets the user select one of
their installed printers for the report, and explains how to get the report
to remember that printer for the future.
 
Put this code behind the on_click event procedure of a command button on a
form:

dim strDocName as string
dim strPrinter as string
strDocName = "rptSingleLabel" 'substitue your report name
DoCmd.OpenReport strDocName, acViewPreview
'set strPrinter to your printer name, this uses a lookup table
strPrinter = DLookup("[sqlPrinter]", "tblSqlType", "sqlID =" & Chr$(39) &
txtSqlRec & Chr$(39))
'if no printer found in table, the default printer will automatically be
used instead
If Len(strPrinter & vbNullString) > 0 Then
Application.Reports(strDocName).Printer =
Application.Printers(strPrinter)
End If
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
end sub


Bernie said:
Sorry...I'm still somewhat new to VBA...how would this be included in my
code?

stDocName = "BOM Report"
Set Application.Printer = Application.Printers("Adobe PDFWriter")
DoCmd.OpenReport stDocName, acViewPreview
Set Application.Printer = Nothing



Bernie said:
I used the Application.Printers("PrinterDeviceNameOfDesiredPrinter")
function
and it worked fine. However, is there a way to have the desired printer
be
obtained from a user selected combo box on a form? I tried using
Application.Printers([Device Name]) but I get an error. [Device Name]
being
the field name on the form.

I have a continous form where users can select multiple line items than
select a command button to print/export. I would like the print command
to
print to the selected printer with no print dialog box appearing.

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top