-
Hi. My name is Emidio, I living in Brazil and I have 29 year old.
I'm a programmer (19 year, 6 in VB) but I have a small question that leave me crazy. Is about Lostfocus event.
p.e: I need to write codes in GotFocus, Click and Lostfocus events of all objects in Form. Is about 20 objects (TextBox, ComboBox and MaskEditBox).
Some events is called automatic when a other event is called too.
If you have a Lostfocus, you have too a Gotfocus, Click (if combobox) and Lostfocus of second object.
The question is: How can I do to BREAK the next event when I don't want he?
Sorry by poor english, but in Brazil we talk portuguese... :)
-
Hi Emidio,
Put a TextBox object, name it as Text1 also a CommandButton object,name it as Command1
-------------------------------
Dim blnExec(2, 2) As Boolean
Option Explicit
Private Sub Switch(code As String, a As Integer, b As Integer)
Select Case code
Case "LostFocus"
blnExec(1, 1) = IIf(a = 1, True, False) 'text1
blnExec(2, 1) = IIf(b = 1, True, False) 'command1
Case "Click"
blnExec(1, 2) = IIf(a = 1, True, False) 'text1
blnExec(2, 2) = IIf(b = 1, True, False) 'command1
End Select
End Sub
Private Sub Command1_LostFocus()
' if command1_lostfocus then
' disable all lost focus events
If (blnExec(2, 1)) Then
MsgBox ("Command1 lost focus")
Call Switch("LostFocus", 0, 0)
End If
End Sub
Private Sub Form_Load()
Call Switch("LostFocus", 1, 1)
End Sub
Private Sub Text1_LostFocus()
' if text1_lostfocus then
' disable command1_lostfocus event
' enable text1_lostfocus event
If (blnExec(1, 1)) Then
MsgBox ("Text1 lost focus")
Call Switch("LostFocus", 1, 0)
End If
End Sub
'-- if command1 receives lost focus before text1, then
' it will prompt "Command1 lost focus" after that
' the lost focus flags (for both) will be set to false
'-- if text1 receives lost focus before command1, then
' it will prompt "Text1 lost focus" after that
' the lost focus flag for command1 will be set to false and
' the lost focus flag for text1 will be set to true and
--------------------
Those above is just a concept, you can write
it in a better way.
Does it help ?
Regards
Keiko