Connecting Tech Pros Worldwide Help | Site Map

Modifying Age Function

  #1  
Old November 12th, 2005, 04:00 PM
Deborah V. Gardner
Guest
 
Posts: n/a
I have the following function.

Function Age(varBirthdate As Variant) As Integer

'Function from Microsoft Article Q210522

Dim varAge As Variant

If IsNull(varBirthdate) Then Age = 0: Exit Function

varAge = DateDiff("yyyy", varBirthdate, Now)
If Date < DateSerial(Year(Now), Month(varBirthdate),
Day(varBirthdate)) Then
varAge = varAge - 1
End If

Age = CInt(varAge)

End Function

I would like to modify it to calculate the Age of a person from the date
he entered the program so I rewrote one of the lines to this

varAge = DateDiff("yyyy", varBirthdate, tblClients.IntakeDate)

I receive a Compile Error: Fucntion call on left-hand side of assignment
must return Variant or Object.

I would like to know what I am doing wrong and how to correct it.

Thank you,
Deborah

  #2  
Old November 12th, 2005, 04:00 PM
Phobos
Guest
 
Posts: n/a

re: Modifying Age Function


> Function Age(varBirthdate As Variant, MyDate as Date) As Integer[color=blue]
>
> 'Function from Microsoft Article Q210522
>
> Dim varAge As Variant
>
> If IsNull(varBirthdate) Then Age = 0: Exit Function
>
> varAge = DateDiff("yyyy", varBirthdate, MyDate)
> If Date < DateSerial(Year(Now), Month(varBirthdate),
> Day(varBirthdate)) Then
> varAge = varAge - 1
> End If
>
> Age = CInt(varAge)
>
> End Function[/color]


Then you have to pass the value to the function, in the Design Grid:

QueryField: Age([BirthDate], [MyDate])

P



"Deborah V. Gardner" <dgardner@twcny.rr.com> wrote in message
news:3FA42F5B.E3AB6953@twcny.rr.com...[color=blue]
> I have the following function.
>
> Function Age(varBirthdate As Variant) As Integer
>
> 'Function from Microsoft Article Q210522
>
> Dim varAge As Variant
>
> If IsNull(varBirthdate) Then Age = 0: Exit Function
>
> varAge = DateDiff("yyyy", varBirthdate, Now)
> If Date < DateSerial(Year(Now), Month(varBirthdate),
> Day(varBirthdate)) Then
> varAge = varAge - 1
> End If
>
> Age = CInt(varAge)
>
> End Function
>
> I would like to modify it to calculate the Age of a person from the date
> he entered the program so I rewrote one of the lines to this
>
> varAge = DateDiff("yyyy", varBirthdate, tblClients.IntakeDate)
>
> I receive a Compile Error: Fucntion call on left-hand side of assignment
> must return Variant or Object.
>
> I would like to know what I am doing wrong and how to correct it.
>
> Thank you,
> Deborah
>[/color]


  #3  
Old November 12th, 2005, 04:00 PM
Deborah V. Gardner
Guest
 
Posts: n/a

re: Modifying Age Function


Phobos

Thank you. It worked!

Deborah

Phobos wrote:
[color=blue][color=green]
> > Function Age(varBirthdate As Variant, MyDate as Date) As Integer
> >
> > 'Function from Microsoft Article Q210522
> >
> > Dim varAge As Variant
> >
> > If IsNull(varBirthdate) Then Age = 0: Exit Function
> >
> > varAge = DateDiff("yyyy", varBirthdate, MyDate)
> > If Date < DateSerial(Year(Now), Month(varBirthdate),
> > Day(varBirthdate)) Then
> > varAge = varAge - 1
> > End If
> >
> > Age = CInt(varAge)
> >
> > End Function[/color]
>
> Then you have to pass the value to the function, in the Design Grid:
>
> QueryField: Age([BirthDate], [MyDate])
>
> P
>
> "Deborah V. Gardner" <dgardner@twcny.rr.com> wrote in message
> news:3FA42F5B.E3AB6953@twcny.rr.com...[color=green]
> > I have the following function.
> >
> > Function Age(varBirthdate As Variant) As Integer
> >
> > 'Function from Microsoft Article Q210522
> >
> > Dim varAge As Variant
> >
> > If IsNull(varBirthdate) Then Age = 0: Exit Function
> >
> > varAge = DateDiff("yyyy", varBirthdate, Now)
> > If Date < DateSerial(Year(Now), Month(varBirthdate),
> > Day(varBirthdate)) Then
> > varAge = varAge - 1
> > End If
> >
> > Age = CInt(varAge)
> >
> > End Function
> >
> > I would like to modify it to calculate the Age of a person from the date
> > he entered the program so I rewrote one of the lines to this
> >
> > varAge = DateDiff("yyyy", varBirthdate, tblClients.IntakeDate)
> >
> > I receive a Compile Error: Fucntion call on left-hand side of assignment
> > must return Variant or Object.
> >
> > I would like to know what I am doing wrong and how to correct it.
> >
> > Thank you,
> > Deborah
> >[/color][/color]

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
(ADP) form problem: "This Recordset is not updatable" radio1 answers 17 March 9th, 2007 06:32 PM
passing pointer to struct by reference Mike answers 12 March 21st, 2006 11:15 PM
[EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF Ilias Lazaridis answers 104 January 13th, 2006 07:35 PM
How would Mr. Stroustrup implement his solution to 12.7[2] Oplec answers 26 July 19th, 2005 08:36 PM