Command Buttons


Posted by JohnG on February 08, 2002 12:07 PM

Can anyone think of a way using a for loop to check command buttons on a user form to see what the caption says rather than doing each one in turn. There doesnt seem to be an index I can use.

Posted by DK on February 08, 2002 12:35 PM

Yep,

Dim ctl As Control

For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
Debug.Print ctl.Caption
End If
Next

HTH,
D

Posted by Mark O'Brien on February 08, 2002 12:41 PM

This should do it:

Dim ctrl As Control

For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton Then
MsgBox ctrl.Caption
End If
Next



Posted by JohnG on February 08, 2002 12:42 PM