calculate a persons age code not working. (1 Viewer)

john527

Registered User.
Local time
Today, 02:27
Joined
Jul 9, 2006
Messages
36
Hi all I have another code Problem, Can someone help me with this.
I have two fields
One called cust_birthday ( date field )
And one called cust_age ( text field )
The code below I put in a module name age function.

The Problem, is I get no return from this code.

What is wrong with this code ????

Option Compare Database

Public Function Age(cust_birthday As Date, Optional cust_age As Variant) As Integer
Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
If IsMissing(SpecDate) Then
dteBase = Date
Else
dteBase = SpecDate
End If
cust_age = DateDiff("yyyy", dteDOB, dteBase)
cust_age = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
Age = cust_birthday + (dteBase < cust_age)
End Function

John527
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:27
Joined
Sep 12, 2006
Messages
15,652
what is spec_date? it needs to be one of the parameters to the function. Try compiling - it will probably pick thus up as an error.

put a break point at the top of the code, and step through it line by line, to see what's happening
 

john527

Registered User.
Local time
Today, 02:27
Joined
Jul 9, 2006
Messages
36
can dot get it working.

Hi, gemma-the-husy can you help me.
I did the compiling, no err came up.
I also try to do step through it line by line.
Still can not get a returen,
So I did an add watch with intEstAge = DateDiff("yyyy", dteDOB, dteBase)
The value ( out of context ) ??? what can I do about this. ??
intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
The value ( out of context ) ??? what can I do about this. ??
The form name is customer form.
The table name is customer table

Can someone redo this code so I can understaion it.
What i am doing wrong.
The field is cust_birthday ( Date )
The other is the cust_age ( text )

Can someone help me with this.

Option Compare Database

Public Function Age(dteDOB As Date, Optional specDate As Variant) As Integer
Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
If IsMissing(cust_birthday) Then
dteBase = cust_age
Else
dteBase = cust_age
End If
intEstAge = DateDiff("yyyy", dteDOB, dteBase)
intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
Age = intEstAge + (dteBase < cust_age)
End Function

Thank You for any help I can get..
john527
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:27
Joined
Sep 12, 2006
Messages
15,652
its hard to see what you are trying to do.

in your last example you have ismissing(cust_burthday), but the ismissing should be testing for the optional parameter spec_date. Then whether ismissing returns true or false, you are still setting dtebase to the same value.

What are the dates you are passing in to the parameter supposed to represeny

i presume dtedob is the persons date of burth. Is this ALWAYS a value? or can it be 0 or blank ie unknown? What does specdate contain?

What are you trying to return - the age at a particular date, or the age at today's date?
 

deBassMan

Registered User.
Local time
Today, 10:27
Joined
Jul 25, 2006
Messages
56
Try this

Code:
Function CalcAge(DOB)
CalcAge=Int((Date-DOB)/365.25)
End Function

It's not particularly accurate - but it might get you started ...

good luck

deBassMan
 

raskew

AWF VIP
Local time
Today, 04:27
Joined
Jun 2, 2001
Messages
2,734
Hi -

Give this a try:
Code:
Function fAge2(DOB As Date, dteEnd As Date) As Integer
'Inputs:  1) ? fAge2(#4/13/53#, #10/23/06#)
'         2) ? fAge2(#11/1/53#, #10/23/06#)
'Outputs: 1) 53
'         2) 52

   fAge2 = DateDiff("yyyy", DOB, dteEnd) + (DateSerial(Year(dteEnd), Month(DOB), Day(DOB)) > dteEnd)

End Function

HTH - Bob
 

Users who are viewing this thread

Top Bottom