im using Access as the database and im having a problem with the query below. I know the problem is with the email_date field but I dont know how to fix it. The problem is a text field which im trying to make use it as a datefield by using CDATE and compare it to a actual datefield which is causing the problem. Im getting the data mismatch error. In the email_date field if there is nothing, the field consists of ‘–‘, else it has 9/21/2011. Any help would be very much appreciated.
SELECT A.ICAO, A.IATA, A.AIRPORT_NAME, A.CITY, A.COUNTRY,
A.REVISED_DATE, A.COMPANY, A.EMAIL_DATE
FROM AIRPORT_CHECKLIST A
WHERE A.COMPANY = 'company'
AND FLAG_DELETE = 'No'
AND EMAIL_DATE <> '--'
AND CDATE(REVISED_DATE) > CDATE(EMAIL_DATE)
You can add a nested IIf() expression in the WHERE clause: return False if EMAIL_DATE is “–“; otherwise return True or False depending up the CDate() comparison of the two fields. A row will only be included in the result set if that expression returns True.
Also if both “date” fields were text type, you could store the date values in “yyyy-mm-dd” format and simply compare the text values with no data type mismatch problems.
Edit: If FLAG_DELETE is Yes/No type (instead of text type), use a literal False in the comparison.