AfterUpdate Event Handling for a textbox class

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:
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:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Please take a minute to read the forum rules, especially regarding cross-posting, and then update your post to include links to any and all cross-posts in other forums. Thanks.
 
Upvote 0
Class modules do not expose some events including the AfterUpdate event.

see if you can adapt the following workarounds to your specific needs :

Take a look at this tread (post#38)

also this thread

or for a more robust and elegant solution look at this thread
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top