• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Data Type error in ADO Code

Why am I getting a "Data Type Mismatch in criteria expression" on this line?

Set rs = Myconn.Execute("SELECT * FROM " & SaveDBName & " WHERE ID='" & List1.Text & "'")



It comes from this code:

Dim rs As ADODB.Recordset

    Set rs = Myconn.Execute("SELECT * FROM " & SaveDBName & " WHERE ID='" & List1.Text & "'")
    If rs.EOF Then
        Myconn.Execute "INSERT INTO " & SaveDBName & " (ID) VALUES ('" & List1.Text & "')"
    End If
        rs.Close
        Set rs = Nothing
0
Takamine334
Asked:
Takamine334
1 Solution
 
SethiCommented:
Is ID field a text field or a numeric field? If it is a numeric field then you dont have to use the single quotes and the statement will be like this:
Set rs = Myconn.Execute("SELECT * FROM " & SaveDBName & " WHERE ID=" & List1.Text & ")
0
 
Takamine334Author Commented:
I had to add the single quotes. thank you!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now