Clearing Text Boxes

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?
 
G

Guest

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
 
P

Pat Hartman\(MVP\)

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.
 
G

Guest

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
 
G

Guest

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top