C
Chris C
I have the code below to run a query that matches two text boxes based on
input in one of the two. I'm not throwing any errors here, but I'm not
getting the results I'm expecting. To me, it looks like the query itself
isn't actually executing, but you can't use the QueryDef.Execute command here
[or so the application told me].
In a nutshell, I'm shooting a message box with a success message to the user
if the query returns anything other than 0 records, and if 0, a fail.
Everytime I click my button, it returns nothing, but I know the record match
exists already.
Any ideas?
Private Sub Command19_Click()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set dbs = CurrentDb
sqlStr = "SELECT count(*) As Total from tblError where "
sqlStr = sqlStr & "tblError.err_taskID = '" &
Forms!frmMatch.Controls!err_taskID & "' AND "
sqlStr = sqlStr & "tblError.error_details LIKE '%" &
Forms!frmMatch.Controls!mchText & "%'"
Set qdf = dbs.CreateQueryDef("", sqlStr)
If (qdf.RecordsAffected <> 0) Then
MsgBox ("Your text matches this error! Returned: " &
qdf.RecordsAffected & " rows")
Else
MsgBox ("Your text does not match this error. Returned: " &
qdf.RecordsAffected & " rows")
End If
qdf.Close
End Sub
input in one of the two. I'm not throwing any errors here, but I'm not
getting the results I'm expecting. To me, it looks like the query itself
isn't actually executing, but you can't use the QueryDef.Execute command here
[or so the application told me].
In a nutshell, I'm shooting a message box with a success message to the user
if the query returns anything other than 0 records, and if 0, a fail.
Everytime I click my button, it returns nothing, but I know the record match
exists already.
Any ideas?
Private Sub Command19_Click()
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set dbs = CurrentDb
sqlStr = "SELECT count(*) As Total from tblError where "
sqlStr = sqlStr & "tblError.err_taskID = '" &
Forms!frmMatch.Controls!err_taskID & "' AND "
sqlStr = sqlStr & "tblError.error_details LIKE '%" &
Forms!frmMatch.Controls!mchText & "%'"
Set qdf = dbs.CreateQueryDef("", sqlStr)
If (qdf.RecordsAffected <> 0) Then
MsgBox ("Your text matches this error! Returned: " &
qdf.RecordsAffected & " rows")
Else
MsgBox ("Your text does not match this error. Returned: " &
qdf.RecordsAffected & " rows")
End If
qdf.Close
End Sub