Results 1 to 15 of 15
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Userform Control Type (Word 97SR2)

    The debug watch window in the IDE shows a control's type if you add a control (like a text box) to the watch list.

    How can I access the control's type property in code? I want to test the control's type and take action accordingly.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Kevin,

    Something like:
    <pre>Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is Calendar Then
    Debug.Print "calendar"
    ElseIf TypeOf ctl Is TextBox Then
    Debug.Print "textbox"
    End If
    Next
    </pre>

    Klunky, particularly if you have lots of types you want to access. Intellisense gives you the options after typing the "is".
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Userform Control Type (Word 97SR2)

    Another method is to use the ControlType property of the control, which gives you a bit more flexibility than TypeOf since you aren't stuck with an If-End If:

    <pre>For Each ctl in frm.Controls

    Select Case ctl.ControlType
    Case acTextBox
    ...
    Case acComboBox
    ...

    End Select
    Next ctl</pre>

    Charlotte

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Except for commandbars, Word does not have a type property for controls.

    Must be another exclusive Access feature.

    But that would be nice if it did!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Geoff,

    I think the TypeOf "statement" will do the trick. Thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Userform Control Type (Word 97SR2)

    ControlType is VB/VBA, not Access at all.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Charlotte,

    With this code<pre>For Each ctl In Me.Controls
    MsgBox ctl.controltype
    Next ctl</pre>

    I get "Object does not support this property or method" in both VB and VBA. Am I doing something wrong?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Userform Control Type (Word 97SR2)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> No, Geoff. It's just that my New Year's resolution to make at least one glaring blunder a day to keep me humble kicked in on this thread. Kevin is absolutely right that ControlType is an Access property. I must have been thinking of something else obscure that belongs to VB/VBA when I wrote that.
    Charlotte

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    I don't see controltype as a property for userform controls. What am I missing?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Sorry for posting below. I had not read your post above.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Gosh darn. I thought I was going to learn something really useful there.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Kevin is anything like following of use ?<pre>
    For Each ctrl In Me.Controls
    If TypeName(ctrl) = "TextBox" Then
    'Do whatever
    End If
    Next</pre>

    For differing control types I suppose a select case might apply.

    Andrew

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform Control Type (Word 97SR2)

    Yes, that's very good. But I've already coded up using If.. Typeof.. Is... which does the same thing, so I guess I'll leave well enough (home) alone for now. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Userform Control Type (Word 97SR2)

    My response to Geoff. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Charlotte

  15. #15
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Userform Control Type (Word 97SR2)

    But you did, Geoff. You learned that I'm just as capable of foot-in-mouth disease as anybody else who hangs out in the Lounge ... in spite of my magnificance! <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>
    Charlotte

Posting Permissions

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