Solved

Update record error (data type mismatch)

Posted on 2003-11-03
8
344 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 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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

630 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