Orange Coast Database Forums

Post Info TOPIC: Access Queries.


Directeur

Status: Offline
Posts: 42
Date:
Access Queries.


This is the thread for discussion of Access Queries. Feel free to pose your query questions, tips and tricks here.



__________________
Anonymous

Date:

I have a date of birth field in my database. How do I calculate the age in a query?



__________________


Directeur

Status: Offline
Posts: 42
Date:

Add the following function to a module in your database.

Public Function calcAge(dob As Date) As Integer
Dim age As Integer
age = DateDiff("yyyy", dob, Now())
calcAge = IIf(Format(dob, "mmdd") >= Format(Now(), "mmdd"), age - 1, age)
End Function


You can call this function in a query just like a built in function. It takes the number of years between the data of birth and the current date. Then it adjusts it down 1 year if the birthday has not yet occurred for the current year.

---Dan 

__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.

Tweet this page Post to Digg Post to Del.icio.us
Members Login
Username 
 
Password 
    Remember Me  


Create your own FREE Forum
Report Abuse
Powered by ActiveBoard