J
Joseph Atie
im trying to iterate through 2 recordsets.
the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
relationship.
so the idea is for each loop of rs1 there should be serveral loops of rs2.
but im stuck inside my loops and cant seem to find a way out.
help please
Set rs1 = CurrentDb.OpenRecordset(qry1)
'loop through transaction codes and check if items have been returned
If Not (rs1.BOF And rs1.EOF) Then
rs1.MoveFirst
Do While Not rs1.EOF
'set closed to catch open record
closed = True
'collect transcode from recordset and search transdata
tcode = rs1.Fields("transcode")
qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
WHERE Transdata.Transcode= " & tcode & ";"
Set rs2 = CurrentDb.OpenRecordset(qry2)
If Not (rs2.BOF And rs2.EOF) Then
rs2.MoveFirst
'loop through transdata for each transaction code, set closed to
true if open record found
Do While Not rs2.EOF
If IsNull(rs2.Fields("in")) Then
closed = False
rs2.MoveLast
Else
rs2.MoveNext
End If
Loop
End If
If closed = True Then
rs1.Edit
rs1.Fields("in date") = Date
rs1.Update
rs1.MoveNext
End If
Loop
End If
the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
relationship.
so the idea is for each loop of rs1 there should be serveral loops of rs2.
but im stuck inside my loops and cant seem to find a way out.
help please
Set rs1 = CurrentDb.OpenRecordset(qry1)
'loop through transaction codes and check if items have been returned
If Not (rs1.BOF And rs1.EOF) Then
rs1.MoveFirst
Do While Not rs1.EOF
'set closed to catch open record
closed = True
'collect transcode from recordset and search transdata
tcode = rs1.Fields("transcode")
qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
WHERE Transdata.Transcode= " & tcode & ";"
Set rs2 = CurrentDb.OpenRecordset(qry2)
If Not (rs2.BOF And rs2.EOF) Then
rs2.MoveFirst
'loop through transdata for each transaction code, set closed to
true if open record found
Do While Not rs2.EOF
If IsNull(rs2.Fields("in")) Then
closed = False
rs2.MoveLast
Else
rs2.MoveNext
End If
Loop
End If
If closed = True Then
rs1.Edit
rs1.Fields("in date") = Date
rs1.Update
rs1.MoveNext
End If
Loop
End If