I'm making a mdi-style program where on a number of my child forms I need to trigger code whenever they leave a number of text boxes / combo boxes. The code a number of things and then passes the focus onto the next text box / combo box. When the form loads up a text box has focus by default. I want code to trigger when they leave focus from that text box with the EXCEPTION of two things. One being when you close the form (already have that completed) or if the form loses focus (for example, the user decides to open up another form in the menu). On the leave event of one of the text boxes I have the following:
If UserInitiatedClose = False Then
CodeToTriggerHere()
End If
I have this working so that if the user tries to close the form it does not trigger the code in the textbox leave event. I already tried the following without any luck:
If UserInitiatedClose = False or me.focus = false Then
CodeToTriggerHere()
End If
or
If UserInitiatedClose = False or me.focused = false Then
CodeToTriggerHere()
End If
or
If UserInitiatedClose = False or me.Activeform = false Then
CodeToTriggerHere()
End If
I do notice that there is a sub for 'lost focus' but there is no such thing as me.lostfocus. To slightly confuse matters is that whenever another form loads up a text box / combo box has focus that will trigger code if that text box loses its focus. The work around for this would simply to put the code to prevent it from happening in one text box / combo box into all of them.
To sum everything up:
Is it possible to trigger code when a text box / combo box loses it focus with the exception of when the User is closing down the form (I already have that coded successfully) OR when the user is going to a different form. Thanks in advance!
Any help would be greatly appreciated.
Start Free Trial