Thomas Brooks
Thomas Brooks

Reputation: 11

MS access select specific data cell

I have a field named "name" and I want to loop through that field and get each row value in a form such that it can be saved to a VBA variable. I'm having an issue with specifying the column & row and saving it to a VBA variable. Can anyone help me with this?

Upvotes: 0

Views: 1233

Answers (1)

HansUp
HansUp

Reputation: 97101

A data bound form has has a Recordset. It also has a RecordsetClone, which is a read-only copy of the Recordset.

Using VBA, you can loop through the rows of the RecordsetClone and read the value of any field in the current row. Most often we indicate which field we want to read by field name rather than the field's ordinal position, but you can do it either way.

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.MoveFirst
Do While Not rs.EOF
    Debug.Print rs!id ' value of field named id '
    Debug.Print rs(0) ' value of first field in recordset '
    rs.MoveNext
Loop
Set rs = Nothing

Upvotes: 1

Related Questions