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!

Clearing Input Text Boxes on Forms 2

Status
Not open for further replies.

OB1too

Technical User
Jun 7, 2000
37
AU
I have a form that has 2 Text Boxes for input and a series of Command Buttons for running queries based on that input. However when the query is closed down, the data remains in the Text Boxes. How do I clear them automatically on closure of the queries?
Thanks
 
You can't detect the closing of the queries from within the form--but you should be able to clear the text boxes right after you've opened the queries and passed the data to them.

But if the queries are grabbing the values from the text boxes (using Forms![form name]![text box name]), you won't really know when the data's been grabbed, will you? I'd suggest that you just clear them 1 or 2 seconds after the queries have been opened. That should be enough time for the queries to get their data.

To get this to happen after 1 or 2 seconds, modify your command button Click events so that after they open a query, they set Me.TimerInterval to 1000 (or 2000 for 2 seconds). Then create a Form_Timer event procedure as follows:
Me.TimerInterval = 0
Me.Text1 = ""
Me.Text2 = ""

I think that will do it. Rick Sprague
 
Many thanks Rick. Shall give it a try. You reply also gave me some other clues on using SetValue in the macro event associated with On Click.
Thanks again, much appreciated
 
As the last line in your command button's code, you might try:

Me!txtFindSomeone = Null

...substituting the name of your text box for txtFindSomeone.


 
Do you really want to clear the box? Or do you just want to make it easy for the next data entry. Try this and see if you like it:
Private Sub field_GotFocus()
Me!field.SelLength = X ' X is an integer larger than the
' longest possible data entry
End Sub

 
Thanks for all the suggestions. As I've set the OnClick to run a Macro, all I did was to append 2 SetValue instructions to the macro after the OpenQuery instruction.
The SetValue resets the Input Boxes on the original form back to "" and (so far ) that seems to work fine.
Thanks again
 
Hey OB1too, I had the same problem and did what you suggested and it works just fine and no programming. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top