Link to home
Start Free TrialLog in
Avatar of mlagrange
mlagrangeFlag for United States of America

asked on

"Data type mismatch in criteria expression", just by JOIN'ing to another table

Hello, I have two tables, say "tblParents" and "tblChildren" (Access 2010). They both have primary keys that are AutoNumber fields (say "ParentKey" and "ChildKey"). tblChildren carries ParentKey field as a Number, Long Integer.

There is a Relationship defined that LEFT JOIN's tblParents!ParentKey to tblChildren!ParentKey, as One-To-Many, all 3 options checked for Ref Integrity, Cascading Updates & Deletes.

I can start with a query with just tblChildren, printing most of the fields, for all records. No problems. But when I add tblParents to the query, and the JOIN is automatically created from the Relationship, I get the "Data type mismatch in criteria expression" error message, even if I don't throw down any fields from tblParents.

I have checked for missing or bad values in the key fields in both tables, and checked for orphans in tblChildren. Everything seems ok.

Any ideas?
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

We need to see the sql of the problem query.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, for kicks - try sorting tblChildren by ParentID.

Does that reveal any blanks/nulls in the ParentID field?  These may cause an error in your JOINs.
Avatar of mlagrange

ASKER

ok, I was filtering on a date field in tblChildren, which I was wrapping with DateValue() to get rid of the time component on some records, and that worked fine, until I JOIN'ed to tblParents, which had some parent records with no children, as it turns out...

"WHERE DateValue(tblChildren!ChildDate) <= #04/30/2013#  "

The filtering on the expression that assumed a value in the date field was what was causing the error message, when it hit the nulls.

I reversed the lay-out of the query, LEFT JOIN'ing  tblChildren to tblParents, and that side-steps the "childless" parent records.

Thank you for your responses