Cycle through all controls on a form 
Author Message
 Cycle through all controls on a form

Is it possible to cycle through all controls on a form? I'd like to do sth
like:

For Each Ctrl In [Controls on current form]
     If {Ctrl is Label} Then    'or I can check it by: Ctrl.Tag = sth
         Ctrl.BackColor = PrefinedColor
     End If
Next

TIA
--------------------------------------
emsi
[no idea 4 sig]



Sun, 29 Aug 2004 15:19:29 GMT  
 Cycle through all controls on a form


Quote:
>Is it possible to cycle through all controls on a form? I'd like to do sth
>like:

>For Each Ctrl In [Controls on current form]
>     If {Ctrl is Label} Then    'or I can check it by: Ctrl.Tag = sth
>         Ctrl.BackColor = PrefinedColor
>     End If
>Next

>TIA
>--------------------------------------
>emsi
>[no idea 4 sig]

Try it like so....

For Each Ctrl In Me.Controls
     If TypeOf Ctrl Is Label Then
         Ctrl.BackColor = PrefinedColor
     End If
Next

If this code is running somewhere other than the current form, you
will need to change the "Me" reference to a reference to the desired
form.

HTH,
Bryan
____________________________________________________________
New Vision Software            "When the going gets weird,"
Bryan Stafford                   "the weird turn pro."

Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas



Sun, 29 Aug 2004 15:53:06 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help: For Loop to cycle through all forms controls

2. activex control and form life cycles

3. VB6+WORD form-letters cycling problem

4. cycle through form and add values to text boxes

5. Event cycle of forms?

6. Cycle through controls and Highlight some - Help?

7. User Control life cycle ***CONFUSED****

8. form!control vs form.control

9. Cycling Through Records in a Table

10. Cycle property in subforms

11. cycle through new mail only

12. Outlook Contacts - cycling through with Items Collection

 

 
Powered by phpBB® Forum Software