Announcement

Collapse
No announcement yet.

Loop through text boxes on User Form

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop through text boxes on User Form



    Here's the scenario:

    I have a user form with 15 text boxes named form1.text1, .text2, .text3 etc.
    Values will be transferred to these text boxes, but the number of text boxes that values will be transferred to will vary. I need to create a loop that will increment the name of the text box by 1 each time the loop is run.

    I've tried every imaginable form of set statement, variable, etc. and get different kinds of error statements......"Type mismatch, With stetment not set, etc."

    Here's the loop I need:

    For trsf = 1 to num (a variable indicating the #of times loop will run) step 1
    form1.text1.value = first value
    num = num - 1
    next trsf

    The next time the loop runs, the text box name should be text1+1 or text2, etc., etc. etc., and I can't seem to figure out how to change the name so that it is recognizable as an object in the form.

    Any help would be greatly appreciated.

    Thanks in advance

    Ted.............

  • #2
    Re: Loop through text boxes on User Form

    Hi,

    Something like this,
    Code:
        Dim trsf As Integer
        
        For trsf = 1 To 3
            Me.Controls("Textbox" & trsf).Text = "Value " & trsf
        Next trsf

    Cheers
    Andy

    Comment


    • #3


      Re: Loop through text boxes on User Form

      THANK YOU ANDY !!!

      Once again you have saved my bacon. I had tried the me.controls statement but forgot to use the brackets. Simple solution and works great.

      Hmmmmmmmmm, now if only I could figure out how to mark this post as solved.

      Ted........

      Comment

      Working...
      X