CLEARING TEXT BOXES

G

Guest

Does anyone have the VB code or know how you can get access to clear a text
box field ready for a new entry when clicked on.


EG Say you were searching for a student:

1) You enter a students name
2) the search is performed
3) you return to the form to search for a different student
4) the students name is still visible in the text box for the original search
5) you click in the text box to begin the second search
6) The text box clears........ (This is what I want to happen..how?)

Thanks for your help

Sarah
 
A

Alex White MCDBA MCSE

Have you tried the got focus event for the textbox with something like


if me.txtSearch.value <> "" then
me.txtSearch.value = ""
end if


maybe what you need is a variable to say you have searched setting that to
true, then only clearing when the variable = true setting the variable to
false on clearing
 
R

Rob Parker

In the GotFocus event of the textbox:
tboxSearchFor = ""

This will clear the contents of the textbox whenever it gains focus, after
having lost it. This will, naturally, include the situation you describe,
but it will also clear the box if a user enters something, moes elsewhere on
the form, then re-enters the textbox.

I'd be inclined to place the code after the line which calls your search
form (I'm assuming this is another form), so that when you return from the
search form the textbox is empty, rather than containing the string from the
previous search. To do that, put the code in your existing routine
immediately after the line which opens the search form. You'll want
something like:

...
DoCmd.OpenForm "frmMySearchForm" 'your existing command to open the
search form
tboxSearchFor = "" 'clear the textbox ready for next search
...

HTH,

Rob
 

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