C
CAM
I am using Access 2003.
The database records have DOB and Age as given by the client. I am looking
for errors in the data and want to list all records where the DOB and Age
don’t agree. I have written a VBA function to calculate the age. I want to
filter for the records where the difference between the calculated age and
given age is not 0. The filter
results in a ‘Data type mismatch in criteria expression’.
Notes:
tblClientList.RecNum is Number
tblClientList.ApptDate is Date/Time
tblClientList.DOB is Date/Time
tblClientList.Age is Number
Function funcGetAge() is defined as follows in a VBA Module:
Public Function funcGetAge(dtmBD As Date, Optional dtmDate As Date = 0) As
Integer
Dim intAge As Integer
If dtmDate = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Date
End If
intAge = DateDiff("yyyy", dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
funcGetAge = intAge
End Function
The following SQL results in a “Data type mismatch in criteria expressionâ€
error when previewed.
SELECT tblClientList.RecNum,
tblClientList.ApptDate,
tblClientList.DOB,
tblClientList.Age,
funcGetAge(tblClientList!DOB,tblClientList!ApptDate) AS CalcAge,
funcGetAge(tblClientList!DOB,tblClientList!ApptDate)-tblClientList!Age AS
CalcDiff
FROM tblClientList
WHERE ((
(tblClientList.DOB) Is Not Null)
AND ((tblClientList.Age) Is Not Null)
AND
((funcGetAge(tblClientList!DOB,tblClientList!ApptDate)-tblClientList!Age)<>0
));
I haven’t been able to figure out where the mismatch is occurring.
The database records have DOB and Age as given by the client. I am looking
for errors in the data and want to list all records where the DOB and Age
don’t agree. I have written a VBA function to calculate the age. I want to
filter for the records where the difference between the calculated age and
given age is not 0. The filter
results in a ‘Data type mismatch in criteria expression’.
Notes:
tblClientList.RecNum is Number
tblClientList.ApptDate is Date/Time
tblClientList.DOB is Date/Time
tblClientList.Age is Number
Function funcGetAge() is defined as follows in a VBA Module:
Public Function funcGetAge(dtmBD As Date, Optional dtmDate As Date = 0) As
Integer
Dim intAge As Integer
If dtmDate = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Date
End If
intAge = DateDiff("yyyy", dtmBD, dtmDate)
If dtmDate < DateSerial(Year(dtmDate), Month(dtmBD), Day(dtmBD)) Then
intAge = intAge - 1
End If
funcGetAge = intAge
End Function
The following SQL results in a “Data type mismatch in criteria expressionâ€
error when previewed.
SELECT tblClientList.RecNum,
tblClientList.ApptDate,
tblClientList.DOB,
tblClientList.Age,
funcGetAge(tblClientList!DOB,tblClientList!ApptDate) AS CalcAge,
funcGetAge(tblClientList!DOB,tblClientList!ApptDate)-tblClientList!Age AS
CalcDiff
FROM tblClientList
WHERE ((
(tblClientList.DOB) Is Not Null)
AND ((tblClientList.Age) Is Not Null)
AND
((funcGetAge(tblClientList!DOB,tblClientList!ApptDate)-tblClientList!Age)<>0
));
I haven’t been able to figure out where the mismatch is occurring.