Solved

Update record error (data type mismatch)

Posted on 2003-11-03
8
337 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 48
Run code from text file in vb 1 33
vb6 connector to mongodb 2 27
Macro Excel - Multiple If conditions 2 8
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

21 Experts available now in Live!

Get 1:1 Help Now