Data Type error in ADO Code

Posted on 2007-07-30
Last Modified: 2010-04-30
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
        Set rs = Nothing
Question by:Takamine334
    LVL 18

    Accepted Solution

    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 & ")

    Author Comment

    I had to add the single quotes. thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    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…

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now