Printing a report to a specific printer

  • Thread starter Thread starter Wendy Clarkson
  • Start date Start date
W

Wendy Clarkson

Hi

I run a macro (Access 2003) which creates several reports, I would like to
send these reports direct to the sites printers over the network using the
same macro but I cannot see an option to print a report at a specific
printer. Can anyone help please?

Thanks

Wendy
 
You need to open the reports in turn in design mode and then click on File,
Page Setup from the top menu. You then select the relevant printer for each
report. When you then save and close the report the printer information will
be saved with it. You then don't need to change your macro at all as when the
report is printed it will print to the printer you specified.
 
Wendy:

You don't actually need to do this as Dennis suggested (Opening in design
mode). However, you do need to use Visual Basic for Applications to
accomplish your goal in Access 2002 and greater, it can't be done purely as
a macro.

VB provides the ability to address and change Access' printer object, which
when set, tells Access which printer to use when printing reports (provided
the report is set to use the default printer in their File -> Page Set Up ->
Page setting.)

You can do this using two small functions like those shown below and call
them from your macro using the RunCode Macro call, supplying the report name
and the name of the printer as it appears on your machine in the print
dialog box (e.g. \\SomeServer\SomeNetworkPrinter )

Hope this helps
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

----------Cut and Paste Into VB Module---------------

Public Function PrintReportToPrinter(strReportName as String, _
strPrinterName as String, _
Optional strWhere as String)
On Error GoTo ErrHandler
'Set the Target Printer
Call SetAppPrinter (strPrinterName)
Do Events
'Send the Report
If Len(strWhere) >0 Then
DoCmd.OpenReport strReportName, acViewNormal, , strWhere
Else
DoCmd.OpenReport strReportName, acViewNormal
End if
ExitProc:
Exit Function
ErrHandler:
MsgBox "Error: " & Err.Number & " " & Err.Description
Resume ExitProc
End Function

Private Sub SetAppPrinter(strPrinterName As String)
On Error Resume Next
Dim objPrn As Object
Dim App As Object
Dim strPrinter As String
Set App = Application
If Val(SysCmd(acSysCmdAccessVer)) >= 10 Then
For Each objPrn In App.Printers
strPrinter = objPrn.DeviceName
If strPrinter = strPrinterName Then
Set App.Printer = objPrn
End If
Next
End If
End Sub

-------------end code---------------
 
Hi Steve

Thanks it works.

Wendy



SA said:
Wendy:

You don't actually need to do this as Dennis suggested (Opening in design
mode). However, you do need to use Visual Basic for Applications to
accomplish your goal in Access 2002 and greater, it can't be done purely as
a macro.

VB provides the ability to address and change Access' printer object, which
when set, tells Access which printer to use when printing reports (provided
the report is set to use the default printer in their File -> Page Set Up ->
Page setting.)

You can do this using two small functions like those shown below and call
them from your macro using the RunCode Macro call, supplying the report name
and the name of the printer as it appears on your machine in the print
dialog box (e.g. \\SomeServer\SomeNetworkPrinter )

Hope this helps
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

----------Cut and Paste Into VB Module---------------

Public Function PrintReportToPrinter(strReportName as String, _
strPrinterName as String, _
Optional strWhere as String)
On Error GoTo ErrHandler
'Set the Target Printer
Call SetAppPrinter (strPrinterName)
Do Events
'Send the Report
If Len(strWhere) >0 Then
DoCmd.OpenReport strReportName, acViewNormal, , strWhere
Else
DoCmd.OpenReport strReportName, acViewNormal
End if
ExitProc:
Exit Function
ErrHandler:
MsgBox "Error: " & Err.Number & " " & Err.Description
Resume ExitProc
End Function

Private Sub SetAppPrinter(strPrinterName As String)
On Error Resume Next
Dim objPrn As Object
Dim App As Object
Dim strPrinter As String
Set App = Application
If Val(SysCmd(acSysCmdAccessVer)) >= 10 Then
For Each objPrn In App.Printers
strPrinter = objPrn.DeviceName
If strPrinter = strPrinterName Then
Set App.Printer = objPrn
End If
Next
End If
End Sub

-------------end code---------------
 
Back
Top