Clearing fields in a query using a "CLEAR" button

J

jimswinder

I want to create a button that clears all the fields in a form used for a
query?
Isn't there a Visual Basic DoCmd. that will do this for me? Also...isn't
there also a DoCmd. that will close the form? I can't seem to find them...
 
D

Dirk Goldgar

jimswinder said:
I want to create a button that clears all the fields in a form used
for a query?
Isn't there a Visual Basic DoCmd. that will do this for me?

If the form is unbound (i.e., no recordsource, just used for specifying
filter values for the query) then there's no single command, but you can
loop through the form's Controls collection.

Dim ctl As Access.Control

On Error Resume Next ' not all controls will have Value property

For Each ctl In Me.Controls
ctl.Value = Null
Next ctl
Also...isn't there also a DoCmd. that will close the form? I can't
seem to find them...

DoCmd.Close acForm, Me.Name

or

DoCmd.Close acForm, "NameOfYourForm"

depending on whether this code is running on the form you want to close
or not.
 
J

jimswinder

Dirk... Got ot to work first time!!!! Thanks for the help...your knowledge
was MOST helpful!!!!
 
Top