First the easy one, how to split "Input_99"
I was going to use MID() after it got to where it was sent to. That
was going to be another problem since the code wont know how many
digits are in the number portion of the name,
You don't need to know how many digits
s1 = "Input_"
s2 = Mid$("Input_99", 7, 5)
num = Val(s2)
This assumes that the length of the left portion is always 6. The "5" is an
arbitrary number that will be at least the number of digits, ie length of
digits. As it seems unlikely you will have more than 999 textboxes you could
change the "5" to "3". If you might have a name like say "Input_12moretext"
use the Val() function.
It is part of a trio of events for each control (Change, Enter and
Exit).
The Withevents example I posted shows the Change event working for all your
textboxes
' in the withevents class
Private Sub tbx_Change()
tbx.Parent.Caption = "TB-" & gID & ": " & tbx.Text
End Sub
The same demo shows how to process any textbox only by supplying its number
tbID = 99
arrTBoxes(tbID).TextBoxStuff nClr
Unfortunately though the Enter & Exit events, which you say you require, do
not work in a Withevents class. Indeed this is a limitation. Sometimes there
are ways of working round this, eg by detecting other events, can be done
but quite a lot of work. However with modern machines it might not be such a
big deal to write the 124 pairs of Enter/Exit events in the form (use Excel
to help write the repetitive code in cells). For other events I'd strongly
suggest the WithEvents class.
' userform
Private Sub TextBox1_Enter() ' similar
TBX_Enter TextBox1
End Sub
Private Sub TBX_Enter(tbx As MSForms.TextBox)
Dim pos As Long
If Not mbExitEvent Then
' assumes all texbox names include a "_"
' but if they are all "Input_" change pos+1 to 7
pos = InStr(tbx.Name, "_")
MsgBox "text box : " & Mid$(tbx.Name, pos + 1, 4)
End If
End Sub
If you want to disable the event, eg you are changing focus with code,
temporarily set the module level flag mbExitEvent, but don't forget to
reset to false when done (important, double check code to ensure no
accidental way for it not to get reset, error handling etc).
Dim mbExitEvent As Boolean ' top of form code
Private Sub CommandButton1_Click()
mbExitEvent = True
TextBox1.SetFocus
mbExitEvent = False
End Sub
Get back if it's still not coming together. I still don't quite follow all
of what you are doing but whatever it is I suspect it's doable!
Regards,
Peter T