Reference Dynamic Field Names

I have a table in which I need to take the data from the field "Name" and copy these values  into a fiield name that is named by the field "Level".

I think I'm close with the code below but I am getting Error 3219 Invalid Operation.  What am I doing wrong?


Set dbs = CurrentDb()
sTable = "tbl_Hierarchy"

    Set rs = dbs.OpenRecordset(sTable)


     rs.MoveFirst
                    
    Do While Not rs.EOF
    
        j = rs!Level + 4
        strName = rs!Name

        
        rs.Edit
        rs(j).Name = strName
        rs.Update
        
        rs.MoveNext
    Loop
   
rs.Close
dbs.Close
Set rs = Nothing

End Sub

Open in new window

rsaphierAsked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
If you are trying to copy data from a field in your recordset named "Name" into a field whose name is defined by rs!Level + 4 (this may mean that a different field is filled for each record in your recordset), I believe you need to write it as follows:

        rs.Edit
        rs(j)  = strName
        rs.Update


0
 
Rey Obrero (Capricorn1)Commented:
try this revision

        rs.Edit
        rs(rs(j).Name) = strName
        rs.Update
0
 
rsaphierAuthor Commented:
I knew I wasn't too far off the mark and it had to be something simple.  Thanks!
0
 
Rey Obrero (Capricorn1)Commented:
rsaphier,
did you try the post at http:#a36956205 ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.