Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox.text Set all of them on a form

Status
Not open for further replies.

thegameoflife

Programmer
Dec 5, 2001
206
US
what is the best way to set all my text boxes Text value = "" on open??
 
This code will do it as long as your fields are unbound.

Dim i As Integer

For i = 0 To Me.Controls.Count - 1
If (Me.Controls(i).ControlType = acTextBox) Then
Me.Controls(i).Value = vbNullString
End If
Next i
 
FancyPrarie,

Why do you say "as long as your fields are unbound"?

I just did this as a test:
Private Sub Command8_Click()
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl = Null
End If
Next ctl

End Sub


which uses only slightly differnt methodology, and it works fine. It's true that indexes could mess you up here, but other than that, this works just fine with bound controls, and I would assume yours does too.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top