Make calculated text boxes update only once.

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

Guest

I have a form that uses a function to calculate a date field based on the
data that I am viewing. Each time I look at a new record, the text box
blanks and recalculates the same data over & over again. Can I get the box
to calculate only once and show the data without blanking as I scroll through
records?
 
Dave T said:
I have a form that uses a function to calculate a date field based on
the data that I am viewing. Each time I look at a new record, the
text box blanks and recalculates the same data over & over again.
Can I get the box to calculate only once and show the data without
blanking as I scroll through records?

Are you saying the value to be displayed in this text box doesn't change
no matter what record you are looking at? If that's true, then I
wouldn't think you'd need to pass any fields of the form in its
controlsource expression, and if you don't, then I don't *think* it will
recalculate every time you come to a new record.

If this is a value that does depend on a record's data, but only needs
to be calculated for the very first record, then I think you could use a
completely unbound control but calculate and assign a value to it in the
form's Load event.

If you really do need to recalculate the value for each record, then
maybe the answer to your display problem is to make it an unbound
control, but calculate and assign a value to it in the form's Current
event.
 
Dirk,

The date fields I calculate show the dates of the week that the records I am
viewing came from. They never change no matter how many records I view.
They are basically "dymanic" labels for the records I am viewing. Could you
expand on the form "load event" procedure?

Dave T.
 
Dave T said:
Dirk,

The date fields I calculate show the dates of the week that the
records I am viewing came from. They never change no matter how many
records I view. They are basically "dymanic" labels for the records I
am viewing. Could you expand on the form "load event" procedure?

There are two ways to approach this. One would be to examine (in the
form's Open or Load event) whatever it is that tells the form what set
of records to display -- the form's Filter property, or an OpenArgs
value, or maybe even the WHERE clause of the form's recordsource -- and
then set the value of your unbound text box accordingly.

The other, which I was referring to, would be to use data from the
form's first record to calculate the value. I'm not sure whether you
can refer to values of the form's controls until the Current event has
fired, but you can refer to the first record in the form's
RecordsetClone in the form's Load event. So you could have code along
these lines:

'----- start of example code -----
Private Sub Form_Load()

With Me.RecordsetClone
If .RecordCount > 0 Then
Me!YourDateTextbox = YourFunction(!SomeField)
End If
End With

End Sub
'----- end of example code -----
 
Back
Top