Solved

Update record error (data type mismatch)

Posted on 2003-11-03
8
338 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
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 250 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 250 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now