Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Control groups (WinXP/O2003)

    Hi,

    Is there in VBA a property similar to VB6's "TypeOf " with which you can taste the flavour of a control.
    Can't seem to find a property that uniquely identifies the controls type

    Eg. got a form with a bunch of controls. Created a group of option buttons among other controls on the form.

    Now I would like to
    1. go directly to the group without having to loop through all the other controls or
    2. loop through the collection and simply taste on the "TypeOf" (if it's an optionbutton and groupname="MyGrp" then....)

    Been looking at MSDN, office help and two reference books, but they don't really get around this issue for Office.

    Any suggestions?
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Control groups (WinXP/O2003)

    You can use TypeName. It returns a string such as "TextBox", "OptionButton", "Label".

    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeName(ctl) = "OptionButton" Then
    If ctl.GroupName = "MyGrp" Then
    ...
    End If
    End If
    Next ctl

    Note that you must use nested If ... End If blocks, for GroupName is not valid for other controls than option buttons.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control groups (WinXP/O2003)

    Sure you can:

    Dim oObject as Object
    '.......
    If TypeOf oObject Is msforms.OptionButton Then
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Control groups (WinXP/O2003)

    So obvious - once you know it...

    Thanks a lot both of you.
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •