Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identifing Textboxes (Office XP)

    Can anyone help? I am cycling through the controls in a userform and want to identify the textboxes only rather than all the other controls. Is this available in VBA as Help isn't being that helpful !!!

    Many thanks
    Jack

  2. #2
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Thanks M

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Hi, welcome to Woodies!

    Well, if you are in MS ACCESS you can do the following code:

    Dim cn As Control
    Dim f As Form
    Set f = formname
    For Each cn In f.Controls
    If cn.ControlType = acTextBox Then
    > code for textboxes here
    End If
    Next cn

    or in VBA or Excel you could do

    Dim c As Control
    For Each c In Form1.Controls
    If TypeName© = "Textbox" Then
    .. code here
    End If
    Next


    Is this the kind of thing you need?

    Are you wanting to do this in VB or in Office VBA, if so, which Application? eg access, word, excel..
    Thanks,

    pmatz

  4. #4
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Hi Jack, no problem.

    If you run this code

    Dim c As Control
    For Each c In UserForm1.Controls
    Debug.Print TypeName©
    Next

    it should print out to the debug window all the names of the control types you have on your form. You have to replace userform1 with the name of your form. To open the debug window do CTRL+G.

    Then you can test for textbox with an if statement.
    Thanks,

    pmatz

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

    Re: Identifing Textboxes (Office XP)

    You can also use TypeOf:

    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
    ' your code goes here
    End If
    Next ctl
    Set ctl = Nothing

    Note the use of Is in the If statement.

  6. #6
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Morning M

  7. #7
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Hans

    You are a star <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    Thanks for your help.

    Regards
    Jackie

  8. #8
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    Hmmm... <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Did you try Hans' suggestion too? Any joy?

    Are you running the code from a command button on the userform? If so you could try

    for each c in me.controls

    Can you attach the word document for me to have a quick look at it? Take out all sensitive info though <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Thanks,

    pmatz

  9. #9
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    M

  10. #10
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identifing Textboxes (Office XP)

    No Probs! Hans is a star, I have learnt much from the knwoledgable one!

    Cheers Jackie, glad its sorted <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Thanks,

    pmatz

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

    Re: Identifing Textboxes (Office XP)

    This version of the code by M

Posting Permissions

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