ktab
Well-known Member
- Joined
- Apr 21, 2005
- Messages
- 1,297
Hello,
This code is at UF initialize event:
And the following at class1 module:
The code handles keydown, keypress events with no problem. Also similar change events, and probably more.
I cannot figure out why it does not handle enter event.. What ever i may do. Unbelievable or so obvious that i cannot see?
This code is at UF initialize event:
Code:
Option Explicit
Dim TextBoxes() As New Class1
Dim ComboBoxes() As New Class1
Private Sub UserForm_Initialize()
Dim TCount As Long, CCount As Long, c As Control
TCount = 0
CCount = 0
'Set TabIndexCollection = New Collection
For Each c In Me.Controls
' TabIndexCollection.Add c, CStr(c.TabIndex)
If TypeOf c Is MSForms.TextBox Then
TCount = TCount + 1
ReDim Preserve TextBoxes(1 To TCount)
Set TextBoxes(TCount).TextBoxGroup = c
End If
If TypeOf c Is MSForms.ComboBox Then
CCount = CCount + 1
ReDim Preserve ComboBoxes(1 To CCount)
Set ComboBoxes(CCount).ComboBoxGroup = c
End If
Next c
End Sub
And the following at class1 module:
Code:
Public WithEvents TextBoxGroup As MSForms.TextBox
Public WithEvents ComboBoxGroup As MSForms.ComboBox
Sub ComboBoxGroup_Enter()
MsgBox "Hello from " & ComboBoxGroup.Name
Exit Sub
If ComboBoxGroup.Name Like "TN*" Then
frmTask.StatusBar1.Panels(1).Text = "NUM"
Else: frmTask.StatusBar1.Panels(1).Text = ""
End If
End Sub
Sub TextBoxGroup_Enter()
MsgBox "Hello from " & TextBoxGroup.Name
Exit Sub
If TextBoxGroup.Name Like "TN*" Then
frmTask.StatusBar1.Panels(2).Text = "NUM"
Else: frmTask.StatusBar1.Panels(2).Text = ""
End If
End Sub
Sub TextBoxGroup_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim i As Integer
If TextBoxGroup.Name Like "TN*" Then
nonNumberEntered = False
If KeyCode < 49 Or KeyCode > 57 Then
If KeyCode < 96 Or KeyCode > 105 Then
If KeyCode <> 8 Then
If KeyCode <> 111 Then
If KeyCode <> 191 Then
nonNumberEntered = True
End If
End If
End If
End If
End If
End If
end sub
Sub TextBoxGroup_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If nonNumberEntered = True Then KeyAscii = 0
End Sub
The code handles keydown, keypress events with no problem. Also similar change events, and probably more.
I cannot figure out why it does not handle enter event.. What ever i may do. Unbelievable or so obvious that i cannot see?