J
JB
OK, this was my setup/problem. I had a form with initially 1 textbox
and a cancel button enabled. If I entered any text into the text box
and then clicked on the cancel button or hit tab the validation event
would fire. If a user entered tab I wanted to go ahead and
validate...if they clicked on Cancel, no matter what they had already
entered into the textbox, I wanted to Cancel and close.
My solution:
I added another button to my form and made it size 0,0 and made sure
the tab order was set with this basically hidden control to come
before the cancel button.
I then in my validating code (which was handling multiple textbox
validations) added the following two checks:
1) I then checked Me.ActiveControl.Name to see if it was equal to
btnCancel. If it was then I just put focus on the cancel button and
exited the sub. (This is because this was the only control outside of
the sort of hidden control that the user could have clicked on).
2) If current textbox was empty I assumed user wanted to cancel and
just placed focus on the cancel button and exited the sub
Without having the extra hidden control to catch the tab the
Me.ActiveControl.Name would always be equal to btnCancel and
validation would never occur!
If someone has a better approach (without excluding the validating
event) please let me know...this was driving me crazy.
The only thing I settled on and did NOT resolve was when a user was
first on the first textbox if they did not enter anything and then
they hit the escape key it would close the form...but if they had
entered any text into the textbox then tried to hit escape validation
would occur.
JB
and a cancel button enabled. If I entered any text into the text box
and then clicked on the cancel button or hit tab the validation event
would fire. If a user entered tab I wanted to go ahead and
validate...if they clicked on Cancel, no matter what they had already
entered into the textbox, I wanted to Cancel and close.
My solution:
I added another button to my form and made it size 0,0 and made sure
the tab order was set with this basically hidden control to come
before the cancel button.
I then in my validating code (which was handling multiple textbox
validations) added the following two checks:
1) I then checked Me.ActiveControl.Name to see if it was equal to
btnCancel. If it was then I just put focus on the cancel button and
exited the sub. (This is because this was the only control outside of
the sort of hidden control that the user could have clicked on).
2) If current textbox was empty I assumed user wanted to cancel and
just placed focus on the cancel button and exited the sub
Without having the extra hidden control to catch the tab the
Me.ActiveControl.Name would always be equal to btnCancel and
validation would never occur!
If someone has a better approach (without excluding the validating
event) please let me know...this was driving me crazy.
The only thing I settled on and did NOT resolve was when a user was
first on the first textbox if they did not enter anything and then
they hit the escape key it would close the form...but if they had
entered any text into the textbox then tried to hit escape validation
would occur.
JB