Link to home
Start Free TrialLog in
Avatar of mosemadl
mosemadl

asked on

Data type mismatch in criteria expression.

I've done this a million times, but I keep getting the error: Data type mismatch in criteria expression from the following code.

valCancel = DateTime.Now() & "-" & TracktionUser
strCancel = "Update CWE_Debug Set Cancel=@Cancel Where UserCode = '" & valUser & "' And ExamID = '" & valExam & "'"
cmdCancel = New OleDbCommand( strCancel, conTracktion )                                                            
cmdCancel.Parameters.Add( "@ExamID", OleDBType.Char).Value = valCancel                   
cmdCancel.ExecuteNonQuery()

valCancel is defined as a string and the Cancel field in my Access DB is ShortText. I've tried to update other fields in the table and got the same error. So I thought my DB got corrupted and I run repair. Is there a line of code to ask what oledbtype its looking for? I'm completely stumped on this one. Anybody have any ideas?
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Can you state what that code is suppose to be doing, ...you naming is throwing me off...
Avatar of mosemadl
mosemadl

ASKER

I just need to update a field labeled 'Cancel' to be a string like "5/12/2015-Moseman".
Cstr([Cancel])

Note that "Cancel" is a bad name for a field, ..as it is a reserved word.
Note that you should be able to concatenate values to a ate field without Cstr()...
According to this https://support.microsoft.com/en-us/kb/286335 its not a reserved word, but I'll try changing it anyway.
It is a reserved word in VBA...
ex:
    Private Sub Combo1_BeforeUpdate(Cancel As Integer)

...it is also a property of some objects:
User generated image
Nope! I renamed the field to 'CancelStr' and I still get data type mismatch. No idea what type it thinks it is.
ASKER CERTIFIED SOLUTION
Avatar of mosemadl
mosemadl

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
The filed name was not part of the issue, ..I merely mentioned the name as a note...

Lets be clear, ...did you then still wrapped the field in the cst() function:
Cstr(CancelStr)
...and you still got the error?
I figured it out.