I'm brand new to recordsets in code, so chuckle all you want. I'm trying
to
open a recordset by executing some sql, iterate through two records or no
records in code using the existing connection when something takes place
on a
form (afterUpdate). I was hoping I didn't have to create a new instance
of
connection? But, obviously don't know what I'm doing. Any help? Many
thanks.
Dim varSql As String
Dim myErr As Integer
Dim adoRS As New ADODB.Recordset
varSql = "SELECT top 2 [maximum] as myMax FROM tblAbsentee ORDER BY
[maximum] DESC where [subLotID]=" & Me.subLotID.Value
adoRS = DoCmd.RunSQL varSql
if adoRS.EOF then
myErr=1
else
myErr = 0
end if
Do While Not adoRS.EOF
If Me.maximum < adoRS.Fields("myMax").Value Then
myErr = myErr+1
End If
adoRS.MoveNext
Loop
adoRS.Close
Set adoRS = Nothing
Results = msgBox(myErr, vbOKOnly, "My results")