Click to See Complete Forum and Search --> : structured control/field names


Linnet
June 29th, 2001, 09:57 AM
I have a number of tables & forms, in each of which some (but not all) of the field / control names are structured in some way, eg:
A1, A2, A3, A4, A5, B1, B2 .... D4, D5.
I have to perform an identical operating on each in turn, and would like to capitalise on their naming structure, e.g.:

dim counter1 as integer, counter2 as integer
for counter1 = 1 to 5 ' or do while, or whatever
for counter2 = 1 to 5
'do something to me!<counter1><counter2>
next
next




Can this be done, and what is the syntax to denote some or all of the field / control name with a variable?

Thanks, Linnet

Jean-Guy2000
June 29th, 2001, 10:03 AM
there are 2 ways of doing this. first of all you can create a control array by setting the index property for the controls on a form (like textbox)
and give all the textboxs the same name. Then you would refercance them by textbox(x).Text = "text"
OR
create a new project
create 3 textboxs in the form
copy this code in
Private Sub Form_Load()
Dim MyTextBox As TextBox

For Each MyTextBox In Me
MyTextBox.Text = "Hi there"
Next MyTextBox
End Sub

Jean-Guy

Clearcode
June 29th, 2001, 10:03 AM
You can return a control from the Controls collection by name thus if you have ten textboxes called Text1 to Text10 you could cpitalise the text in them thus:


Dim nItem as Integer

for nItem = 1 to 10
me.Controls("Text" & nItem).Text = UCase(me.Controls("Text" & nItem).Text)
next nItem




HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com