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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3021

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
 
First, of course, check that your [First Date SubSet] and [Second Date SubSet] tables/queries are not empty. Either of these would cause the problem.

The next thing I note is that your second loop, "Do Until rst1.NoMatch", ends with "rst1.MoveNext". There are no Find... calls within it. NoMatch can only become true on a Find... (or Seek) call. Since you don't have one within the loop, the loop can never terminate properly.

Did you mean "rst1.FindNext ..." before the second to last Loop statement?

Some advice: Put some comments in there! You're familiar with it now, but in a few months it won't be so easy to read. And it's really tough on us who don't know what you're doing here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top