Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / December 2007

Tip: Looking for answers? Try searching our database.

Calculating someones age

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Landor - 13 Dec 2007 13:58 GMT
I am using Access 2007 and I want to calculate a persons age in years, months
and days on a form. I have a DOB field. Is there an easy formula I can use to
do this? The easier the better as I am new to Access and not that good with
VB, modules etc.

Thanks in anticipation

Landor
Tony Williams - 13 Dec 2007 14:10 GMT
I have a piece of code I use to calculate age and then warn if under 18.You
may be able to adapt this, it foes in the OnEnter event of the control
txtage
Private Sub txtAge_Enter()
Dim dateBirthday As Date
 dateBirthday = Date_of_Birth.Value
 Dim varAge As Variant
 varAge = -DateDiff("yyyy", Date, dateBirthday)
 Dim varDiff As Variant
 varDiff = DateDiff("d", DateAdd("yyyy", varAge, dateBirthday), Date)
 If varDiff < 0 Then
   varAge = varAge - 1
 End If
 txtAge.Value = varAge
If txtAge.Value < 18 Then
       MsgBox "This person is under 18!", vbOKOnly, "Warning"
   End If
End Sub

HTH
Tony
>I am using Access 2007 and I want to calculate a persons age in years,
>months
[quoted text clipped - 7 lines]
>
> Landor
BruceM - 13 Dec 2007 15:54 GMT
There is some age-calculation code here, if you want to explore other
options:
http://www.mvps.org/access/datetime/date0001.htm

>I am using Access 2007 and I want to calculate a persons age in years,
>months
[quoted text clipped - 7 lines]
>
> Landor
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.