F
flores
I created a form that uses a tab control to display two full pages. Page1
and Page2 are the tab's names (index 0 and 1). The two pages are bound to a
single table called tblComplaints. Each page was designed to fit on an 8.5"
by 11" page and to print as seen on the screen. Then I saved the form as
REPORT called rptComplaints. The report looks exactly as the form, it has
two pages (two tabs) and each page fits on one page.
I am sharing the code I wrote to print the rptComplaints. The code is
called from a command button on frmComplaints. It creates a filter to show
only one record based on control ComplaintNo from frmComplaints. Then the
report is sent to the printer. The problem is that it prints only Page1
(index 0), and page2 (index 1) is not printed.
Can someone tell me what code I should use to print both pages of the
report’s Tab Control (call it tabCtrl)?
This is the code that prints the report, but it prints only page1:
Private Sub cmdPrintComplaint_Click()
'
Dim ReportName$
Dim rprt As Access.Report, ReportObj As Object
Dim dbs As Object
ReportName$ = "rptComplaints"
Set dbs = Application.CurrentProject
Set ReportObj = dbs.AllReports.Item(ReportName$) ' to use IsLoaded
On Error GoTo Err_Handler
WhereClause$ =
"([tblComplaints]![ComplaintNo]=Forms!frmComplaints!ComplaintNo)" '&
Forms!frmComplaints!ComplaintNo & ")"
If ReportObj.IsLoaded Then 'Close report if it is already open
DoCmd.Close acReport, ReportName$, acSaveNo
End If
DoCmd.OpenReport ReportName$, acViewNormal, , WhereClause$ ' This prints
the report without previewing.
Set rprt = Reports(ReportName$)
DoCmd.SelectObject acReport, ReportName$, False
rprt.ZoomControl = 90 ' set view to 90 percent zoom
Exit_Proc:
Set dbs = Nothing
Set ReportObj = Nothing
Set rprt = Nothing
Exit Sub
Err_Handler:
If Err.Number = 2501 Then ' Canceled operation, report has no data.
Me.SetFocus ' return to input form, maximized.
End If
Resume Exit_Proc
End Sub
and Page2 are the tab's names (index 0 and 1). The two pages are bound to a
single table called tblComplaints. Each page was designed to fit on an 8.5"
by 11" page and to print as seen on the screen. Then I saved the form as
REPORT called rptComplaints. The report looks exactly as the form, it has
two pages (two tabs) and each page fits on one page.
I am sharing the code I wrote to print the rptComplaints. The code is
called from a command button on frmComplaints. It creates a filter to show
only one record based on control ComplaintNo from frmComplaints. Then the
report is sent to the printer. The problem is that it prints only Page1
(index 0), and page2 (index 1) is not printed.
Can someone tell me what code I should use to print both pages of the
report’s Tab Control (call it tabCtrl)?
This is the code that prints the report, but it prints only page1:
Private Sub cmdPrintComplaint_Click()
'
Dim ReportName$
Dim rprt As Access.Report, ReportObj As Object
Dim dbs As Object
ReportName$ = "rptComplaints"
Set dbs = Application.CurrentProject
Set ReportObj = dbs.AllReports.Item(ReportName$) ' to use IsLoaded
On Error GoTo Err_Handler
WhereClause$ =
"([tblComplaints]![ComplaintNo]=Forms!frmComplaints!ComplaintNo)" '&
Forms!frmComplaints!ComplaintNo & ")"
If ReportObj.IsLoaded Then 'Close report if it is already open
DoCmd.Close acReport, ReportName$, acSaveNo
End If
DoCmd.OpenReport ReportName$, acViewNormal, , WhereClause$ ' This prints
the report without previewing.
Set rprt = Reports(ReportName$)
DoCmd.SelectObject acReport, ReportName$, False
rprt.ZoomControl = 90 ' set view to 90 percent zoom
Exit_Proc:
Set dbs = Nothing
Set ReportObj = Nothing
Set rprt = Nothing
Exit Sub
Err_Handler:
If Err.Number = 2501 Then ' Canceled operation, report has no data.
Me.SetFocus ' return to input form, maximized.
End If
Resume Exit_Proc
End Sub