Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 281
johnny93 Avatar asked Sep 17 '25 21:09

johnny93


2 Answers

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

Me.Controls("txt" & intloop)
like image 187
serakfalcon Avatar answered Sep 20 '25 14:09

serakfalcon


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.

like image 38
VBlades Avatar answered Sep 20 '25 14:09

VBlades