Datatype mismatch in criteria expression regarding a CDate function field.

Maybe have another look at my post #3. If the date is stored as a string, it can easily be an invalid date without being Null. Consider "31-Feb-2014#, which will cause CDate() to choke.

But check out the query in my post . . .

I did that and it gave the result of 1, however this query uses unconverted dates. When I enter the query using CDate, I get the data mismatch error.
 
Lol, ok, so one of the dates in your data is not valid. There's your error. CDate() must receive a valid date string to do a conversion.

Makes sense?
 
Lol, ok, so one of the dates in your data is not valid. There's your error. CDate() must receive a valid date string to do a conversion.

Makes sense?

Yeah, but just to make sure, that query gave me does work for dates are are in a text field right?
 
Yeah, but just to make sure, that query gave me does work for dates are are in a text field right?
Sorry, can't quite make sense of that.
 
It has previously been explained in this thread that if you supply an invalid string to CDate(), CDate() will fail. Consider . . .
Code:
Debug.Print CDate("Not a date")
Similarly, you have been shown a query that will count invalid dates in your source data, and apparently when you run that query, the result is 1. That means there is one (1) invalid date in your source data. I think that to get the result you are looking for, you need to remove the invalid date from your source data. One way you can do that is with another query, maybe something like . . .
Code:
SELECT * FROM SourceQuery WHERE IsDate(DateFieldToTest)
. . . so that query will only return records where the field DateFieldToTest is a valid date.
Once you have filtered out invalid dates from your source data, then you can run CDate() successfully.
Hope that helps,
 

Users who are viewing this thread

Back
Top Bottom