Full Version: Loop through table fields
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
rost_b
Hi. Trying to find how to do something like this:

for each Field in Table
if Field.Name = myName then
Field.Value = "Example"
end if
next

How do I go about it? Thanks.
treeless
Is this just one table, or a number of tables?

Hopefully, it is just one, and you can use the query builder to build an update query to update all values in the myName field to "Example"
rost_b
It is one table. But the issue is not in updating values. I'm struggling with looping through field names in any given table.
xteam
Dim fldItem
Dim rst as recordset

Set rst = CurrentDb.OpenRecordset("YourTable",dbOpenDynaset)

' here assuming you moved to desired record in your recordset

For Each fldItem In rst.Fields
If fldPO.Name = myName Then
rst.Edit
rst(fldItem.Name) = "Example"
rst.Update
Endif

Next
rost_b
Thanks a lot, xteam.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.