-
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.
-
This should work:
Code:
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
-
this also works
Code:
Private Sub CommandButton1_Click()
Dim TB As TextBox
For Each TB In Me.Controls
TB.Text = ""
Next TB
End Sub
-
If you declare it as a TextBox you'll get an error. Declare it as a Control instead.
-
oh yeah, I tried parksie's code and got it confused with mine... oops.... :o