Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update record error (data type mismatch)

Posted on 2003-11-03
8
Medium Priority
?
345 Views
Last Modified: 2010-05-01
I'm trying to update a record. but i get the following error: Data type mismatch in criteria expression. error: -2147217913
I have spent 4 hrs and i can't find the solution. I'm going crazy. Is it because i'm using an array?  the debuging points to the .open

the Course_Registration_ID field in access is my Primary Key and is autonumber.
the intCourseID , i have changed to long and it doesn't work either.

Dim intCourseID as integer

intCourseID = txtCourseID(index).Text

strSQL = "SELECT * FROM Course_Registration "
         strSQL = strSQL & "WHERE Course_Registration.Course_Registration_ID = '" & _
                           intCourseID & "'"

With recCertificate
            .ActiveConnection = cnConn
            .LockType = adLockOptimistic
            .CursorType = adOpenKeyset
            .Source = strSQL
            .Open
            .MoveFirst
            .Find "Course_Registration_ID = '" & intCourseID & "'"
            .Fields("Certificate") = txtCertificate(index).Text
            .Fields("Certificate_Date") = Date
            .Update
            .Close
        End With
        Set recCertificate = Nothing

do you know what i am doing wrong?? thank you so much.
0
Comment
Question by:mapy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9675174
Does it help if you change strSQL to?

strSQL = "SELECT * FROM Course_Registration WHERE Course_Registration_ID = '" & _
                           intCourseID & "'"
0
 
LVL 29

Assisted Solution

by:leonstryker
leonstryker earned 1000 total points
ID: 9675249
Is Course_Registration_ID a numeric field?  Then your statement should be:

strSQL = "SELECT * FROM Course_Registration "
strSQL = strSQL & "WHERE Course_Registration.Course_Registration_ID = " & intCourseID

If that does not work, put a break point the line after the strSQL statement and copy you sql string from the immediate window into you database and try to run the query, see if that works.

Leon
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 1000 total points
ID: 9675418
rs.Open strSQL, , adOpenForwardOnly, adLockReadOnly
intCourseID = txtCourseID(index).Text

strSQL = "SELECT * FROM Course_Registration WHERE Course_Registration_ID=" & intCourseID

With recCertificate
            .ActiveConnection = cnConn
            .CursorLocation = adUseClient
            .Source = strSQL
            .Open strSQL, , adOpenKeyset, adLockOptimistic
            .MoveFirst
            .Find "Course_Registration_ID = '" & intCourseID & "'"
            .Fields("Certificate") = txtCertificate(index).Text
            .Fields("Certificate_Date") = Date
            .Update
            .Close
End With
Set recCertificate = Nothing

regards,
~ fantasy ~
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9675777
since you have declared :

Dim intCourseID as integer

intCourseID = txtCourseID(index).Text

strSQL = "SELECT * FROM Course_Registration "
         strSQL = strSQL & "WHERE Course_Registration.Course_Registration_ID = '" & _
                           intCourseID & "'"

I assume that the field Course_Registration.Course_Registration_ID is a NUMBER.  If that is correct then leonstryker is 100% correct.  get rid of the '....' around the intCourseID varaible in the SQL.  the '...' indicate that the value is a STRING of thext, not a NUMBER, and that will cause the Type Mismatch error.

AW
0
 

Author Comment

by:mapy
ID: 9679864
Thank you guys.   Strings don't need quotations, hey!  & "'"
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9680508
mapy,

No, strings do need quotes.  Numbers do not.

Leon
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683188
Thanks for that.

String do need quotes. And Numbers do not need that.

~ fantasy ~
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9683391
deja vu  

all other again
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question