![]() |
Userforms
Hello,
I have a form with two frames on it. Each frame has a few controls. In the exit event of the controls I reformat the text to correct user entry errors. The problem I have is that when a user tabs out of the last control on a form the exit event does not fire until the user tabs back into the frame. Is there a way around this? And second... In one exit event I verify the integrety of the data and if incorect I set the focus back to the control but this does not seem to work. Can you not set focus in the exit event? Thanks, Ernst. |
Userforms
"Ernst Guckel" wrote:
The problem I have is that when a user tabs out of the last control on a form the exit event does not fire until the user tabs back into the frame. Is there a way around this? And second... In one exit event I verify the integrety of the data and if incorect I set the focus back to the control but this does not seem to work. Can you not set focus in the exit event? I'm not sure why this happens, but the exit event for the frame is firing instead of the exit for the last control. Then when you come back into the frame, it fires the last control's exit event. I don't know why it thinks you need it then. Maybe you could put the validation code for the last control in an independent method and call it when the frame exit fires. That will break, though, if you ever change the tab order or add another control. I hope someone else has a better solution. As for focus: if you set the Cancel variable to True inside the Exit Event handler, the control will not give up its focus. If you want to select the text in a textbox, I believe you have to do that with the .SelStart & ..SelLength properties. If (bad condition) Then Cancel = True With TextBox1 .SelStart = 0 .SelLength = Len(.Text) End With end if |
Userforms
"Ernst Guckel" wrote:
the exit event does not fire until the user tabs back into the frame. I found some more frame event peculiarities: Frame is consistent about intercepting exit events. If you Shift-Tab and leave the first control in the frame, that control's exit event won't fire. So if you try to do validation in the frame exit event, you have to test all the controls, I guess. If you click out of the frame, the last control with focus won't fire its exit event. I can't make sense of the enter event on the first control. Sometimes it fires, sometimes it doesn't. If I just tab straight through the form, it will fire on entry, but if I shift-Tab back to the first frame, then tab back in, it won't fire. Also, if instead of tabbing through controls, you click into the second control of the second frame while a control in the first frame has focus, the Enter event of the second frame's *first* control fires. That is, even if you leap-frog over the first control of the second frame, its enter event fires. |
Userforms
I found some more frame event peculiarities:
Frame is consistent about intercepting exit events. If you Shift-Tab and leave the first control in the frame, that control's exit event won't fire. So if you try to do validation in the frame exit event, you have to test all the controls, I guess. If you click out of the frame, the last control with focus won't fire its exit event. Exactly... I can recreate this time and time again but I just don't understand why it does it. But I worked around it through the frame exit event... Thanks for the help. |
All times are GMT +1. The time now is 07:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com