Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have created some dynamic controls on my userform. I have also managed
(with the help of someone's posted code) how to add events to these controls at runtime by using class modules. The events seem to work well. However, for the textboxes, they work too well. To test the procedure, the routine now is just to open a msgbox (not the eventual purpose, but does make sure it's happening). I've put the code for the textbox below. My problem is that, for the textbox, EVERY single digit (or letter) entered into the textbox triggers the change event sub. So for example, if I want to enter 200 in the textbox, and then trigger the change event, what is currently happening is: I enter 2 - msgbox appears I enter 0 - msgbox appears I enter 0 - msgbox appears I sure that's not how nature and Microsoft intended it to be (well, I'm sure about nature). Can anyone suggest how I can remedy this so that the change event for a text box is only triggered once, either on leaving the changed cell, or when the full change in the textbox is completed. The same class module and routines for the combobox work perfectly. They have exactly the same syntax (except text = combo). Thanks for any suggestions! 'in the class module clsActiveTextBox Private WithEvents ActiveTextBox As msforms.TextBox 'this sets each TextBox control which is passed to it, as an element of the class array Sub Set_ControlArrayElement(ByVal cmb As msforms.TextBox) Set ActiveTextBox = cmb End Sub Private Sub ActiveTextBox_Change() MsgBox "You clicked " & ActiveTextBox.Name End Sub 'In the UserForm_Initialize sub Call CreateControls TextBox_ClassArrayInit 'see below Sub TextBox_ClassArrayInit() Dim CTL As msforms.Control Dim lngCtrl As Long Dim frm As msforms.UserForm Dim bIsTextB As Boolean Dim strPrefix As String Set frm = SettingsWindow.MultiPage1.Pages(0) For Each CTL In frm.Controls If TypeOf CTL Is msforms.TextBox Then lngCtrl = lngCtrl + 1 ReDim Preserve aryTextBox(lngCtrl) Set aryTextBox(lngCtrl) = New clsActiveTextBox 'call class method (function in the class module) which we made up aryTextBox(lngCtrl).Set_ControlArrayElement CTL End If Next End Sub |