473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Datatype mismatch in criteria expression - query

13
Hello -

I am a novice in MS Access and do not know SQL. I am using Access 2003.

I have set up two queries that seem to be working fine. Each comes directly from a table. I have joined the two queries in a "include all records from A and only those records from B where the joined fields are equal" join.

The fields that I am using for the join are both fixed decimal, zero decimal place fields in their respective queries.

I am getting the "datatype mismatch in criteria expression" error, but have no idea how to go about de-bugging to track down the problem.

I gather from reading other posts that the problem may not even be in the join fields, but could be elsewhere. But how do I go about tracking this down?

The SQL code from the join is below.

thanks very much in advance,
Kristin Graves
Expand|Select|Wrap|Line Numbers
  1. SELECT gibbons_starting_meter_list.Account15,
  2.        gibbons_starting_meter_list.[Old Mtr Prfx],
  3.        gibbons_starting_meter_list.[Old Mtr #],
  4.        mv90_info.Channels,
  5.        gibbons_starting_meter_list.[New Mtr Prfx],
  6.        gibbons_starting_meter_list.[New Mtr #],
  7.        gibbons_starting_meter_list.[Trucking Order #],
  8.        gibbons_starting_meter_list.[Ship Date],
  9.        mv90_info.LPC_Phone,
  10.        gibbons_starting_meter_list.[Comm Type],
  11.        gibbons_starting_meter_list.[Signal Strength],
  12.        gibbons_starting_meter_list.[Signal Quality],
  13.        gibbons_starting_meter_list.[New Equip?],
  14.        gibbons_starting_meter_list.[Timers Date],
  15.        gibbons_starting_meter_list.[LPDS Date],
  16.        gibbons_starting_meter_list.[MExtra 1],
  17.        gibbons_starting_meter_list.[MExtra 2],
  18.        gibbons_starting_meter_list.[MExtra 3],
  19.        gibbons_starting_meter_list.[MExtra 4],
  20.        gibbons_starting_meter_list.[MExtra 5],
  21.        gibbons_starting_meter_list.Comments
  22.  
  23. FROM   gibbons_starting_meter_list LEFT JOIN
  24.        mv90_info
  25.   ON   gibbons_starting_meter_list.[Old Mtr #] = mv90_info.Meter;
Mar 11 '10 #1
12 8272
TheSmileyCoder
2,322 Expert Mod 2GB
You have no WHERE clause in your SQL statement, so I would guess that it IS related to the join.


Your joining Field [Old Mtr #] from Table gibbons_starting_meter_list with Field Meter from table mv90_info

To start debugging this, I would suggest opening each of the tables in design view, and finding those Fields in each table, and checking the datatype. Its likely to be either String or number. If its Number, you also need to check what KIND of number it is, Byte, Integer, Long, Single, Double.

Report that back here, and we can advice you on how to proceed.
It would also help if you post a few entries from each of the joined fields, from each table, so we can tell you if its "safe" to change the datatype, in order to allow the join.
Mar 11 '10 #2
NeoPa
32,556 Expert Mod 16PB
It's also conceivable that the error is actually coming from one or both of the subqueries.

Like Smiley, I'll request that you report back after you've tried running each of the subqueries individually.

Have fun and Welcome to Bytes!
Mar 11 '10 #3
gravesk
13
OK, here is a little more about my set-up and the format of my fields.

I start with two tables, read each of those tables into a query, and then the problem comes when I try to join the two queries into a third query.

Here is the information about the field formats for my two join fields:
[Old Mtr #] field
The starting point for the [Old Mtr #] field is table A. In table A, the field is called E_MTR_NO, and the format is number, long integer, fixed, 0 decimal places.

The query that reads table A is called gibbons_starting_meter_list. In that query, I re-name E_MTR_NO as follows: Old Mtr #: E_MTR_NO -- the format is fixed, 0 decimal places. Each record is populated with a non-zero value.

Some sample records follow:
Old Mtr #
7116190
7117022
7719119
7144228
7144239
19893
7424026


[Meter] field
The starting point for the [Meter] field is table B. In table B, the field is called RecorderID, and it is a text field with the meter number embedded in it - I fix that in the query. The specific format is text (I don't see any other parameters assigned).

The query that reads table B is called mv90_info. In that query, I re-name and fix RecorderID as follows: Meter: IIf(Left([RecorderID],3)="REC",Val(Mid([RecorderID],4,7)),Val([RecorderID])) -- the format is fixed, 0 decimal places. There are quite a number of records that take a value of 0.

Sample records follow:
Meter
90370107
40360309
6596820
6815256
6815261
87940
87941
87942



Thanks again for any help you folks can provide.
Mar 11 '10 #4
NeoPa
32,556 Expert Mod 16PB
@NeoPa
Did you run the queries separately? Were there any problems reported?
Mar 11 '10 #5
TheSmileyCoder
2,322 Expert Mod 2GB
If it was me, I would try to:
1) Add a new field ot table B, lets call it NewMeter, making it Number, Long Integer. Remember that Fixed and 0 decimal spaces, has nothing to do with the STORAGE of the value, only how its visually presented to the user.

2) Run a update Query on Table B, setting NewMeter=IIf(Left([RecorderID],3)="REC",Val(Mid([RecorderID],4,7)),Val([RecorderID]))

3) Then run the original query, joining on the new field.
The problem as I see it (could be wrong) is that your trying to join a String with a Number field.


It might also work in the original query if you do a conversion Meter:Clng(IIf(Left([RecorderID],3)="REC",Val(Mid([RecorderID],4,7)),Val([RecorderID]))) though Im a bit fuzy on that.
Mar 11 '10 #6
NeoPa
32,556 Expert Mod 16PB
@TheSmileyOne
Although the original data is textual Smiley, the result after the Val() call is numeric. This is a typical way of linking two datasets where the originating data doesn't have linkable fields. It's the method I'd recommend in a similar situation.
Mar 11 '10 #7
TheSmileyCoder
2,322 Expert Mod 2GB
I learned something today too then. Thank you. :)
Mar 11 '10 #8
NeoPa
32,556 Expert Mod 16PB
@TheSmileyOne
I missed this bit earlier. This is actually very close to what may be required (still waiting on some results).

If the data that is being linked to is actually long, then CLng() would be a better conversion function to use. Also, as you have it, the conversion function could happily be outside of (encapsulating) the whole IIf() function call. There is then no requirement to call it twice inside. Something like :
Expand|Select|Wrap|Line Numbers
  1. CLng(IIf(Left([RecorderID],3)='REC',Mid([RecorderID],4,7),[RecorderID]))
I presume this is here because some of the records preceed the number with the text "REC".
@TheSmileyOne
Always a pleasure. I frequently learn things and pick up tips from the other experts around here.
Mar 11 '10 #9
gravesk
13
Yes, I did run the two queries separately without problems. Everything appears to be fine when I do it separately.

I will try the CLng function as suggested. If CLng doesn't do it, then I'll try the new field and the update query (I don't even know what that is, but I'll look it up), and then the revised original query joining on the new field (all as suggested by thesmileyone.

I'll get back with results, but it won't be til Saturday.

Thanks again everyone!

Thanks.
Mar 11 '10 #10
NeoPa
32,556 Expert Mod 16PB
@gravesk
Cool. Thanks for keeping us updated.

In view of your answer to my question, I would recommend the SQL posted in my previous post. I'd be interested to hear if that works for you. I can only assume that the Val() function was too non-specific to match the fields from the two sources.
Mar 12 '10 #11
gravesk
13
Hi all - I tried the CLng function as suggested by NeoPa, but it did not work.

I then looked into the three-step process suggested by TheSmileyOne. As I mentioned earlier, I am pretty inexperienced with Access. One thing that I had not mentioned previously is that my tables are imported from Excel worksheets. Moreover, the worksheets are refreshable (that is, with the click of a button, they update with the latest set of data from an external database). The way that I have the Access set up, we will periodically be refreshing the Excel worksheets and then importing them into Access, where we will be running the queries, forms, etc. This is a long-winded way of saying that it appeared to me to be easier to get the right formula for my meter number field in Excel than in Access. So, that's what I did. I extracted the numeric part of the number in Excel, used that field in Access, and it is working fine now.

I greatly appreciate the time that you folks spent helping me out, and learned quite a bit along the way about formats in Access, various functions, etc. so this was not a waste of anyone's time.

Thank you all so much for your help with this.

Kristin Graves
Mar 13 '10 #12
NeoPa
32,556 Expert Mod 16PB
Thanks again for the update Kristin.

I can't see why the process wouldn't have worked as suggested, but there are always imponderables when dealing via a forum site. The important thing is that you're happy with your results.
Mar 15 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't...
2
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".  Here's an example table that I'm working with... ...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
1
by: ArcadeJr | last post by:
Good morning all! I have been getting a Run-time Error message #3464 - Data Type mismatch in criteria expression. While trying to run a query. I have a database where the field Asset_Number...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
6
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
2
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of...
0
by: Snoopy33 | last post by:
I have a query that builds a date from a text field with the date imput as yyyymmdd in the query, so i have to piece it together in my expression as follows: exp:...
14
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.