Results 1 to 2 of 2
  1. #1

    Thread Starter
    Join Date
    Jun 2012

    "Data type mismatch in criteria expression" in SQL statement

    hey there,

    Here's my complete code for a delete button that deletes a record in a Hierarchical Flex Grid.

        Dim rsTour As New ADODB.Recordset
        Dim cn As New ADODB.Connection
        Dim strSQL As String
        cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & App.Path & "\Luckshan Tours & Travels.mdb;" & _
        "Persist Security Info:False"
        msg = MsgBox("Delete Record?", vbYesNo)
        If msg = vbYes Then
        strSQL = "Delete From Tour Where [Tour ID] = '" & fgdTour.TextMatrix(fgdTour.Row, 1) & "'"
        cn.Execute strSQL
        strSQL = "Select * From Tour"
        rsTour.Open strSQL, cn, adOpenStatic, adLockPessimistic
        Set fgdTour.DataSource = rsTour
        End If
        Set fgdTour.DataSource = rsTour
        If rsTour.RecordCount <> 0 Then
        End If
    The code works great for two of my forms, but for the other two it doesn't. It gives me an error saying "Data type mismatch in criteria expression" and highlights the statement :

    cn.Execute strSQL
    Please help.... I've gone over and over the code for errors but could find none, I mean it works perfectly for the other two forms.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Bristol, UK

    Re: "Data type mismatch in criteria expression" in SQL statement

    What data type is the TourID field in the database?

    If it isn't Text/String based, there is an error in the way you specified the value. For an explanation and examples of delimiters to use around values within SQL statements, see the article How do I use values (numbers, strings, dates) in SQL statements? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)

    You should also check what your SQL statement contains at the time of the error, because you cannot tell from just the code what it will be.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width