ACommandLineKindaGuy
Active Member
- Joined
- May 11, 2002
- Messages
- 378
- Office Version
- 365
- Platform
- Windows
I have the following code to check the input of a Textbox.
So, for say TextBox301, I call a routine to validate the number I enter. I have a lot of groups of TextBoxes and they all have different maximum integer values, so I pass the maximum value using public constant n:
<code>Private Sub TextBox301_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Call ValidateInput(TextBox301, 5)
End Sub
Private Sub ValidateInput(MyControl, n) 'n = Control's max value
'#UNDER DEVELOPMENT############### THE PROBLEM IS THE .Value > n STATEMENT
'We only have to check for integers since the maximum characters is 1...
With MyControl
If Not IsNumeric(.Value) Or .Value < 1 Or .Value > n Then
MsgBox "Must be numeric, or an integer between 1 and " & n & "... ", vbCritical, "Invalid Entry:"
.SelStart = 0
.SelLength = .MaxLength + 1
Cancel = True
End If
End With
'#END UNDER DEVELOPMENT###########
End Sub</code>
The problem is with the ".Value > n" portion of the If statement. If I remove it, the If statement doesn't fire. If I substitute ".Value * 1 > n" it also doesn't fire, but then of course the routine errors out when I enter a letter.
So, anyone have any idea WHAT is going on? If I had any hair, I'd be bald...
So, for say TextBox301, I call a routine to validate the number I enter. I have a lot of groups of TextBoxes and they all have different maximum integer values, so I pass the maximum value using public constant n:
<code>Private Sub TextBox301_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Call ValidateInput(TextBox301, 5)
End Sub
Private Sub ValidateInput(MyControl, n) 'n = Control's max value
'#UNDER DEVELOPMENT############### THE PROBLEM IS THE .Value > n STATEMENT
'We only have to check for integers since the maximum characters is 1...
With MyControl
If Not IsNumeric(.Value) Or .Value < 1 Or .Value > n Then
MsgBox "Must be numeric, or an integer between 1 and " & n & "... ", vbCritical, "Invalid Entry:"
.SelStart = 0
.SelLength = .MaxLength + 1
Cancel = True
End If
End With
'#END UNDER DEVELOPMENT###########
End Sub</code>
The problem is with the ".Value > n" portion of the If statement. If I remove it, the If statement doesn't fire. If I substitute ".Value * 1 > n" it also doesn't fire, but then of course the routine errors out when I enter a letter.
So, anyone have any idea WHAT is going on? If I had any hair, I'd be bald...
Last edited: