Starting a counter in a report

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

Guest

This is similar to discussions already posted in the forum, but I don't
believe any have addressed this specific point (my apologies, however, if it
is being rehashed):

Each record in my report may or may not have text in a field called
"Location." If there is text in this field, I need the record to be counted.
My records appear in random order. I have a label titled "lblFigure" which
I have set to visible when text is visible in the "Location" field, and is
supposed to iterate in each instance of this.

In this way, the first time that there is text in the "Location" field,
there will be a statement saying "Please refer to Figure 1." The next time,
it will say "Please refer to figure 2," and so on.

Initially, it appears that this problem can be solved simply by programming
a counter in one section of the report code (though I'm unsure which one) and
having the counter increment each time this condition is met. My attempts to
do this, however, have been unsuccessful. I tried entering the following
code in the detail section of my report (where lblFigure appears):

If Me.Location <> "" Then
Me.lblImage1.Visible = True
Me.lblImage2.Visible = True
Me.lblFigure.Visible = True
counter = counter + 1
Me.lblFigure.Caption = counter
Else
Me.lblImage1.Visible = False
Me.lblImage2.Visible = False
Me.lblFigure.Visible = False
End If

But counter is erratic and does not increment in a discernible manner.

This seems tricky to me; any light shed on this matter will
be greatly appreciated. I'll go into even further detail if needed.

Joe
 
Each record in my report may or may not have text in a field called
"Location." If there is text in this field, I need the record to be
counted. My records appear in random order. I have a label titled
"lblFigure" which I have set to visible when text is visible in the
"Location" field, and is supposed to iterate in each instance of this.

You should be able to use the OnFormat event of the Location control to
do this. It would really help if the records were sorted in some way, but
it is possible to get round this anyway with a Static counter


private sub txtLocation_Format()

static dim dwCounter as long

if not isnull(txtLocation) then
dwCounter = dwCounter + 1
lblFigure.Caption = format(dwCounter,"""See figure ""0")
lblFigure.Visible = True

else ' hide it
lblFigure.Visible = False

end if

end sub

You'll prolly get more help in the m.p.a.reports group.

B Wishes


Tim F
 
Joe said:
This is similar to discussions already posted in the forum, but I don't
believe any have addressed this specific point (my apologies, however, if it
is being rehashed):

Each record in my report may or may not have text in a field called
"Location." If there is text in this field, I need the record to be counted.
My records appear in random order. I have a label titled "lblFigure" which
I have set to visible when text is visible in the "Location" field, and is
supposed to iterate in each instance of this.

In this way, the first time that there is text in the "Location" field,
there will be a statement saying "Please refer to Figure 1." The next time,
it will say "Please refer to figure 2," and so on.

Initially, it appears that this problem can be solved simply by programming
a counter in one section of the report code (though I'm unsure which one) and
having the counter increment each time this condition is met. My attempts to
do this, however, have been unsuccessful. I tried entering the following
code in the detail section of my report (where lblFigure appears):

If Me.Location <> "" Then
Me.lblImage1.Visible = True
Me.lblImage2.Visible = True
Me.lblFigure.Visible = True
counter = counter + 1
Me.lblFigure.Caption = counter
Else
Me.lblImage1.Visible = False
Me.lblImage2.Visible = False
Me.lblFigure.Visible = False
End If

But counter is erratic and does not increment in a discernible manner.


That's to be expected. Because events are processed in any
order required to format your report, you can not reliably
accumulate a value across multiple records.

Create a text box named txtImageCnt in the detail section.
Set its control source expression to:
=IIf(Nz(Location, "") <> "", 1, 0)
and set its RunningSum property to Over Group.

Then your code would be more like this:

If Me.Location <> "" Then
Me.lblImage1.Visible = True
Me.lblImage2.Visible = True
Me.lblFigure.Visible = True
Me.lblFigure.Caption = txtImageCnt
Else
Me.lblImage1.Visible = False
Me.lblImage2.Visible = False
Me.lblFigure.Visible = False
End If
 
Hey Marshall --

That worked perfectly, but I foolishly neglected to tell you that there is a
group header called "Case" in the report. "Case" is visible only when there
is text in the "Case" field in the table. The only reason I cannot keep it
in the detail section is that when two or three records come up with the same
"Case" text, I don't want it to repeat itself over and over in the report. I
just want it to appear once at the beginning of the group.

Now the numbers reset each time a new Case group begins. When I take away
the case, the Case text appears before every record. Not sure if you have an
answer for this one, but I would really appreciate the help.

Thanks

Joe
 
Hey Marshall, that was pretty silly of me. All I had to do was set the
Running Sum to "over all" and the problem is solved. Sometimes you can
really out-think yourself when it comes to these things.

Thank you just the same. You've really been a tremendous help.
 
Back
Top