Clearing Text Boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I clear text boxes on a form when I select a different record? I have
some text boxes that are used as calculations on a form that are populated by
the users. When they select a different record I want these fields to be
cleared of the data that was entered from the last user. I have a combo box
that I use to select the record so I guess I would put some sort of code
behind that field that clears all the fields on the form. How would I do this?
 
Hi,
I assume that those fields are unbound since they are calculations and
calculations should NOT be stored in tables.
You could try some code like this:

Dim ctl As Control

On Error Resume Next
For Each ctl In Form.Controls
If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox) And ctl.Tag
= "Validate" Then
ctl.Value = Null
Next ctl

Now use the tag property of the controls you want to clear and type in
Validate.
HTH
Good luck
 
The suggested code should go into the Current event of the form. That way
it will run whenever a new record is displayed regardless of the method used
to navigate to that record.
 
Thanks! I will give it a try!

freakazeud said:
Hi,
I assume that those fields are unbound since they are calculations and
calculations should NOT be stored in tables.
You could try some code like this:

Dim ctl As Control

On Error Resume Next
For Each ctl In Form.Controls
If (ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox) And ctl.Tag
= "Validate" Then
ctl.Value = Null
Next ctl

Now use the tag property of the controls you want to clear and type in
Validate.
HTH
Good luck
 
Actually it's not working. I'm getting error messages that say "You can't
assign a value to this object". Any idea what this means?
 
Back
Top