I have an Access 2010 database, where one of the tables has a list of Beneficiaries, and Intermediaries. For QC, I need to calculate the ownership of all Beneficiaries, and omit the ownership of entities that act as links between the bottom Beneficiaries and top Intermediaries. So I have a table with 4 columns of intermediaries. I want the following steps to occur:
- start with column "IMY_Up1", select the first intermediary ID number
- look through the second "IMY_Up2" column to see if that ID exists there.
- If it does - edit the "Linked IMY" column to "Yes", if it does not exist in that column - edit the "Linked IMY" column to "No".
Issue I'm facing: Current Code - Loops through accurately (Locals window shows 'i' and 'j' step through as expected). But only the first row has it's "Linked_IMy" value updated to "No".
Attempted Fix: put in 'Do While' loops. But this causes loop to continue to run, and no 'i' or 'j' value is reached in the Locals window.
My ultimate question: How can I change my code so it steps through and works as desired? Do I need to re-design the whole thing, and if so, how should I start?
Here is the VBA code:
Option Compare Database
Option Explicit
Public Sub modFieldlengthRegulate()
Dim i As Integer 'set "i" as integer for IMY_Up1 loop
Dim j As Integer 'set "j" as integer for IMY_Up2 loop
Dim db As DAO.Database 'imy database
Dim rs As DAO.Recordset 'QC_LoopTestTable as recordset
Set db = CurrentDb 'imy database
Set rs = db.OpenRecordset("QC_LoopTestTable") 'QC_LoopTestTable as recordset
For i = 0 To rs.RecordCount - 1 'set up for IMY_Up1 loop
rs.MoveFirst 'always start at first row
'Do While Not rs.EOF
'Set rs.Fields("IMY_Up1").Value = refSelect 'wanted to see what value it was assigning, but causes errors, so comment out
For j = 0 To rs.RecordCount - 1 'set up for IMY_Up2 loop
rs.MoveFirst
'Do While Not rs.EOF
'Set rs.Fields("IMY_Up2").Value = compareSelect 'wanted to see what value it was assigning, but causes errors, so comment out
If (rs.Fields("IMY_Up2").Value = rs.Fields("IMY_Up1").Value) Then
rs.Edit
rs.Fields("Linked_IMY") = "Yes"
rs.Update
Else:
rs.Edit
rs.Fields("Linked_IMY") = "No"
rs.Update
End If
'Loop
Next j
'Loop
Next i
rs.Close 'close the recordset as part of the last step
Set rs = Nothing 'close the recordset as part of the last step
db.Close 'close the database as part of the last step
End Sub

rs.MoveNextto get it to move to the next record.