Hello,
I am trying to fix the following If then statements code behind a command button. On a form I have a text box and a command button next to each other. In the text box users are only allowed to enter numbers. Once they entered a number they then click on the command button and it executes some code. What I want it do before it executes the main code is via the following if statements is to check that a user did not enter text first of all, then check that the number entered is between 1 and 99 because if it is not then it should exit the sub. If the data entered is not text and the number is between 1 and 99 then go ahead and execute the code.
txtTaxRate is an unbound text box
Go is a boolean variable (boolGo) that executes some code if true
Thanks,
BC
I am trying to fix the following If then statements code behind a command button. On a form I have a text box and a command button next to each other. In the text box users are only allowed to enter numbers. Once they entered a number they then click on the command button and it executes some code. What I want it do before it executes the main code is via the following if statements is to check that a user did not enter text first of all, then check that the number entered is between 1 and 99 because if it is not then it should exit the sub. If the data entered is not text and the number is between 1 and 99 then go ahead and execute the code.
txtTaxRate is an unbound text box
Go is a boolean variable (boolGo) that executes some code if true
Code:
If Not IsNumeric(txtTaxRate) then
MsgBox ("Please enter a number and not text.")
Exit Sub
ElseIf
If (Val(txtTaxRate) >= 1 and Val(txtTaxRate) <= 99) Then
boolGo = True
ElseIf
If (Val(txtTaxRate) < 1 or Val(txtTaxRate) > 99) Then
boolGo = False
MsgBox ("Please enter a Tax Rate between 1 and 99")
Exit Sub
End If
boolGo = True
Thanks,
BC