Frustrating Error: "Data type mismatch" with Subquery

G

Guest

The following query returns the error "Data type mismatch in criteria
expression" and I honestly have NO CLUE why this doesn't work:

SELECT * FROM
(SELECT * FROM qryProjects WHERE qryProjects.ID IN
(SELECT ID FROM tblProjects
WHERE tblProjects.connectionDate IS NOTNULL)
) AS tblNew
WHERE MonthName(DatePart('m',tblNew.ConDate)) = "February";

Basically the qryProjects will format the dates in tblProjects according to
a date format specified in tblProjects. However not all rows in tblProjects
specify a date, so I filter those out with the subquery. I know MonthName is
returning a string (and I even tried casting it to a string with CStr)
because when I do the following, I get a list of months:

SELECT MonthName(DatePart('m',tblNew.ConDate)) FROM
(SELECT * FROM qryProjects WHERE qryProjects.ID IN
(SELECT ID FROM tblProjects
WHERE tblProjects.connectionDate IS NOTNULL)
) AS tblNew;

Can someone PLEASE help me figure this out?
 
G

Guest

NOTNULL should be Not Null.

Instead of:
MonthName(DatePart('m',tblNew.ConDate)) = "February";
try
MonthName(DatePart('m',tblNew.ConDate)) = 2;
 
G

Guest

Sorry, I made a typo when typing the query in here, I have "NOT NULL" in my
Access query & I still get the criteria error expression.

I tried the MonthName(...) = 2, it didn't work... MonthName should simply be
returning a string. In the second query I specified, I got a list of month
names so I know that this little function is outputting what I want... but
for some reason I just can't compare it to ANYTHING.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top