PDA

View Full Version : Solved: (Strange?) TextBox Exit Sub Behaviour



shrivallabha
02-26-2011, 12:39 AM
I just came across strange (maybe it is not strange but I do not know) behaviour of TextBox Exit Subroutine. I am attaching the sample sheet to convey my expressions if they don't (by what I have written here). Here it is:
I)There are "three grouped items" and three groups on the userform. Press the commandbutton1.
I) Each TextBox is associated with Exit Sub.
II) When a user keys in data and presses TAB to exit then event gets triggered or it should.

Now to the problem:
In the first group ID3 is the last item in the group. When I press TAB the event gets fired as I have added another textbox (with tabindex 3). This blank textbox is of no consequence except to fire the event for ID3.

I have created the problem at ID6, ID9. The event doesn't get fired at these points.

My Questions:
1. Why does the event not work at ID6, ID9 after hitting TAB button?
2. Is the grouping controls culprit?
3. Am I doing something incorrect?
4. Or Excel installed has some problems?

Kindly advice. Currently the 'Ugly' solution at group1 is working. I can always hide that textbox4. Please :help

mdmackillop
02-26-2011, 08:20 AM
The Frames seem to cause the issues. Delete Exits subs for textboxes 3,6 & 9 and try

Private Sub Frame1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "You typed in " & ID3.Value
End Sub

Private Sub Frame2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "You typed in " & ID6.Value
End Sub

Private Sub Frame3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "You typed in " & ID9.Value
End Sub

shrivallabha
02-26-2011, 08:42 AM
When I exit the userform, all the events run (textbox exit) when they are not of any use.

Thank you MD :hi: . You are always a good help. That solves it for me. Your solution is better on at least two counts:

1. I do not have to add any other (hidden textboxes) to make this work.
2. Secondly, I do not want any (pending) events to run after userform exit.

Maybe, this thread will serve as "DON'T" design your form like this.