reducing redundant code

  • Thread starter Thread starter Trent
  • Start date Start date
T

Trent

Hi I am having trouble working out the best way to have an
array that will reference directly to about 40 text boxes,
so I don't have to repeat very similar code just because
the text box goes from textbox1 to textbox2 (or textbox3
etc). Also I have to set the focus everytime I need to
change the value in a text box....

What I want to do is have a loop that will insert values
into these 40 or so textboxes from an array, just in a
sequential order (hopefully to make it easier) and if
there is an easier way than setting the focus onto a text
box everytime I want to change the value, any help would
be great,

Thanks.
 
Use the Controls collection of the form to reference each control in turn.

The is no need to SetFocus to the control to change its Value. You do need
to SetFocus if you are changing the Text property instead of Value: although
that is the typical approach in VB, it is not the right approach in Access.

Example:

Dim strControl As String
Dim i As Integer

For i = 1 to 40
strControl = "textbox" & i
Me.Controls(strControl).Value = MyArray(i)
Next
 
Back
Top