views:

24

answers:

1

i have some comboboxes and some textboxes on a form

i would like to clear all of them with one line of code. is that possible?

something like all_controls.text=""

+3  A: 

Not with one line of code. You will have to walk through all of the controls with a loop.

Dim ctl As Control
For Each ctl In Me.Controls
    If (ctl.ControlType = acTextBox) Then
        ctl.Value = Null
    End If
Next ctl

http://www.tek-tips.com/faqs.cfm?fid=5010

Robert Harvey
If you're doing this often, say in an unbound form that is used in a query-by-form interface, it's vastly faster to assign the controls you're clearing to a custom collection in the OnLoad event of the form, and then walk that collection instead of the entire controls collection.
David-W-Fenton