S
Stephen Newman
I am using a class I found here that works very well for my needs. Now
I would like to reference and change the caption of a label of the
same name (number) as the text box.
The Class:
Public WithEvents txtBox As MSForms.TextBox, CtlNum As String
Public laBl As String
Private Sub Class_Terminate()
Set txtBox = Nothing
End Sub
Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 46, 48 To 57
If Right(txtBox, 2) = ".5" Then KeyAscii = 0
If KeyAscii = 46 Then SendKeys ("5")
''' These are all number. No Problem
Case Else
''' Some other kind of character. Beep and cancel it.
Beep
KeyAscii = 0
End Select
SetLabel
End Sub
Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 8 Then txtBox.Value = ""
End Sub
Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) <> ".5" Then txtBox
= Null
If Len(txtBox.Text) > 4 Then txtBox = Null
End Sub
'Here's where it fails.
Sub SetLabel()
'This returns the TextBox number
CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name))
laBl = "Label" & 3
MsgBox UserForm.Name.laBl.Caption
End Sub
All help will be appreciated.
Thank you.
I would like to reference and change the caption of a label of the
same name (number) as the text box.
The Class:
Public WithEvents txtBox As MSForms.TextBox, CtlNum As String
Public laBl As String
Private Sub Class_Terminate()
Set txtBox = Nothing
End Sub
Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 46, 48 To 57
If Right(txtBox, 2) = ".5" Then KeyAscii = 0
If KeyAscii = 46 Then SendKeys ("5")
''' These are all number. No Problem
Case Else
''' Some other kind of character. Beep and cancel it.
Beep
KeyAscii = 0
End Select
SetLabel
End Sub
Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 8 Then txtBox.Value = ""
End Sub
Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) <> ".5" Then txtBox
= Null
If Len(txtBox.Text) > 4 Then txtBox = Null
End Sub
'Here's where it fails.
Sub SetLabel()
'This returns the TextBox number
CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name))
laBl = "Label" & 3
MsgBox UserForm.Name.laBl.Caption
End Sub
All help will be appreciated.
Thank you.