Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3021 2

Status
Not open for further replies.

BenjaminLim

IS-IT--Management
May 24, 2000
73
GB
Hi

I have the following error please assist:
Run-time 3021 - No current record

Code
======
Sub Forecast2()
Dim SeqA As String, NumA As String
Dim DateA As Date, OrigA As String
Dim db As Database, rstd1 As Recordset, rstd2 As Recordset
Dim rst As Recordset, rst1 As Recordset, rst2 As Recordset
Dim varBookmark As Variant
Dim varBookmark1 As Variant

Set db = CurrentDb
Set rst = db.OpenRecordset("Forecast2")
Set rstd1 = db.OpenRecordset("select Date1 from [First Date SubSet] order by date1", dbOpenSnapshot)
Set rstd2 = db.OpenRecordset("select Date1 from [Second Date SubSet] order by date1", dbOpenSnapshot)
Set rst1 = db.OpenRecordset("select * from [4d dated 07Jan01] order by Date1", dbOpenSnapshot)
Set rst2 = db.OpenRecordset("select * from [4d dated 10Jan01] order by Date1", dbOpenSnapshot)

rstd1.MoveFirst
Do Until rstd1.EOF
rst1.MoveLast
varBookmark = rst1.Bookmark
rst1.FindFirst "Date1 = #" & rstd1!Date1 & "#"
If rst1.NoMatch Then
rst1.Bookmark = varBookmark
Exit Do
End If
Do Until rst1.NoMatch
If rst1.NoMatch Then
rst1.Bookmark = varBookmark
Exit Do
End If
SeqA = rst1!Seq
NumA = rst1!Num1
DateA = rst1!Date1
OrigA = rst1!OrigNo
rstd2.MoveFirst
Do Until rstd2.EOF
If rstd2!Date1 > rstd1!Date1 Then
rst2.MoveLast
varBookmark1 = rst2.Bookmark
rst2.FindFirst "Date1 = #" & rstd2!Date1 & "#"
If rst2.NoMatch Then
rst2.Bookmark = varBookmark1
Exit Do
End If
Do Until rst2.NoMatch
If rst2.NoMatch Then
rst2.Bookmark = varBookmark1
Exit Do
End If
If rst2!Date1 > rst1!Date1 Then
rst.AddNew
rst!SeqA = SeqA
rst!SeqB = rst2!Seq
rst!NumA = NumA
rst!NumB = rst2!Num1
rst!DateA = DateA
rst!DateB = rst2!Date1
rst!OrigA = OrigA
rst!OrigB = rst2!OrigNo
rst!NumAB = NumA & rst2!Num1
rst.Update
End If
rst2.FindNext "Date1 = #" & rstd2!Date1 & "#"
Loop 'for rst2

End If 'rstd2!Date1 > rstd1!Date1
rstd2.MoveNext
Loop 'for rstd2
rst1.MoveNext
Loop 'for rst1.NoMatch
rstd1.MoveNext
Loop 'rstd1

End Sub


Pls advice. Thanks.

Regards
Benjamin

 
This error means that one of your recordsets is empty. Whenever you open a recordset, you should test to see if the recordset has records or not, to avoid this error:

You can use either
If rs.Recordcount > 0 Then OR
If rs.EOF And rs.BOF Then

==========
If rs.Recordcount > 0 Then
Do your Code ....
Else
Handle it if there are no records ...
End If
==========

If you have multiple recordsets, you should always handle the case that you won't have any recordsets returned:
==========
If rs.Recordcount > 0 Then
Do your Code ....

If rs2.Recordcount > 0 Then
Continue Code ....
Else
Handle no records in rs2...
End if
Else
Handle no records in rs ...
End If
==========

Two other things:

1) I usually open recordsets that return ONLY the records I want by using a WHERE statement. This way I do not have use the FindFirst and FindNext methods, as I will only have the records I want to deal with.

2) It is beneficial to name your recordsets with meaningful names rather than 1,2 (rsFirstDate, rsSecondDate, etc.).

If this did not answer your question, let us know. Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Jim,

God Bless You !
I had been struggling with the same error.

(rs.recordcount > 0) did the trick.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top