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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,693
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,203
Office Version
  1. 2016
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,296
Messages
5,635,364
Members
416,856
Latest member
silentir

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
Top