"Data type mismatch in criteria expression" need help in query

irishmike94

New Member
Joined
Sep 24, 2011
Messages
26
Hi guys,

I wanted to add a query from a rugby player database with position (number) and team (either A or B). I want to run a query for players in the A team and with positions 1, 2 and 3. So the criteria are based on two fields of data. However when I try to do "A" in team, it works perfectly showing all A team players, and yet, when I add "1", "2", "3" to the position column it shows an error saying "Data type mismatch in criteria expression".

I don't know how to solve this error, and I could really use some help!!

Thanks in advance;

irishmike94
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I am trying to get some base line working to start from.
Try writing the query yourself with the single criteria (using the Table you first mentioned, not the Query), and see if you can get that working.
Then post that SQL code here. I want to see how it differs from the first criteria code I provided. That may hold a clue as to what is going on.

Also, ae any non-text entries in the Team? field? (I assume it is all text).
 
Upvote 0
The key to debugging something like this is start simple (maybe even no criteria at all) and then add them in, one at a time, checking each time to see if it works. At the point it "breaks", you know the last thing you added is the thing that broke it. And that is where you need to put your focus on.

If you are adding a whole bunch of criteria, and one far down the line crashes, restart creating a brand new query, addng that problematic criteria first (with no other criteria). That will confirm that is the cause of the problem, and then you can play around with it, seeing if you can get it to work without any interference from any other criteria.

Sometimes it is not the criteria that is the problem, but a data issue. So you may want to inspect the data you are placing the criteria on looking for any odd data (blanks, nulls, errors, etc).
 
Upvote 0
I have sorted it;

WHERE (((QryFullNamePlayer.Position)=1) AND ((QryFullNamePlayer.[Team?])="A")) OR (((QryFullNamePlayer.Position)=2) AND ((QryFullNamePlayer.[Team?])="A")) OR (((QryFullNamePlayer.Position)=3) AND ((QryFullNamePlayer.[Team?])="A"));

Thanks for your support, without it, this result wouldn't have been reached, thank you all xxx

irismke94
 
Upvote 0
Ah, so it looks like it might have been an issue with the precedence of AND and OR, and parentheses. Glad you got it figured out!
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top