kpasa
Board Regular
- Joined
- Nov 20, 2015
- Messages
- 82
I have a class that groups several textboxes in a userform for event handling. Here is the class:
And here is the code inside the userform:
I have a custom EnableEvents boolean so I can manually enable and disable the event firing when i need to (since Application.EnableEvents doesnt work in this situation).
The above code works great, except the change event happens every single time I type a character. In the past, I've used the AfterUpdate event on each individual textbox control, but it will not work on this class. Any ideas on how i can catch the event when the whole field is updated (afterupdate, exit, etc)?
Code:
Private WithEvents MyTextBox As MSForms.TextBoxPublic EnableEvents As Boolean
Public Property Set Control(tb As MSForms.TextBox)
Set MyTextBox = tb
End Property
Private Sub MyTextBox_Change()
If EnableEvents = True Then
'code for triggered event
Else
'No Trigger
End If
End Sub
And here is the code inside the userform:
Code:
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim obj As clsTextBox
Set tbCollection = New Collection
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
Set obj = New clsTextBox
Set obj.Control = ctrl
tbCollection.Add obj
End If
Next ctrl
Set obj = Nothing
EnableEvents = True
End Sub
I have a custom EnableEvents boolean so I can manually enable and disable the event firing when i need to (since Application.EnableEvents doesnt work in this situation).
The above code works great, except the change event happens every single time I type a character. In the past, I've used the AfterUpdate event on each individual textbox control, but it will not work on this class. Any ideas on how i can catch the event when the whole field is updated (afterupdate, exit, etc)?
Last edited: