Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression Builder help needed

Status
Not open for further replies.

Dbyte

Technical User
Mar 6, 2002
87
I want to build an expression that calculates the age for someone using their date of birth. This will include people born before 1930. The catch is that I want it calculated (& entered into the table automatically) when the person entering the data exits out of the Date of Birth field on my form. I believe this can be done using the On Exit property, but can't figure out how to write the actual expression. I have the following 2 old queries that I would like to combine in this expression:

1. IIf((Int((Now()-[Date of Birth])/365.2425)/100)<0,Int((Now()-([Date of Birth]-36524.25))/365.2425),Int((Now()-[Date of Birth])/365.2425)) AS Age INTO [CITable]

2. UPDATE [Report Table] SET [Report Table].Age = 100-&quot;Abs[Age]&quot; WHERE ((([Report Table].Age)<0))

How can I change this into 1 all-inclusive expression, so that the calculation is done right after the date of birth is entered & people born before 1930 are calculated correctly? Or if it can't be done then, when/how should I go about accomplishing this? Thanks in advance for your help.

-D
 
dys,
You aren't supposed to store calculated fields in a db...
Instead, on your form Create a textbox and put
=DateDiff(&quot;d&quot;,[birthday],Date())/365.25
as the control source.
Will give years.decimal
If your form is based on a query you can, in a blank field of the QBE grid
DateDiff(&quot;d&quot;,[birthday],Date())/365.25
it will show up as
exp1:datediff etc.
change the exp1 to whatever you want &quot;years old&quot; or something similar.
jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top