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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling code in textfield (validate) 1

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
0
0
US
I have a text field where a user puts in a numeric figure and after they tab out of it, the text field will run some calculation code that I setup.

However, If a user goes back and clears the field and then tabs out of it, the code will still run.

How can I set it up so that if a user clears the field and decides to move on to the next field, it will not run the code?

I guess I could force the user to put something in the field as it is required, but I wanted to know if there was a way to get around it if they decided to clear the field and click into another field for the moment.
 
Use the lostfocus event of the textbox to check its not left empty.

If trim(Text1.text)= "" then
' Dont run the code, display messabox or whatever
else
' Run the code and leave
end if

Only a first off suggestion before heading out for the day
 
I ended up making the first textbox a required field as they HAVE to enter in a figure in that field before they can move on to any other field on the form.

thanks for the info though, i can use it for future reference.
 
You are better off using the Validate event. It fires after the lost focus event and you can cancel it (Cancel variable) and return the focus to the same text box if your validation code comes up false.

Also with the Trim function use the Trim$ variation instead. The former version converts your text box string to a variant and then returns the variant. This unnecessary extra step uses resources and takes longer.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top