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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLEAR FORM OF ENTRIES WITH COMMAND BUTTON 2

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
Hi Everyone,

I have a form which has several text boxes where users can enter criteria for queries that are executed by clicking on command buttons. I would like to add some code that would clear out the entries made upon clicking the command button, so that they could start over with an empty screen.

What would be the easiest way to do that?

THANKS!!
 
Thanks but me.undo didn't work.
any other suggestions?
 
Code:
For Each Ctl In Me.Controls
  If Ctl.ControlType = acTextBox Then
    Me.Ctl.DefautValue = vbnullstring
  End If
Next Ctl
alternatively you can confine the loop to a section of the form: me.Detail.Controls

I also suggest you give the users a warning before their entries disappear.

Cheers, Bill
 
Sorry, but my earlier post should have read:

<code>
For Each Ctl In Me.Controls
If Ctl.ControlType = acTextBox Then
Me.Ctl.Value = vbnullstring
End If
Next Ctl
</code>

There was a typo on the control (ctl) property.

Bill
 
Thanks for your help, but VBA comes back and highlights the "ctl" in this line:
"Me.Ctl.Value = vbnullstring"
and says "not found".

What's missing?

Thanks?
 
Thanks for the help. This is what I got to work:

Private Sub Command4_Click()
Dim Ctl As Control
For Each Ctl In Me.Controls
If (Ctl.ControlType = acComboBox) Or (Ctl.ControlType = acTextBox) Then
Ctl.Value = Null
End If
Next Ctl
End Sub

THIS ALSO WORKS AND IS SIMPLER

Private Sub Command5_Click()
Dim Ctl As Control
On Error Resume Next
For Each Ctl In Me.Controls
Ctl.Value = Null
Next Ctl
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top