Enabling multiple option buttons in userform

Enabling multiple option buttons in userform

Post by D. Bur » Fri, 04 Jul 2003 00:03:22



Instead of enabling option buttons using the following code, I'd like
to make it more efficient.  Here's what works:

If UserForm1.cbAMPG = True Then

    With UserForm1
        .obAftBase.Enabled = False
        .obAftmkt.Enabled = False
        .obBase.Enabled = False
        .obDetail.Enabled = False
        .obTotal.Enabled = False
        .obSelShts.Enabled = False
        .obAllShts.Enabled = False
        .ckAsset.Enabled = False
        .ckCost.Enabled = False
    End With

End If

I tried using something like the following but the Control object
doesn't use the Enabled property even though the OptionButton object
does?

Dim ctrl As Control
    For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "OptionButton" Then
            ctrl.Value = False
        End If
    Next ctrl
End Sub

Any suggestions would be appreciated.  I tried dimensioning ctrl as an
OptionButton but then I get an error on the For Each line.

Thanks - DB

 
 
 

Enabling multiple option buttons in userform

Post by Tushar Meht » Fri, 04 Jul 2003 22:02:52


That's interesting.  Even though the VBE Intellisense capability
doesn't list the Enabled property, it still works.  The foll. tested OK
with XL2002:

Private Sub UserForm_Click()
    Dim ctrl As Control
    For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "OptionButton" Then
            ctrl.Enabled = Not ctrl.Enabled
            End If
        Next ctrl
    End Sub

Of course, whether the above is more efficient than just enumerating
the list somewhere is debatable. ;-)

--
Regards,

Tushar Mehta (www.tushar-mehta.com) MS MVP -- Excel



Quote:> Instead of enabling option buttons using the following code, I'd like
> to make it more efficient.  Here's what works:

> If UserForm1.cbAMPG = True Then

>     With UserForm1
>         .obAftBase.Enabled = False
>         .obAftmkt.Enabled = False
>         .obBase.Enabled = False
>         .obDetail.Enabled = False
>         .obTotal.Enabled = False
>         .obSelShts.Enabled = False
>         .obAllShts.Enabled = False
>         .ckAsset.Enabled = False
>         .ckCost.Enabled = False
>     End With

> End If

> I tried using something like the following but the Control object
> doesn't use the Enabled property even though the OptionButton object
> does?

> Dim ctrl As Control
>     For Each ctrl In UserForm1.Controls
>         If TypeName(ctrl) = "OptionButton" Then
>             ctrl.Value = False
>         End If
>     Next ctrl
> End Sub

> Any suggestions would be appreciated.  I tried dimensioning ctrl as an
> OptionButton but then I get an error on the For Each line.

> Thanks - DB


 
 
 

1. Adding command buttons to a userform at run-time and getting them to work

I have a userform that adds a variable number of command buttons to the form
based on information from a worksheet.  That part works fine.  The problem
comes when I press one of the added buttons...nothing happens.  I have
subroutines for up to six added buttons entitled Private Sub
TButton1_Click(), TButton2_Click(), etc under the Userform module.  What do
I need to do to get the added command buttons to work?  Here is the code
that adds the command buttons (running under Private Sub
Userform_Initialize() ):

For Clocker = 0 To ((FieldsD * 10) - 1) Step 10
    Set Cmd = Controls.Add("Forms.CommandButton.1")
        With Cmd
          .Left = 90
          .Top = 312 + 65 * Clocker / 10
          .Width = 36
          .Height = 15
          Dim Name As String
          Name = "TButton" & Clocker + 1
          .Name = Name
          .Caption = "SEND"
          .Font.Size = 5
    End With
Next Clocker

Help would be greatly appreciated.  Thanks!

2. HELP... Oracle SQL Date question...

3. Back button on a userform

4. RPG/400 Development in Ontario, Canada

5. XL userform: show with auto_open, buttons don't work

6. Bug in Compudyne 75mz Pentiums?

7. Plug ins enable/disable

8. Gnu C for Philips XA-G49 80C51

9. Using spin button with textbox in userform

10. extract figure from one userform to other userform

11. XL 97 VBA Question...Address multiple objects on a UserForm

12. How to enable the Dolby Digital & DTS audio options

13. enabling/disabling command buttons on toolbars