BenjaminLim
IS-IT--Management
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
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