Draw line after n records

  • Thread starter Thread starter Mario
  • Start date Start date
Mario said:
How to draw a line after 120 records in a report?


Use a text box named txtLineCount in the detail section.
Set it control source expression to =1 and RunningSum
property to Over All.

Add a Line control named MyLine at the bottom of the detail
section.

In the detail section's Format event procedure, use a line
of code to make the line visible or not as needed:

Me.MyLine.Visible = (Me.txtLineCount Mod 120 = 0)
 
Hi, Mario,

you can count records in Deatil_Print, for example. Then, if RecordCound mod
120 = 0, simply draw a line.

Dim lngRecCnt As Long

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
lngRecCnt = lngRecCnt + 1
If lngRecCnt Mod 120 = 0 Then
Me.Line (0, 0)-(14400, 0)
End If
End Sub

Be sure to use 14400, it's "an arbitrary number to increase the line to
the max of a section" (taken from Microsoft sample MDB). Don't forget to add
an error-handling-code. ;-)

HTH.

Vlado
 
Vladimír Cvajniga said:
you can count records in Deatil_Print, for example. Then, if RecordCound mod
120 = 0, simply draw a line.

Dim lngRecCnt As Long

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
lngRecCnt = lngRecCnt + 1
If lngRecCnt Mod 120 = 0 Then


Careful there Vladimír, you can not rely on event procedure
code to calculate a value over multiple records. There are
many reasons (CanGrow, KeepTogether, etc) why an event will
be executed multiple times and throw the count off by an
unknown amount. Note that Retreat and
FormatCount/PrintCount are inadequate in trying to keep it
straight.

Much better to use a RunningSum text box.
 
Hi, Marsh,

in fact, I didn't need to print line yet sunce I use to print grid, ie.
BorderStyle = 1. To me it seems that user can "read" the print-out more
easily.

But I wonder why FormatCount/PrintCount should give incorrect results. I'll
ask help (F1) to check it out.

IMHO, using TextBox according to your sample is much simpler to keep track
of what's going on.

Vlado
 
I think the FormatCount issue is that it's just too
complicated for it to be meaningful. Consider a report with
several layers of grouping. One hypothetical situation is
that a section gets formatted (FormatCount=1), but it
doesn't fit on the page so it has to be formatted again
(FormatCount=2) to get part of it on the next page. But one
of the high level groups has KeepTogether set to Whole
Group, so now some group headers/footers and a bunch of
details all have to be redone. This time through, the
detail that was split before get's formatted again
(FormatCount=1 & 2? or 3 & 4?), but this time a lower level
group's KeepTogether causes the whole cycle to go around
again. Toss in some code that makes a text box grow or
shrink differently on even and odd pages and I have no idea
where things stand.

As far as PrintCount is concerned, I think it's practically
worthless when you add the fact that a report's pages can be
previewed in any order and an arbitrary number of times.

The way to sanity is to just ignore the Retreat and Count
stuff and take a different route.
 
Back
Top