473,399 Members | 3,919 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,399 software developers and data experts.

Data type mismatch in criteria expression

Hello,

I know others have the same problem here, I tried (a lot! ) different solutions but still can't get around the problem.. :s

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cb_swedit_sopi_AfterUpdate()
  2. Dim qry_upd_sopi As Variant
  3.  
  4. On Error GoTo Err_sopi_AfterUpdate
  5.  
  6.     MsgBox (Me.RN_EQU)
  7.     MsgBox (Me.cb_swedit_sopi.Column(0))
  8.  
  9.     Me.txt_swedit_sopi_nr = Me.cb_swedit_sopi.Column(2)
  10.  
  11.     qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = '& Me.cb_swedit_sopi.Column(0) &' WHERE [Equipment and Software].RN_EQU = ' & Me.RN_EQU.Value &';"
  12.     DoCmd.RunSQL qry_upd_sopi
  13.  
  14. Err_sopi_AfterUpdate:
  15.     MsgBox Err.Description
  16.  
  17. End Sub
  18.  
cb_ is a ComboBox

Do I need " DoCmd.GoToRecord , , acGoTo " ?

Besides this, the error is data type mismatch in criteria expression
(Where did he say??)

So I guess there is a missmatch between the type of value I get from the ComboBox
and the type of value of the SOP_install field (number).
The error is still there even if I add ".ToNumber" or not to cb_blabla.Column(0)

RN_EQU: primary key and autonumber (long integer)
SOP_install: number (long integer) in both tables..

The Message Boxes display the correct numbers. Either with .Value or not.

Can anyone tell me what is going wrong here?
If more info needed, don't hesitate to ask!
Jul 20 '09 #1
14 3474
MikeTheBike
639 Expert 512MB
hI

May be this is the solution (your query is just a literal string) the quotation marks delimiters cause the variable/control values to be returned as part of the query string.

Expand|Select|Wrap|Line Numbers
  1. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = '" & Me.cb_swedit_sopi.Column(0) & "' WHERE [Equipment and Software].RN_EQU = '" & Me.RN_EQU.Value & "';"
??

MTB
Jul 20 '09 #2
So,

when I put double quotes, it still doesn't change a thing.

But when I add " .ToNumber " to cb_xx.Column(0)
It now says : "Object required".

I don't know what it means, so you can help me again :)
But I'll try also to look on my side..
Jul 20 '09 #3
ADezii
8,834 Expert 8TB
@ezechiel
Expand|Select|Wrap|Line Numbers
  1. Dim qry_upd_sopi As String
  2.  
  3. If IsNull(Me![RN_EQU]) Then Exit Sub
  4.  
  5. DoCmd.SetWarnings False
  6.  
  7. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = '" & _
  8.                 Me.cb_swedit_sopi.Column(0) & "' WHERE [Equipment and Software].RN_EQU = '" & _
  9.                 Me.RN_EQU.Value & "';"
  10.  
  11. DoCmd.RunSQL qry_upd_sopi
  12.  
  13. DoCmd.SetWarnings True
Jul 20 '09 #4
Hi,

thanks for the help, but still have a "data type mismatch" mith the code above.

If I put .ToNumber or .ToLongInteger I get object required again..

additional info:
-the cb's control source is empty -> unbound
- row source type is a query:
SELECT SOP.SOP_id, SOP.SOP_name, SOP.SOP_nr FROM SOP WHERE SOP_domain = "soft" AND (SOP_type = "I" OR SOP_type = "MI")

I created an application before and worked with buttons to insert and delete.
But here I use the AfterUpdate property to UPDATE. I see that updates in access cause a lot of trouble to people. Never had any problem before with a real SQL base and php for example.. So this is really confusing me.

Did I forget any other commands or something? I will lose my hair with this :)
Jul 20 '09 #5
ADezii
8,834 Expert 8TB
@ezechiel
Assuming everything else is correct, namely: Table Field Names are correct, Form Field is correct, Column Reference is valid, etc., there can be 1 of 4 possible SQL Statements depending on the Data Types of the 2 Fields ([SOP_install] and [RN_EQU]). They are:
Expand|Select|Wrap|Line Numbers
  1. '[SOP_install] and [RN_EQU] are STRINGS
  2. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = '" & _
  3.                 Me.cb_swedit_sopi.Column(0) & "' WHERE [Equipment and Software].RN_EQU = '" & _
  4.                 Me.RN_EQU.Value & "';"
  5.  
  6. '[SOP_install] and [RN_EQU] are NUMERIC
  7. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = " & _
  8.                 Me.cb_swedit_sopi.Column(0) & " WHERE [Equipment and Software].RN_EQU = " & _
  9.                 Me.RN_EQU.Value & ";"
  10.  
  11. '[SOP_install] is a STRING and [RN_EQU] is NUMERIC
  12. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = '" & _
  13.                 Me.cb_swedit_sopi.Column(0) & "' WHERE [Equipment and Software].RN_EQU = " & _
  14.                 Me.RN_EQU.Value & ";"
  15.  
  16. '[SOP_install] is NUMERIC and [RN_EQU] is A STRING
  17. qry_upd_sopi = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_install = " & _
  18.                 Me.cb_swedit_sopi.Column(0) & " WHERE [Equipment and Software].RN_EQU = '" & _
  19.                 Me.RN_EQU.Value & "';"
  20.  
Jul 20 '09 #6
ChipR
1,287 Expert 1GB
Since you specified that the table fields are Long Integer, you would use ADezii's 2nd query, at line 7 of the previous post.
If you start a string with a quotation, you need to close it with another quotation before you can append the value of a variable. You can't mix " and ' as in the original post.
Jul 20 '09 #7
Wouhouou!! It works! Thanks to you all.

And saying it was so simple... and that I tried with simple quotes, a mix of simple and double. But double only was the only thing that I didn't tried! Shame on me o_0; !!!


So it's working, my selection is recorded in the table. But now I have two other questions..

When I reopen the form, the cb's starting value is empty, what's normal.
In order to load the stored value, do I need to put:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     sql blabla select...  
  3. End Sub
Or is it something else to display the stored value in the cb?

The other question:
When I've selected my value in the cb, a messagebox is coming up, but it is empty (no text). Should there be something like "1 record updated"? If so,
how do I make it display in the msgbox.
If not, what could it be?
Jul 21 '09 #8
ChipR
1,287 Expert 1GB
If you want to get a stored value out of a table, you can use the DLookup function. It's not quite clear to me the way this form functions, or why you wouldn't just use a form bound to a recordset.
You have two MsgBox statements in your code, so you're going to have to be more specific about the other question.
Jul 21 '09 #9
Well, the access application is one mess (not mine ^^). The database is not ACID at all! So I' m improving it a bit, but it's not that easy.

This is probably a form created with the wizard. Every field is linked to a table.field trough record source. So Access creates the record once the form is closed. Since my cboxes are not 'record sourced' they do not function like the rest of the form. (and this creates other problems..) And I can't make them 'record sourced' since this would not display the right information or put the wrong information in the table. I tried with record source, but I'm unable to make it work liek I want it to..

The disadvantage (or advantage for some) are the 'automatic' jobs of Access.
Like: there is a form to add new software (autonumber ID). The field for this ID has a control source. You fill in the fields of the different tabs in the form, close the form and everything is saved in the new record (like an insert into..)

nb: procedure = SOP

TABLE (RN_EQU(strange name for software id...), other stuff, SOP_use (foreign key), SOP_maint (fk), etc..)

The problem I have here is with my comboboxes (for selecting SOP). I can't set a recordsource since I don't want to show an id number in the field. So I use vb (at least, with vb, you know how it works).

On the first tab, selecting the type (here "software"), triggers the creation of a new record in the table, the ID exists, but the record isn't created yet.
So when I choose a SOP with cb that triggers an update, the update doesn't work because the new record is in memory only. So now I'm searching how to arrange this problem... (maybe create a new post for this one.. form_onClose)

The field to fill in (in software table) with cb (insert or update) is an id which is a foreign key to another table. The information displayed in cb is the info from the other table SOP(id, name, and nr (not id)). This is done trough row source type: query and a SELECT query from the SOP table with some WHERE clauses.



It's kind a mess to explain because it is a mess in fact..
Here's the code that works for cb afterupdate and with which (is this English?) I have a msgbox displayed with no text..

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cb_swnew_sopu_AfterUpdate()
  3. Dim qry_upd_sopu As String
  4. On Error GoTo Err_sopu_AfterUpdate
  5.  
  6.     If IsNull(Me![RN_EQU]) Then Exit Sub
  7.     DoCmd.SetWarnings False
  8.  
  9.     Me.txt_swnew_sopu_nr = Me.cb_swnew_sopu.Column(2)
  10.  
  11.     qry_upd_sopu = "UPDATE [Equipment and Software] SET [Equipment and Software].SOP_use = " & _
  12.     Me.cb_swnew_sopu.Column(0) & " WHERE [Equipment and Software].RN_EQU = " & _
  13.     Me.RN_EQU.Value & ";"
  14.     DoCmd.RunSQL qry_upd_sopu
  15.     DoCmd.SetWarnings True
  16.  
  17. Err_sopu_AfterUpdate:
  18.     MsgBox Err.Description
  19.  
  20. End Sub
So I have no idea what Access is trying to say and why.. (1 record updated, perhaps?)
(I'll take a look at dlookup)
Jul 21 '09 #10
ChipR
1,287 Expert 1GB
Hah, your error code is being executed every time throught the function.
Jul 21 '09 #11
ChipR
1,287 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Function ...
  2. On Error GoTo ErrorHandler
  3.  
  4.     ...
  5.     ...
  6.  
  7. ExitCode:
  8.     Exit Function
  9.  
  10. ErrorHandler:
  11.     ...
  12.     Resume ExitCode
  13. End Function
Jul 21 '09 #12
Hi,

thanks, it works (when changing Function to Sub of course).
But how does it come that it is executed every time?
I picked up the 'old' error handling code somewhere else, used it in an other access prog and never had an issue like this..


What concerns Dlookup, I think I'll rather use something like
Expand|Select|Wrap|Line Numbers
  1. form_onLoad:
  2.  cb = select x, y, z from SOP where (match current software record and sop_id) 
This is not correct syntax, but I guess you get the idea?
Or is this a bad idea?
Jul 21 '09 #13
ChipR
1,287 Expert 1GB
The error handling code you had was executed because you were missing the Exit. The label on the code doesn't prevent it from being executed if you allow it to get there.
Are you talking about the source for the combo or the value for the current record? If you want to set it to the value for the current record, you need to get the value for the bound field and set it equal to that.
Jul 21 '09 #14
Well, my cb is like this:
control source: empty
Row Source:
SELECT SOP.SOP_id, SOP.SOP_name, SOP.SOP_nr
FROM SOP
WHERE SOP_id = 1 OR ((SOP_domain IN ("soft","all")) AND (SOP_type IN ("U", "UM")))
Bound Column: 1

And I only display SOP_name and SOP_nr

So I want the value for the current record to be displayed..
I don't understand this really much.. :s
you need to get the value for the bound field and set it equal to that.
Control source is still a bit confusing to me (after reading explanation on M$ site..)
Jul 21 '09 #15

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

Similar topics

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...
1
by: amitbadgi | last post by:
I am getting the following error while converting an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Data type mismatch in criteria expression. ...
2
by: igor.barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
5
by: blackburnj55 | last post by:
Hi, I am constructing a website for a bike shop. I am using dreamweaver and an access database to create it. I have made a query where two criteria are entered to get results. These are :...
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...
1
by: Bobby Edward | last post by:
Using Access db with VS2008 (ASP.NET/VB.NET).... On the INSERT command I get this error: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. I haven't found a...
9
by: nixonmg | last post by:
When the Command Button "Notify" is clicked, I am wanting to send out an email to the user with appropriate information in the email (works great), check the "Notified" check box (does not work), and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.