Run Time Error 3021

aziz rasul

Active member
Local time
Today, 10:16
Joined
Jun 26, 2000
Messages
1,935
I have the following code: -

Set rstqry = dbs.OpenRecordset("qryLO ID Count", dbOpenDynaset)
LOPID_Count = rstqry.RecordCount
rstqry.MoveFirst

On most occasions the recordset rstqry has x number of records. However on other occasions there are no records and hence I receive the "Run Time Error 3021". How can I alter the code so that it does not come up with this error?
 
here's what i usually do:

Set rstqry = dbs.OpenRecordset("qryLO ID Count", dbOpenDynaset)
If rstqry.RecordCount <> 0 Then
rstqry.MoveFirst
...
else
...
end if
...

testing is always important! hope i helped u!
 
That worked. Many Thanks.
 

Users who are viewing this thread

Back
Top Bottom