Chunk
08-24-2016, 06:53 AM
I have a userform that contains 14 textboxes (tb_one, tb_two, tb_three..........tb_fourteen).
The values that the user needs to enter into the text boxes are numbers. (no decimals, special characters or letters). I do not want a limit on the number of characters as well. After the user enters the numbers they will click on a "Calculate" button that will preform some simple math. For the math to happen, I need to ensure that only numbers are entered into the textboxes. Here is what I have been attempting (obviously, with no success):
Private Sub tb_one_AfterUpdate()
IntCheck
End Sub
Private Sub tb_two_AfterUpdate()
IntCheck
End Sub
Public Sub tb_three_AfterUpdate()
IntCheck
End Sub
Private Sub tb_four_AfterUpdate()
IntCheck
End Sub
Private Sub tb_five_AfterUpdate()
IntCheck
End Sub
Private Sub tb_six_AfterUpdate()
IntCheck
End Sub
Private Sub tb_seven_AfterUpdate()
IntCheck
End Sub
Private Sub tb_eight_AfterUpdate()
IntCheck
End Sub
Private Sub tb_nine_AfterUpdate()
IntCheck
End Sub
Private Sub tb_ten_AfterUpdate()
IntCheck
End Sub
Private Sub tb_eleven_AfterUpdate()
IntCheck
End Sub
Private Sub tb_twelve_AfterUpdate()
IntCheck
End Sub
Private Sub tb_thirteen_AfterUpdate()
IntCheck
End Sub
Private Sub tb_fourteen_AfterUpdate()
IntCheck
End Sub
Private Sub IntCheck()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
End Sub
I stepped through the code and it seems that once it gets to the "If TypeName(Me.ActiveControl) = "TextBox" Then" line, it goes right to "End if". Any help provided is greatly appreciated. Thanks in advance.
Chunk
The values that the user needs to enter into the text boxes are numbers. (no decimals, special characters or letters). I do not want a limit on the number of characters as well. After the user enters the numbers they will click on a "Calculate" button that will preform some simple math. For the math to happen, I need to ensure that only numbers are entered into the textboxes. Here is what I have been attempting (obviously, with no success):
Private Sub tb_one_AfterUpdate()
IntCheck
End Sub
Private Sub tb_two_AfterUpdate()
IntCheck
End Sub
Public Sub tb_three_AfterUpdate()
IntCheck
End Sub
Private Sub tb_four_AfterUpdate()
IntCheck
End Sub
Private Sub tb_five_AfterUpdate()
IntCheck
End Sub
Private Sub tb_six_AfterUpdate()
IntCheck
End Sub
Private Sub tb_seven_AfterUpdate()
IntCheck
End Sub
Private Sub tb_eight_AfterUpdate()
IntCheck
End Sub
Private Sub tb_nine_AfterUpdate()
IntCheck
End Sub
Private Sub tb_ten_AfterUpdate()
IntCheck
End Sub
Private Sub tb_eleven_AfterUpdate()
IntCheck
End Sub
Private Sub tb_twelve_AfterUpdate()
IntCheck
End Sub
Private Sub tb_thirteen_AfterUpdate()
IntCheck
End Sub
Private Sub tb_fourteen_AfterUpdate()
IntCheck
End Sub
Private Sub IntCheck()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
End Sub
I stepped through the code and it seems that once it gets to the "If TypeName(Me.ActiveControl) = "TextBox" Then" line, it goes right to "End if". Any help provided is greatly appreciated. Thanks in advance.
Chunk