I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the date is more than 10 months out.
The query runs fine, but I when I put the criteria of >10 I get 'Data Type mismatch' error. The code below is the original query. I have since put all the datediff bit in code, with all variables declared as date, string, integer etc and called the function in the query, again, "Data type mismatch"
I finally did the comparison in code and had a boolean function returning true or false. The query ran, but when I put in the criteria to return TRUE, I again got the 'Data Type Mismatch'
This is a critical bit of data validation and I am going mad here trying to work out what I am doing wrong
[code=sql]
SELECT Format([Village_ID],"0000") & Format([Womens_ID],"0000") AS WomenKey, DateDiff("m",Da teValue([ifyeslmpday] & "-" & [ifyeslmpmonth] & "-" & [ifyeslmpyear]),[whenentered]) AS LMPMonths
FROM tblWomen
WHERE (((tblWomen.Cur rentlyPregnant) =True) AND ((tblWomen.Ifye sLMPDay) Is Not Null) AND ((tblWomen.Ifye sLMPMonth) Is Not Null) AND ((tblWomen.Ifye sLMPYear) Is Not Null) AND ((DateDiff("m", DateValue([ifyeslmpday] & "-" & [ifyeslmpmonth] & "-" & [ifyeslmpyear]),[whenentered]))>10));
[/code]
The query runs fine, but I when I put the criteria of >10 I get 'Data Type mismatch' error. The code below is the original query. I have since put all the datediff bit in code, with all variables declared as date, string, integer etc and called the function in the query, again, "Data type mismatch"
I finally did the comparison in code and had a boolean function returning true or false. The query ran, but when I put in the criteria to return TRUE, I again got the 'Data Type Mismatch'
This is a critical bit of data validation and I am going mad here trying to work out what I am doing wrong
[code=sql]
SELECT Format([Village_ID],"0000") & Format([Womens_ID],"0000") AS WomenKey, DateDiff("m",Da teValue([ifyeslmpday] & "-" & [ifyeslmpmonth] & "-" & [ifyeslmpyear]),[whenentered]) AS LMPMonths
FROM tblWomen
WHERE (((tblWomen.Cur rentlyPregnant) =True) AND ((tblWomen.Ifye sLMPDay) Is Not Null) AND ((tblWomen.Ifye sLMPMonth) Is Not Null) AND ((tblWomen.Ifye sLMPYear) Is Not Null) AND ((DateDiff("m", DateValue([ifyeslmpday] & "-" & [ifyeslmpmonth] & "-" & [ifyeslmpyear]),[whenentered]))>10));
[/code]
Comment