"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.
Code:
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"
cn.Open
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
rsTour.Update
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 :
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.
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.