G
Guest
The following code is run on two queries, in order to update a field on the
master query (rst1). It is designed to take the first record in rst1 and
determine if the ID from rst1 is matched by a single record in rst2 (in which
case the capture field will be equal to "I") or more than one record in rst2
(in which case the capture field will be equal to "R"). The program runs
fine on all rcords in rst1 except for the first. The first two records in
rst2 have the same ID as rst1. The first has capture = "I" and the second
has capture = "R". Therefore, I am expecting the JUSTI field to be updated
with a "no", but it is updated with a "yes". All other records appear to be
updated correctly. Any ideas on which the first update is erroneous.
Thanks,
LAF
Option Compare Database
Option Explicit
Sub InitialAge()
Dim db As DAO.Database
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim CurrentID As String
Dim sSQL As String
Set db = CurrentDb()
Set rst1 = db.OpenRecordset("qryBirds", dbOpenDynaset)
Set rst2 = db.OpenRecordset("qryBandnumCapture", dbOpenDynaset)
rst1.MoveFirst
rst2.MoveFirst
Do Until rst1.EOF
CurrentID = rst1!Bandnum
sSQL = "[Bandnum]= '" & CurrentID & "'"
rst2.FindLast sSQL
If rst2!Capture = "R" Then
rst1.Edit
rst1!JustI = "no"
rst1.Update
ElseIf rst2!Capture = "I" Then
rst1.Edit
rst1!JustI = "yes"
rst1.Update
End If
rst1.MoveNext
Loop
rst1.Close
rst2.Close
Set rst1 = Nothing
Set rst2 = Nothing
Set db = Nothing
End Sub
master query (rst1). It is designed to take the first record in rst1 and
determine if the ID from rst1 is matched by a single record in rst2 (in which
case the capture field will be equal to "I") or more than one record in rst2
(in which case the capture field will be equal to "R"). The program runs
fine on all rcords in rst1 except for the first. The first two records in
rst2 have the same ID as rst1. The first has capture = "I" and the second
has capture = "R". Therefore, I am expecting the JUSTI field to be updated
with a "no", but it is updated with a "yes". All other records appear to be
updated correctly. Any ideas on which the first update is erroneous.
Thanks,
LAF
Option Compare Database
Option Explicit
Sub InitialAge()
Dim db As DAO.Database
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim CurrentID As String
Dim sSQL As String
Set db = CurrentDb()
Set rst1 = db.OpenRecordset("qryBirds", dbOpenDynaset)
Set rst2 = db.OpenRecordset("qryBandnumCapture", dbOpenDynaset)
rst1.MoveFirst
rst2.MoveFirst
Do Until rst1.EOF
CurrentID = rst1!Bandnum
sSQL = "[Bandnum]= '" & CurrentID & "'"
rst2.FindLast sSQL
If rst2!Capture = "R" Then
rst1.Edit
rst1!JustI = "no"
rst1.Update
ElseIf rst2!Capture = "I" Then
rst1.Edit
rst1!JustI = "yes"
rst1.Update
End If
rst1.MoveNext
Loop
rst1.Close
rst2.Close
Set rst1 = Nothing
Set rst2 = Nothing
Set db = Nothing
End Sub