johnny93
johnny93

Reputation: 225

Set up text boxes in MS Access form as array?

Is there a way to set up text boxes in Access forms as arrays for use in loops with VBA?

Upvotes: 4

Views: 2469

Answers (2)

VBlades
VBlades

Reputation: 2251

I would disagree with serakfalcon in terms of requiring a certain naming schema to iterate through textboxes. The proper way would be to look at the control type. It should really be done like this:

Dim ctl As Access.Control

For Each ctl In Forms!MyForm.Controls
    If ctl.ControlType = acTextbox Then
         '...your code here.
    End If
Next

This does not require a specific naming schema (not saying it is a bad idea, it isn't) and you know for sure the object is what you are expecting.

Upvotes: 2

serakfalcon
serakfalcon

Reputation: 3531

You can access the controls and iterate through them. Have to pick an iterable naming scheme.

Me.Controls("txt" & intloop)

Upvotes: 3

Related Questions