View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default TextBox_Change a little premature!

Unfortunately, application events do not support the TextBox Exit event. You
could always trap the KeyDown event and check it for 13 or 9 (Enter or Tab),
and output your message box then

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Post Tenebras Lux" wrote in
message ...
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