D
Dale Fye
Hey, guys,
I have a couple of custom menus, one on a form that hides the form and opens
a report in preview mode that only contains the record currently displayed
on the 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?
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
I have a couple of custom menus, one on a form that hides the form and opens
a report in preview mode that only contains the record currently displayed
on the 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?
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