Link to home
Start Free TrialLog in
Avatar of peispud
peispudFlag for Canada

asked on

Use For Next loop to refer to data fields

Hi

Using Microsoft Access (latest version)

By example database fields

[Item 1]  --- Text field
[Item 2]  --- Text field
[Item 3]  ---  Text field

etc ... They are identical except by their numerical component in the name.

I would like to be able to do the following.

dim xxx as long
for xxx = 1 to 3
    "[Item"  & xxx & "]".visible = true
next xxx

Open in new window

Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peispud

ASKER

thank you!
it would be possible:
dim xxx as long for xxx = 1 to 3
controls("Item" & xxx ).visible = true
next xxx
Avatar of peispud

ASKER

Thank you
To add on a bit to Guy's comment, you can also do that with fields in a record set:

rst("myFieldsName" & xxx) = <some value>

 So you'd get myFieldName1, myFieldName2, myFieldName3, etc

This type of syntax is what Access converts to internally when working with objects. so it's a tad faster as well in that it doesn't have to do the conversion.

Jim.