D
Dale Fye
Hey guys,
Posted this to the reports news group yesterday, and got no response, so
thought I would try here.
I have a couple of custom menus, one on a form that hides the form and opens
a report in preview mode. This particular code opens the report with a
Where parameter to limit it to the record that is currently displayed in the
hidden form (this code works great).
I then created another shortcut menu, this one for the report, to either
print or close the report. Unfortunately, the code for printing the report
is not working as
anticipated. Instead of printing the report, it is printing the form (all
128 records). When I look at rpt.pages, it has the right number of pages,
but the runcommand is actually printing the form that is hidden rather than
the report. Any ideas how to get it to print the open report rather than
the form? I need to be able to use this technique to allow the user to
change printer parameters (printer, single or duplex, etc) before printing.
Public Function fnPrintReport()
Dim rpt As Report
Dim strMsg As String
Dim intResponse As Integer, bPrint As Boolean
On Error GoTo fnPrintReportError
Set rpt = Screen.ActiveReport
bPrint = True
If rpt.Pages > 10 Then
strMsg = "This report contains " & rpt.Pages & " pages! " _
& vbCrLf & vbCrLf _
& "Print this report anyway?"
intResponse = MsgBox(strMsg, vbOKCancel, "Excessive pages")
If intResponse = vbCancel Then bPrint = False
End If
If bPrint Then
On Error Resume Next
With rpt
Application.RunCommand acCmdPrint
On Error GoTo fnPrintReportError
End With
End If
Set rpt = Nothing
DoCmd.Close acReport, Screen.ActiveReport.Name
Exit Function
fnPrintReportError:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation + vbOKOnly,
"Error in fnPrintReport"
End Function
Posted this to the reports news group yesterday, and got no response, so
thought I would try here.
I have a couple of custom menus, one on a form that hides the form and opens
a report in preview mode. This particular code opens the report with a
Where parameter to limit it to the record that is currently displayed in the
hidden form (this code works great).
I then created another shortcut menu, this one for the report, to either
print or close the report. Unfortunately, the code for printing the report
is not working as
anticipated. Instead of printing the report, it is printing the form (all
128 records). When I look at rpt.pages, it has the right number of pages,
but the runcommand is actually printing the form that is hidden rather than
the report. Any ideas how to get it to print the open report rather than
the form? I need to be able to use this technique to allow the user to
change printer parameters (printer, single or duplex, etc) before printing.
Public Function fnPrintReport()
Dim rpt As Report
Dim strMsg As String
Dim intResponse As Integer, bPrint As Boolean
On Error GoTo fnPrintReportError
Set rpt = Screen.ActiveReport
bPrint = True
If rpt.Pages > 10 Then
strMsg = "This report contains " & rpt.Pages & " pages! " _
& vbCrLf & vbCrLf _
& "Print this report anyway?"
intResponse = MsgBox(strMsg, vbOKCancel, "Excessive pages")
If intResponse = vbCancel Then bPrint = False
End If
If bPrint Then
On Error Resume Next
With rpt
Application.RunCommand acCmdPrint
On Error GoTo fnPrintReportError
End With
End If
Set rpt = Nothing
DoCmd.Close acReport, Screen.ActiveReport.Name
Exit Function
fnPrintReportError:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation + vbOKOnly,
"Error in fnPrintReport"
End Function