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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Age from DOB 2

Status
Not open for further replies.

purpleski

IS-IT--Management
Aug 14, 2002
112
FR
Hi

Before anyone tells me off I know there are loads of posts about this but I can not get them to work; I am a complete newbie.


I have amongst others two fields DOB and Age. I have found

((Now()-[DOB])/365.25)

which seems the neatest bit of code, I do not need anything complicated but where do I put it.

Thanks.

 
You can use this directly in a query by putting something like this on the Field Line of a new column in your query.

Age:((Now()-[DOB])/365.25)

Then when you run the query it will calculate the value. The problem I see is that it will return a number with a decimal place. If you want just whole age, you can use

Age:Int((Now()-[DOB])/365.25))

Paul
 
sorry I was not clear the two fields are in simple form which is derived from the table Attendees. The dob field may be blank as I do not always know the DOB of the client but what I would like is when a valid DOB is entered in the DOB field and tab is pressed the Age field is immediatelty populated with the age of the person.

Hope that is clear?

Regards
 
Use the following :

Age:Int((Now()-[DOB])/365.25))

It works
 
Thanks but sorry

But where do you put the code?

I must apear really dumb but I am just learning.

Regards.
 
Depoending on the typical range of DOB, the simple dividion may give some 'distortion'.

There are numerous threads on the general topic, many of which include more precise soloutions, Use the 'Search' capability with key words (Age | DOD | ...]




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Well, if I was doing this, I would create a query from the table, Attendees, and then I would base my form on the query instead of the table. Using a query as the Record Source for your form allows you to calculate values that can be viewed on the form without adding Event Procedures to the form. If you use the query then you could change your expression to
Age:IIf(IsNull([DOB]),"",Int((Now()-[DOB])/365.25)))

Post back if you don't think that will work for you.

Paul
 
If you would like this to appear on your form rather than a query, create a text box and in the Control source put in =Int((Now()-[DOB])/365.25) This will then calcuate the age and display it on the form. If you need to refer to this elsewhere then you can use Me.txtDOB (assumes you change the name of the text box to txtDOB. you can name the textbox whatever you like so that it is easy for you to remember and refer to it.) if on the same form or code within that form or Forms!frmFORMNAME.txtDOB (frmFORMNAME would be the name of your form) if you need to refer to it from another form, code or report. You could also use this technique on your report if you want to have it as a calculated field on the report rather than part of the query.
 
sxschech

Thanks for that and thank you for helping, but I still get #Error but this is better than before when I was getting
?Name.

Any thoughts?

Regards
 
What is the format of the field you are using for DOB is it a date field or do you have any special formatting such as dd-mmm-yyyy or is it standard format mm/dd/yyyy? Any other information you could provide would be helpful.
 
sxschech

Sorted. I had not formatted the field in the associated table correctly. Working now.

Thank you so much for answering the question precisely it really makes so much easier for newbies like me.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top