Constant Number Of Lines On Report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using code provided by Microsoft on how to print a constant number of
lines on a report. I use it for forms where the printed form has to have x
number of blank lines (the lines are really boxes and they print -- think of
most any form you've seen that has lines for multiple entries). My database
fills in those lines where there is data, and then prints the remaining
number of lines to fill the page. My problem is that the code works fine as
long as the number of used lines is 2 less than the maximum allowable on the
page. If the number of records is one or two less than the maximum, the last
record prints twice. For example, I have a form with 15 lines on it. If there
are 10 records, each one prints just fine (no duplicates) with 5 lines below.
If there are 14 or 15 records, the last one prints twice and no blank lines
are printed. I've tried everything I can think of to avoid this behavior
without success. Can anyone help me?
 
I don't know how MS suggests you make the lines. The solution I use is to
draw the lines with code in the On Page event of the report. This code draws
24 lines regardless of the number of records on the page.

Private Sub Report_Page()
Dim intRows As Integer
Dim intLoop As Integer
Dim intTopMargin As Integer
Dim intDetailHeight As Integer
intRows = 24
intDetailHeight = Me.Section(0).Height
intTopMargin = 360
For intLoop = 0 To intRows
Me.CurrentX = 20
Me.CurrentY = intLoop * intDetailHeight + intTopMargin
Me.Line (0, intLoop * intDetailHeight + intTopMargin)- _
Step(Me.Width, intDetailHeight), , B
Next
End Sub
 
Duane: Here are the functions (modified for my needs) that are being used in
the OnPrint event of the Group Header and Detail sections respectively. I was
able to use the code you supplied successfully, except that I had to modify
the top margin value to make the lines start printing lower on the page, as
there is a page header and a group header section that shouldn't have the
lines. As long as I have something that works, I'm happy, except that I have
several applications where I need the ability to control the number of lines
within sections of a report and it would be nice if the functions below could
be make to work reliably without duplicating the last record when the total
count of the records is equal to the TotGrp value.

Public Function SetCount(R As Report)
TotCount = 0
R![Destination].Visible = True
R![EventDate].Visible = True
R![PickUpTime].Visible = True
R![DropOffTime].Visible = True
R![NumStudents].Visible = True
R![NumBuses].Visible = True
End Function

Public Function PrintLines(R As Report, TotGrp)
TotCount = TotCount + 1
If TotCount = TotGrp Then
R.NextRecord = False
ElseIf TotCount > TotGrp And TotCount < 14 Then
R.NextRecord = False
R![Destination].Visible = False
R![EventDate].Visible = False
R![PickUpTime].Visible = False
R![DropOffTime].Visible = False
R![NumStudents].Visible = False
R![NumBuses].Visible = False
End If
End Function
 
I don't care to reverse engineer their code. I would just use the code that
I know works.

--
Duane Hookom
MS Access MVP
--

DataLady said:
Duane: Here are the functions (modified for my needs) that are being used
in
the OnPrint event of the Group Header and Detail sections respectively. I
was
able to use the code you supplied successfully, except that I had to
modify
the top margin value to make the lines start printing lower on the page,
as
there is a page header and a group header section that shouldn't have the
lines. As long as I have something that works, I'm happy, except that I
have
several applications where I need the ability to control the number of
lines
within sections of a report and it would be nice if the functions below
could
be make to work reliably without duplicating the last record when the
total
count of the records is equal to the TotGrp value.

Public Function SetCount(R As Report)
TotCount = 0
R![Destination].Visible = True
R![EventDate].Visible = True
R![PickUpTime].Visible = True
R![DropOffTime].Visible = True
R![NumStudents].Visible = True
R![NumBuses].Visible = True
End Function

Public Function PrintLines(R As Report, TotGrp)
TotCount = TotCount + 1
If TotCount = TotGrp Then
R.NextRecord = False
ElseIf TotCount > TotGrp And TotCount < 14 Then
R.NextRecord = False
R![Destination].Visible = False
R![EventDate].Visible = False
R![PickUpTime].Visible = False
R![DropOffTime].Visible = False
R![NumStudents].Visible = False
R![NumBuses].Visible = False
End If
End Function
--
Sue A


Duane Hookom said:
I don't know how MS suggests you make the lines. The solution I use is to
draw the lines with code in the On Page event of the report. This code
draws
24 lines regardless of the number of records on the page.

Private Sub Report_Page()
Dim intRows As Integer
Dim intLoop As Integer
Dim intTopMargin As Integer
Dim intDetailHeight As Integer
intRows = 24
intDetailHeight = Me.Section(0).Height
intTopMargin = 360
For intLoop = 0 To intRows
Me.CurrentX = 20
Me.CurrentY = intLoop * intDetailHeight + intTopMargin
Me.Line (0, intLoop * intDetailHeight + intTopMargin)- _
Step(Me.Width, intDetailHeight), , B
Next
End Sub
 
Back
Top