Modifying Age Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Deborah V. Gardner

    Modifying Age Function

    I have the following function.

    Function Age(varBirthdat e As Variant) As Integer

    'Function from Microsoft Article Q210522

    Dim varAge As Variant

    If IsNull(varBirth date) Then Age = 0: Exit Function

    varAge = DateDiff("yyyy" , varBirthdate, Now)
    If Date < DateSerial(Year (Now), Month(varBirthd ate),
    Day(varBirthdat e)) 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.Inta keDate)

    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

  • Phobos

    #2
    Re: Modifying Age Function

    > Function Age(varBirthdat e As Variant, MyDate as Date) As Integer[color=blue]
    >
    > 'Function from Microsoft Article Q210522
    >
    > Dim varAge As Variant
    >
    > If IsNull(varBirth date) Then Age = 0: Exit Function
    >
    > varAge = DateDiff("yyyy" , varBirthdate, MyDate)
    > If Date < DateSerial(Year (Now), Month(varBirthd ate),
    > Day(varBirthdat e)) 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.E 3AB6953@twcny.r r.com...[color=blue]
    > I have the following function.
    >
    > Function Age(varBirthdat e As Variant) As Integer
    >
    > 'Function from Microsoft Article Q210522
    >
    > Dim varAge As Variant
    >
    > If IsNull(varBirth date) Then Age = 0: Exit Function
    >
    > varAge = DateDiff("yyyy" , varBirthdate, Now)
    > If Date < DateSerial(Year (Now), Month(varBirthd ate),
    > Day(varBirthdat e)) 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.Inta keDate)
    >
    > 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]


    Comment

    • Deborah V. Gardner

      #3
      Re: Modifying Age Function

      Phobos

      Thank you. It worked!

      Deborah

      Phobos wrote:
      [color=blue][color=green]
      > > Function Age(varBirthdat e As Variant, MyDate as Date) As Integer
      > >
      > > 'Function from Microsoft Article Q210522
      > >
      > > Dim varAge As Variant
      > >
      > > If IsNull(varBirth date) Then Age = 0: Exit Function
      > >
      > > varAge = DateDiff("yyyy" , varBirthdate, MyDate)
      > > If Date < DateSerial(Year (Now), Month(varBirthd ate),
      > > Day(varBirthdat e)) 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.E 3AB6953@twcny.r r.com...[color=green]
      > > I have the following function.
      > >
      > > Function Age(varBirthdat e As Variant) As Integer
      > >
      > > 'Function from Microsoft Article Q210522
      > >
      > > Dim varAge As Variant
      > >
      > > If IsNull(varBirth date) Then Age = 0: Exit Function
      > >
      > > varAge = DateDiff("yyyy" , varBirthdate, Now)
      > > If Date < DateSerial(Year (Now), Month(varBirthd ate),
      > > Day(varBirthdat e)) 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.Inta keDate)
      > >
      > > 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]

      Comment

      Working...