The below code used to work with DAO - I've now changed it to ADO and although the query is valid and there are 2 records returned when I run the query in Query Design, the recordcount is always -1. Anyone got an idea why this might be?
Private Sub UpdateData(dMyDate as Date, lID as Long, sCriteria as String)
Dim sSQL As String, sSearchStr As String
Dim rst1 As New ADODB.Recordset
Dim sCurrPair As String
Dim sCriteria as String
sSearchStr = "[FieldA] = '" & sCriteria & "'"
sSQL = "Select ID, FieldA, FieldB, FieldC,FieldD, FieldE, " & _
"FieldF, FieldG, FieldH from tbl where " & sSearchStr & _
" AND [FieldF] = #" & Format(dMyDate, "mm/dd/yy") & "#"
' sSQL is equal to:
' Select ID, FieldA, FieldB, FieldC, FieldD, FieldE, FieldF, FieldG, FieldH from tbl where [FieldF] = 'data' AND [FieldF] = #01/03/06#
rst1.Open sSQL, CurrentProject.Connection,
adOpenDynamic, adLockOptimistic, adCmdText
If rst1.RecordCount = -1 Then
Start Free Trial