why does On Format event is preformed twice

snoopy22

Registered User.
Local time
Today, 04:32
Joined
Oct 1, 2004
Messages
45
On my details section (in my report ) I've got a procedure On Format event
I debuged it and I've noticed It been called twice so the msgbox is show twice too
Why does it happend and how do i get rid of it?
here is the code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim Balance As Integer
If Forms!printre.rsNum = False Then
MsgBox "no records after this date"
Else
Balance = Me.Sum_Of_Credit - Me.Sum_Of_Debit + Forms!printre.MyoBalance
If Balance > 0 Then
Me.lblStatus.Caption = "your debt: "
Me.lblBalance.Caption = Str(Balance)
Else
Me.lblStatus.Caption = "your credit "
Me.lblBalance.Caption = Str(Balance)
End If
Me.lblOpeningB.Caption = Str(Forms!printre.MyoBalance)
End If

End Sub

thanks in advance, ofir
 
I don't know why, but it happens, but that's probably one of the reasons there's a FormatCount arguement of the section event.

If Forms!printre.rsNum = False and FormatCount=1 Then

Remember the detail sections on format event will run at least once per each record displayed, so if you need the message box to display only once, and there are more records qualifying, you'll probably need a report private variable to use after showing the message box the first time.

Just curious - why use a message box in a report - I've never done that (except in the on no data event)
 
Hi Roy

Thanks for the advice.

"Just curious - why use a message box in a report - I've never done that (except in the on no data event)"

I call the report from a form, so the box appears on the form
and you were right, It was simplier than i thought, I just needed to
move the msgbox from the report to the form. :)
 
Snoopy,

The format event is called until the results (after formatting) don't fit on
the current page. Then the page is printed without the last formatted
detail line (the one that wouldn't fit).

The next page starts out by "re-formatting" the detail line mentioned above.

Any processing that should be carried out only ONCE for a detail line
should be handled (as Rich says) using the OnPrint events.

Wayne
 
Just be a bit careful, if you're relying on the on print event of report sections firing only once. I'd check the PrintCount property to be sure. Here's a quote

"Note that the value of the PrintCount property is checked, before any accumulating begins, to determine if it's set to one. Access increments this property by one whenever the data for the current section is printed. Because there are times when the Print event for the Detail section for a particular record might be called more than once, checking the PrintCount value ensures that you don't add the same value twice to a page total.",

from this article
http://office.microsoft.com/en-us/assistance/HA011224441033.aspx
 
Roy,

Fortunately, I don't have any current apps that use the Format or Print
events. However, I did quite a bit of research in A97 concerning the
order that triggers fire in reports.

I do know that they changed in A2000, but I haven't ever seen the
OnPrint event fire multiple times for the same detail line. The link doesn't
provide an example. Just for interest, can anyone describe the conditions
under which this could happen?

Wayne
 
I haven't encountered it either, probably because I don't use the print event much, but perhaps also because I have a tendency of including a test on those count properties when using those events, without reflecting much about whether or not it fires more than once.

But, since I found indications that it may trigger more than once, both in ADH 2000 and the helpfiles (on the PrintCount property, where there's also description of one situation that may cause it), and the referenced article, I thought I'd pop in a warning - better safe than sorry, eh?

I'd be interested in knowing if anyone has seen the behaviour, too.
 

Users who are viewing this thread

Back
Top Bottom