Code cycles through specific range of textboxes

  • First off, apologies for the Title - it should have read "Code cycles through. . . ", but can't see how to correct it!


    Hope someone can solve this for me.


    User Form has various "blocs" of Textboxes, which have different formats.


    I want a Code that says for Textbox numbers a to b, do this, and for Textbox numbers x to y do something else.


    I have tried three approaches and none of them work:



    All solutions accepted gratefully


    Ochimus

  • Re: Cide cycltes through specific range of textboxes


    You could use something like

    Code
    Dim tb As Object
    Dim counter As Integer
    For Each tb In Me.Controls
        counter = counter + 1
        If tb.Name = "TextBox" & CStr(counter) Then
            tb.Text = "test"
        End If
    Next tb
    End Sub


    I fixed the thread title for you.

    Regards
    [SIZE=3]Anthony
    [/SIZE]&WCF_AMPERSAND[SIZE=3]
    [/SIZE]&WCF_AMPERSAND&WCF_AMPERSAND&WCF_AMPERSAND[SIZE=2]You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.[/SIZE]




  • Re: Cide cycltes through specific range of textboxes


    Smu,


    Many thanks for amending the title.


    Unfortunately your approach "ain't hackin' it" because it goes through ALL the Textboxes.


    As I explained, I need something that works just on a specific bloc of Textboxes - in this example between Textbox3 to Textbox145 - to make them a Zero and format the box to two decimal places.


    Because another bloc - say Textboxes 206 - 229 will be percentages, or currency, or whatever.


    Ochimus

  • Re: Code cycles through specific range of textboxes


    It ""ain't hackin' it" because I gave you a generic method to iterate through textbox controls - you need to extrapolate from the generic and apply some programming logic to come up with a specific solution. Perhaps this will stimulate some ideas on the required implementation


    Regards
    [SIZE=3]Anthony
    [/SIZE]&WCF_AMPERSAND[SIZE=3]
    [/SIZE]&WCF_AMPERSAND&WCF_AMPERSAND&WCF_AMPERSAND[SIZE=2]You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.[/SIZE]




  • Re: Code cycles through specific range of textboxes


    Hi
    you could use the control tag value


    Worth a look at Ozgrid Free userform control lesson

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!