Print preview looks fine...actual printout is infinite

M

Mackster

MS Access 2003: I am trying to create a report where every page is uniform
regardless of the number of records. In the detail section of the report, I
have the information I would like to display. I can fit exactly five records
on each page. If there is blank space in the detail section after the last
record, the last record is repeated until the last page is filled, but the
repeated record is set to not be visible. I copied the labels for the
controls and pasted them underneath the actual control labels. This way, it
appears to be a pre-printed form without a blank section on the last page.
It works well and the print preview is perfect, showing the proper number of
pages. The problem arises when I try to actually print the report - it will
spool what appears to be an infinite number of pages.

Here is the code
-------code-start-------------
Option Compare Database
Option Explicit
Dim fShowLine As Boolean
Dim intLineNumber As Integer
Dim intLinesUsedThisPage As Integer
Dim intTotalLinesInReport As Integer
Dim intTotalRecordCount As Integer
Const conTotalLinesPerPage As Integer = 5
Dim intTest As Integer
_______________________________
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_Detail_OnFormat

' Determine the maximum number of records in the recordset
intTotalRecordCount = DLookup("[SubCount]", "zquerycount", [OCA])

' Calculate the total number of lines necessary. For example, if the
' conTotalLinesPerPage = 5 and you have 12 records, then in order to fill
' the last page (3rd page) you need 15 records
intTotalLinesInReport = ((intTotalRecordCount \ conTotalLinesPerPage) +
1) * conTotalLinesPerPage

' Handle the page break by assuming it to be NOT VISIBLE
' Then, toggle it visible if we are on the last record for this page.
Me!PageBreakControl.Visible = False
If intLineNumber Mod conTotalLinesPerPage = 0 Then
Me!PageBreakControl.Visible = True
End If

With Me
' If we are under the total count of records, then simply write data
' to the detail section as usual. Moving the layout each time.
If intLineNumber < intTotalRecordCount Then
.MoveLayout = True
.NextRecord = True
.PrintSection = True
Else
' If we are on the last record, print it to the detail section
' and remain here, printing blank lines until finished.
If intLineNumber = intTotalRecordCount Then
.MoveLayout = True
.NextRecord = False
.PrintSection = True
ElseIf intLineNumber = intTotalLinesInReport Then
!SERIAL.Visible = False
!REGYEAR.Visible = False
!EXPYEAR.Visible = False
!YEAR.Visible = False
.MoveLayout = True
.NextRecord = True
.PrintSection = True
Else
!SERIAL.Visible = False
!REGYEAR.Visible = False
!EXPYEAR.Visible = False
!YEAR.Visible = False
.MoveLayout = True
.NextRecord = False
.PrintSection = True
End If
End If
intLineNumber = intLineNumber + 1
End With

Exit_Err_Detail_OnFormat:
Exit Sub

Err_Detail_OnFormat:
MsgBox Err.Description
Resume Exit_Err_Detail_OnFormat

End Sub
___________________________________________
Private Sub Report_Open(Cancel As Integer)
'-- Initialize variables
fShowLine = True
intLineNumber = 1
End Sub
----------code-end---------------------

Thank you for reading this far - I realize it's a lot of information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top