Clear text boxes

jpl458

Well-known member
Local time
Today, 02:37
Joined
Mar 30, 2012
Messages
1,218
Is there a way to clear all the dat entry text boxes on a form without having to address each one?
 
No, there is no Me.ClearAllTextBoxes(), but you can make one.

You can loop through all the controls of a form with by using Me. Controls, then you can use the .ControlType to see if its a acTextBox and if so you can then clear it.
 
Code:
sub ClearAllTextBoxes()
dim ctl as control
for each ctl in controls
   if Typename(ctl) = "TextBox" then ctl.value = ""
next
end sub
 
Code:
sub ClearAllTextBoxes()
dim ctl as control
for each ctl in controls
   if Typename(ctl) = "TextBox" then ctl.value = ""
next
end sub
How about Me.Requery. That seems to work.
 
In a bound form, you are unlikely to actually need to clear all the controls. Perhaps you do not understand how bound forms work. To enter a new record, you use the built in navigation bar at the bottom of a form to advance to the "new" record which will be empty.

OR, you could add a button using the wizard. Choose the new record option. That will advance to the new record automatically.

Also, Remember, Access takes it as a personal mission to save all data. Therefore, when you press the button to advance to the new record, no matter how you do this, Access will save the current record for you if it is dirty. You do not need to force Access to save the dirty record.

However, what you do need to do is to add validation code to the Form's BeforeUpdate event to ensure that you are not saving an empty record or a record where any of the fields have invalid values.
xxNewRecord.JPG
 

Users who are viewing this thread

Back
Top Bottom