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?
mosemadlAsked:
Who is Participating?
 
mosemadlAuthor Commented:
That was weird. I changed the criteria for finding the record to update and it worked, but either way it found the same record. Possible it had to do with one of the criteria being a primary key.
0
 
Jeffrey CoachmanMIS LiasonCommented:
Can you state what that code is suppose to be doing, ...you naming is throwing me off...
0
 
mosemadlAuthor Commented:
I just need to update a field labeled 'Cancel' to be a string like "5/12/2015-Moseman".
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jeffrey CoachmanMIS LiasonCommented:
Cstr([Cancel])

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

...it is also a property of some objects:
cancel Property
0
 
mosemadlAuthor Commented:
Nope! I renamed the field to 'CancelStr' and I still get data type mismatch. No idea what type it thinks it is.
0
 
Jeffrey CoachmanMIS LiasonCommented:
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?
0
 
Jeffrey CoachmanMIS LiasonCommented:
ok great
0
 
mosemadlAuthor Commented:
I figured it out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.