below I have some code that calculates the age from their brirth date. I keep getting the Invalid use of Null Error when I insert a DOB and the age is already dispalyed. Does anyone know how to correct this?
Dim lngAge As Long
Dim dteBirthdate As Date
dteBirthdate = Me.DOB.Value
If Not IsNull(Me.DOB.Value) Then
'If Not IsNull(Me.Age.Value) Then
' Make sure passed-in value is a date.
If Not IsDate(dteBirthdate) Then
dteBirthdate = Date
End If
' Make sure birthdate is not in the future.
' If it is, use today's date.
If dteBirthdate > Date Then
dteBirthdate = Date
End If
' Calculate the difference in years between today and birthdate.
lngAge = DateDiff("yyyy", dteBirthdate, Date)
' If birthdate has not occurred this year, subtract 1 from age.
If DateSerial(Year(Date), Month(dteBirthdate), Day(dteBirthdate)) > Date Then
lngAge = lngAge - 1
End If
CalcAge = lngAge
Me.Age.Value = lngAge
Else
MsgBox "The age is already determined, delete the age and then add the date of birth."
'End If
End If
Dim lngAge As Long
Dim dteBirthdate As Date
dteBirthdate = Me.DOB.Value
If Not IsNull(Me.DOB.Value) Then
'If Not IsNull(Me.Age.Value) Then
' Make sure passed-in value is a date.
If Not IsDate(dteBirthdate) Then
dteBirthdate = Date
End If
' Make sure birthdate is not in the future.
' If it is, use today's date.
If dteBirthdate > Date Then
dteBirthdate = Date
End If
' Calculate the difference in years between today and birthdate.
lngAge = DateDiff("yyyy", dteBirthdate, Date)
' If birthdate has not occurred this year, subtract 1 from age.
If DateSerial(Year(Date), Month(dteBirthdate), Day(dteBirthdate)) > Date Then
lngAge = lngAge - 1
End If
CalcAge = lngAge
Me.Age.Value = lngAge
Else
MsgBox "The age is already determined, delete the age and then add the date of birth."
'End If
End If