CasVan
Technical User
- Dec 17, 2008
- 5
All -
This ia a variation of the “Isolation of problem with calculating age” post by MADDPM of 13-Nov-2008
I would like to account for individuals without DOBs with either a null value and/or a dummy date of 00/00/0000. Right now, if the qryDates runs, the fields with the missing dates return with #Error and the "Data Type mismatch in criteria expression" error.
If I add is not null to the DOB field in the qryDates, the query runs without errors.
I have listed my query/module below; any helpful suggestions are gladly welcomed.
Query: QryDates
Issue: Age_YMDs: basDOB2AgeExt([DOB],NZ([DOD],-1))
SQLQuery:
Enough rambling... Thoughts anyone?
~Cas
This ia a variation of the “Isolation of problem with calculating age” post by MADDPM of 13-Nov-2008
I would like to account for individuals without DOBs with either a null value and/or a dummy date of 00/00/0000. Right now, if the qryDates runs, the fields with the missing dates return with #Error and the "Data Type mismatch in criteria expression" error.
If I add is not null to the DOB field in the qryDates, the query runs without errors.
I have listed my query/module below; any helpful suggestions are gladly welcomed.
Query: QryDates
Issue: Age_YMDs: basDOB2AgeExt([DOB],NZ([DOD],-1))
SQLQuery:
Code:
SELECT qryFAMLists.FullnameFIRST, qryFAMLists.FullnameLAST, qryFAMLists.DOB, qryFAMLists.DOD, basAgeExt([DOB],NZ([DOD],-1)) AS Age, Format([DOB],'mmm') & '-' & Format([DOB],'dd') AS MnthDy, Year([DOB]) AS BYear, Year([DOD]) AS DYear, Month([DOB]) AS Mnth, Day([DOB]) AS Dy, Format([DOB],'mmmm') AS Mnth_, Format([DOB],'ddd') AS DyBorn_, AgeGroup([DOB],IIf(IsNull([DOD]),Date(),[DOD])) AS AgeGrp, basDOB2AgeExt([DOB],NZ([DOD],-1)) AS Age_YMDs, DateSerial(Year(Date()),Month([DOB]),Day([DOB])) AS BDay, qryFAMLists.Gender
FROM qryFAMLists;
Code:
Public Function basDOB2AgeExt2(DOB As Date, Optional DOD As Date = -1) As String
'Michael Red 5/23/02
'Customized by MADDPM 11/13/08
'DOB is just the date of Birth
'DOD is an optional date to check - as in examples 1 & 2
'Otherwise, the DOB is checked against the Current Date
'? basDOB2AgeExt(#8/21/42#)
'59 Years 9 Months and 2 Days.
'? basDOB2AgeExt(#8/21/1942#, #8/20/2022#)
'79 Years 11 Months and 30 Days.
'? basDOB2AgeExt(#8/21/1942#, #8/21/2022#)
'80 Years 0 Months and 0 Days.
Dim tmpAge As Integer 'Simple DateDiff w/o Birthday correction
Dim tmpDt As Date 'Date to use in intermediate Calcs
Dim DtCorr As Boolean 'BirthDay Before or After date in question
Dim YrsAge As Integer
Dim MnthsAge As Integer 'Additional Mnths
Dim DaysAge As Integer 'Additional Days
If IsNull(DOB) Then
basDOB2AgeExt = Null
Else
If (DOD = -1) Then 'Check for (Optional Date to Check against)
DOD = Date 'If Not Supplied, Assume Today
End If
tmpAge = DateDiff("YYYY", DOB, DOD) 'Just the Years considering Jan 1, Mam
DtCorr = DateSerial(Year(DOD), Month(DOB), Day(DOB)) > DOD
YrsAge = tmpAge + DtCorr 'Just Years and Correction
tmpDt = DateAdd("yyyy", YrsAge, DOB)
MnthsAge = DateDiff("m", tmpDt, DOD)
DtCorr = DateAdd("m", MnthsAge, tmpDt) > DOD
MnthsAge = MnthsAge + DtCorr
tmpDt = DateAdd("m", MnthsAge, tmpDt)
DaysAge = DateDiff("d", tmpDt, DOD)
basDOB2AgeExt = YrsAge & " Years " & MnthsAge & " Months and " & DaysAge & " Days."
End If
End Function
'Called by:
'=basDOB2AgeExt([DOB]) 'no DOD value passed, use current date.
'=basDOB2AgeExt([DOB],[DOD]) 'calculate using DOB and DOD values.
'*basDOB2AgeExt([DOB],NZ([DOD],-1)) If no DOD use current date
Enough rambling... Thoughts anyone?
~Cas