Results 1 to 5 of 5

Thread: For Each....Next --- help, please

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2000
    Posts
    16
    I'm trying to loop thru' all of the textboxes on a form to set their text properties to "". However, I keep getting an object error. I've checked the online help and searched this site yet I still can't seem to find the problem. Can you please show me an example, including the Dim Statements, of using For Each...Next. FYI, programming in Word 2000 vba.

    Thank you.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    This should work:
    Code:
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            ctl.Text = ""
        End If
    Next
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    this also works


    Code:
    Private Sub CommandButton1_Click()
        Dim TB As TextBox
    
        For Each TB In Me.Controls
            TB.Text = ""
        Next TB
    End Sub

  4. #4
    Guest
    If you declare it as a TextBox you'll get an error. Declare it as a Control instead.

  5. #5
    Guest
    oh yeah, I tried parksie's code and got it confused with mine... oops....


Posting Permissions

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



Click Here to Expand Forum to Full Width