Best place for datediff? (1 Viewer)

StephenB

Registered User.
Local time
Today, 10:07
Joined
Apr 18, 2002
Messages
101
I have a form with two fields: [DOB] (for date of birth) and [Age] (which is unbound). I'm using the following to calculate age:

[Age] = DateDiff("yyyy", [DOB], Date) + (Date < DateSerial(Year(Date), Month([DOB]), Day([DOB])))

My question is this: What's the best place to place this? If I place it on [DOB] (update or exit), [Age] does not change when I scroll through records. So I placed it on the form's "on timer" event with a timer inerval of 1000. This is better but I still get that split second delay in recalculating. This is OK if you visually start at the top of the form and work your way down, but if you're scrolling through records looking at ages, you can see it change. Any other place I can place this so that [Age] is calculated and displayed along with the rest of the data on the form as I scroll throught the records? Is there an event such as "on load record" or something?

TIA
 

llkhoutx

Registered User.
Local time
Today, 09:07
Joined
Feb 26, 2001
Messages
4,018
Place in vba code on the "OnCurrent" event.
 

Elana

Registered User.
Local time
Today, 07:07
Joined
Apr 19, 2000
Messages
232
Or, place the code in the control source of the unbound field AGE - take out the "[AGE] = " and just start with "=DateDiff....".




[This message has been edited by Elana (edited 05-17-2002).]
 

StephenB

Registered User.
Local time
Today, 10:07
Joined
Apr 18, 2002
Messages
101
The On_Current worked, but placing it on the control source of the unbound age field gave me the "#Name?" error.

Thank you both for taking the time to respond.

Stephen
 

Elana

Registered User.
Local time
Today, 07:07
Joined
Apr 19, 2000
Messages
232
Assuming you have a field called "DOB" on your form, place this code in control source of the field called "AGE":

=DateDiff("yyyy",[DOB],Date())

This will give you the age based on the DOB.

EB
 

Users who are viewing this thread

Top Bottom