J
J Bailey
I am trying to loop through a recordset using a do until
loop in Access 97. Here is an example of the code:
Dim rsTimeoff As ADODB.recordset
Dim ConnStr6 As String
ConnStr6 = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
" Data Source "
Set rsTimeoff = New ADODB.recordset
rsTimeoff.Open "us_TimeOff", ConnStr6,
adOpenForwardOnly, adLockPessimistic
rsTimeoff.MoveFirst
Do Until (rsTimeoff!us_agentSSN = strGlobalSSN And
rsTimeoff!us_Date = dtmJobDate) Or (rsTimeoff.EOF = True)
rsTimeoff.MoveNext
Loop
The loop works fine when there is a record in the
recordset that matches the variables that are being
compared. Whenever there is not a record in the recordset
that matches the variables, the loop continues until it
reaches the End Of File (.EOF). At this point it should
jump out of the loop and perform the next line in the code
outside of the loop structure. Instead, it is throwing an
error. The error is the 3021 runtime error. How can I
prevent this from occuring using Access 97's VBA. I am
using ADO to connect to the database if this helps. I
have written code very similar to this in the past with
VB6 and it works just fine. I even have examples in books
that do the same thing in VB6. How can I get the loop to
end and jump to the next line in the code when it
reaches .EOF? Any help would be greatly appreciated.
Thanks
JDB
loop in Access 97. Here is an example of the code:
Dim rsTimeoff As ADODB.recordset
Dim ConnStr6 As String
ConnStr6 = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
" Data Source "
Set rsTimeoff = New ADODB.recordset
rsTimeoff.Open "us_TimeOff", ConnStr6,
adOpenForwardOnly, adLockPessimistic
rsTimeoff.MoveFirst
Do Until (rsTimeoff!us_agentSSN = strGlobalSSN And
rsTimeoff!us_Date = dtmJobDate) Or (rsTimeoff.EOF = True)
rsTimeoff.MoveNext
Loop
The loop works fine when there is a record in the
recordset that matches the variables that are being
compared. Whenever there is not a record in the recordset
that matches the variables, the loop continues until it
reaches the End Of File (.EOF). At this point it should
jump out of the loop and perform the next line in the code
outside of the loop structure. Instead, it is throwing an
error. The error is the 3021 runtime error. How can I
prevent this from occuring using Access 97's VBA. I am
using ADO to connect to the database if this helps. I
have written code very similar to this in the past with
VB6 and it works just fine. I even have examples in books
that do the same thing in VB6. How can I get the loop to
end and jump to the next line in the code when it
reaches .EOF? Any help would be greatly appreciated.
Thanks
JDB