Data type mismatch in criteria expression (1 Viewer)

BJS

Registered User.
Local time
Today, 15:39
Joined
Aug 29, 2002
Messages
109
I am getting the error "Data type mismatch in criteria expression" when I put sorting on the following field in a query:

3 Month Date: DateAdd("m",+3,[Current Date])

If I remove sorting the query works fine. When I add sorting to this column in the query design grid, I get the error message.

Any ideas?

Thanks,
BJS
 

WayneRyan

AWF VIP
Local time
Today, 15:39
Joined
Nov 19, 2002
Messages
7,122
BJS,

I can't replicate the problem. It works fine for me.

Wayne
 

BJS

Registered User.
Local time
Today, 15:39
Joined
Aug 29, 2002
Messages
109
Hi Wayne...thanks for looking at this!

I should have mentioned that the "Current Date" field in the design grid of the query looks like this:

Current Date: CDate(Format([CUR_MON],"00") & "/" & Format([CUR_DAY],"00") & "/" & Format([CUR_YR],"00"))

I can get the same error message when sorting on this field. I can sort on the "Current Date" field if I remove "CDate", but still am unable to sort on the "3 Month Date" field. I need to convert the data to Date so I can sort the records by date in the report which uses the query. Even if I do the sorting in the report, I get the same error.

Hope this helps.
 

mresann

Registered User.
Local time
Today, 07:39
Joined
Jan 11, 2005
Messages
357
I don't have a problem either. Can you post the whole query?
 

bvan

Registered User.
Local time
Today, 15:39
Joined
Dec 8, 2000
Messages
23
Some of the date functions (DateVal for example) choke when they hit nulls. See if your query is encountering any nulls in the date field. The result of a null is a type mismatch error.
 

BJS

Registered User.
Local time
Today, 15:39
Joined
Aug 29, 2002
Messages
109
I checked the data, there are no null values in the "Current Date" field.

I would post a sample of the db with the query, but it uses ODBC connection to DB2 tables. Here is a sample of the sql:

SELECT Table1.NAME, Table1.EMP_NO, CDate(Format([CUR_MON],"00") & "/" & Format([CUR_DAY],"00") & "/" & Format([CUR_YR],"00")) AS [Current Emp Date]
FROM Table1 INNER JOIN Table2 ON Table1.KEY = Table2.KEY
ORDER BY CDate(Format([CUR_MON],"00") & "/" & Format([CUR_DAY],"00") & "/" & Format([CUR_YR],"00"));

I checked for null values; there are none in the "Current Date" field.
I am starting to think that it is an issue with the data though; just need to find out which record.

Please let me know if the SQL looks good. Thanks!
 

FoFa

Registered User.
Local time
Today, 09:39
Joined
Jan 29, 2003
Messages
3,672
Why not just ORDER BY [CUR_YR], [CUR_MON], [CUR_DAY]
Would not that be the same as a date sort without all the conversion?
 

BJS

Registered User.
Local time
Today, 15:39
Joined
Aug 29, 2002
Messages
109
Thank you everyone! The problem was an invalid date (09/31/2004) in one of the records. The month of September only has 30 days.

Problem solved!
 

Users who are viewing this thread

Top Bottom