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

Cancel button in a user form

Status
Not open for further replies.

rlman

Technical User
Aug 23, 2003
4
US
This is my first time using a forum. I hope i will be able to describe my problem.

I'm trying to create a user form with a textbox, ok button and cancel button. I would like to run my code when the ok button or enter is used in the textbox, then close the form.

I would like the cancel to work:
1. with nothing in the input box
2. after entering some text

I have tried using the afterupdate, beforeupdate and exit events. When something has been entered these procedures seem to run before my cancel procedure.

My problem seems to be that when I hit the cancel button after I enter text in the txtbox - the txtbox procedure must run first.

Also new to Vba.
Sorry to be so wordy.

Thanks
 
The textbox procedure has to run first most likely because you have a TextBox_Exit event. Try using the TextBox_Change event instead.

Besides, if the purpose of the UserForm is supposed to start after the OK button is pressed, you shouldn't really need any type of events for the TextBox.

P.S. You can use the Esc button to cancel out of a UserForm if you set the "Cancel" button's Cancel property to True.

Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Thanks Mike

I forgot to mention that I tried the change event. I couldn't figure out how to trigger the event when the enter key was pressed. The "=" worked when it was the first character and I couldn't figure out how to get the like operator to recognize the enter key.

My original thought is that a user may use either the enter or OK button after the data is entered to close the form. I currently have it woking without any textbox event, which is good enough for now.

The esc button hint is good to know - Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top