Calculating Age

armoredcars

New member
Local time
Today, 15:13
Joined
Jun 25, 2007
Messages
9
I'm trying to make a button that will calculate someone's age by their birthday using Visual Basic. Here is one of my many attempts:

Private Sub Command16_Click()
CCurrentAge = DateDiff("yyyy", CBirtday, Now)
End Sub

All I can ever get is 108 no matter what I put in CBirthday (box on my form.)
 
try date() instead of now()

The additional info, as an FYI, is that you use NOW if you want to have date AND time and DATE if you want only date.
 
Thanks for the tip, but I still get 108. :confused:

Sorry, I missed your messed up syntax as I got focused on the date vs. now situation.

I'm assuming that CCurrentAge is your text box and that CBirtday is actually CBirthday.

Private Sub Command16_Click()
Me.CCurrentAge = DateDiff("yyyy", Me.CBirthday, Date)
End Sub

But, this is not totally accurate as you know they are not that age until they hit that day on this year. I know someone on the site has created a formula for that so you may want to go search.
 
This the exact code?
Code:
Private Sub Command16_Click()
CCurrentAge = DateDiff("yyyy", [COLOR="Red"]CBirtday[/COLOR], Now)
End Sub

thats a spelling mistake.. CBirthday
Edit::
apparently my refresh button is slow.....
 
Code:
Public Function Age(DOB As Date) As Integer

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

End Function
 

Users who are viewing this thread

Back
Top Bottom