A standard way of doing this is as follows: ...
You can make this kind of thing a common routine to be included in your bag of tricks, for use in any program. To make it more generally applicable, you can allow it to target specific controls. One simple way is to place something in their
.Tag property for it to recognise.
For example, if you pass your form to this sub, it will only hit those textboxes which have "/CLEARME" somewhere in their tag.
- Public Sub ClearTextBoxes(frm As Form)
-
Dim ctrl As Control
-
For Each ctrl In frm.Controls
-
If TypeName(ctrl) = "TextBox" Then
-
If InStr(ctrl.Tag, "/CLEARME") Then
-
ctrl.Text = ""
-
End If
-
End If
-
Next ctrl
-
End Sub
To call it from a button on the form, for instance, you would just say