Reputation: 603
I currently have an Access 2003 database, which has a form to print a series of reports based off what job the user selects. The query is within the VBA code as well, which looks at the job's cataloged parts and opens their corresponding reports.
Here's the code that does so, correctly:
Private Sub Print_Report_Click()
Dim default_cat As Dao.Database
Dim d As Dao.Recordset
Dim q As String
Set default_cat = CurrentDb
q = "SELECT DISTINCT CATALOG, USER3 FROM [_MASTER_UPLOAD] WHERE SerialNumber='" & Me.[SerialNumberSelection] & "'"
Set d = default_cat.OpenRecordset(q, dbOpenDynaset)
d.MoveFirst
DoCmd.RunCommand acCmdPrint
Do While Not d.EOF
Select Case d!USER3
Case "COM"
DoCmd.OpenReport "RPTCompressor", , , "CATALOG = '" & d!CATALOG & "'"
Case "CON"
DoCmd.OpenReport "RPTCondenser", , , "CATALOG = '" & d!CATALOG & "'"
Case "CRV"
DoCmd.OpenReport "RPTCapacityRegValve", , , "CATALOG = '" & d!CATALOG & "'"
Case "CV"
DoCmd.OpenReport "RPTCheckValve", , , "CATALOG = '" & d!CATALOG & "'"
Case "etc..."
End Select
d.MoveNext
Loop
d.Close
End Sub
Basically now where my problem lies is in the printer selection DoCmd.RunCommand acCmdPrint
. The popup appears and I can select whatever printer I want, however that selection only seems to effect the first report of the group (all the others go to the computer's default printer). Most likely, I'll print the reports out from our print room printer, or just convert them to PDFs, but this also means I can't hardcode it to always print to a specific location.
How can I make my printer selection stay valid for all of the reports, preferably without having to run the acCmdPrint command for every single report in the same group?
Thanks in advance.
EDIT
This question is specified and continued here: How to pass reference to combobox?
Upvotes: 0
Views: 1714
Reputation: 27644
From the first result of googling access vba select printer (just saying):
The easiest way, if your reports are set to print on the default printer, is to temporarily change the default printer:
Set Application.Printer = Application.Printers("myPrinterDeviceName")
DoCmd.OpenReport "FirstReport"
DoCmd.OpenReport "SecondReport"
' ...
Set Application.Printer = Nothing
If not, you can do it per report:
DoCmd.OpenReport "FirstReport", View:=acPreview, WindowMode:=acHidden
Set Reports("FirstReport").Printer = Application.Printers("myPrinterDeviceName")
DoCmd.OpenReport "FirstReport", View:=acViewNormal
The linked page also has an example on how to present a list of available printers for selecting one.
Private Sub GetPrinterList(ctl As Control)
Dim prt As Printer
For Each prt In Printers
ctl.AddItem prt.DeviceName
Next prt
ctl = Application.Printer.DeviceName
End Sub
Upvotes: 1