-
October 10th, 2002, 10:02 AM
#1
Problem using "On Error" Statement...
Hi all,
On my form I have a text box(Text1) and a button(Command1), here is the code at the moment:
Private Sub Command1_Click()
On Error GoTo Err1
If Int(Text1) < 0 Then
MsgBox ("Only enter a positive number")
Else
MsgBox ("You have entered a correct digit")
End If
Err1: MsgBox ("An Error has occured")
End Sub
The reasons I have put in the error statement is to prevent the user from entering letters into the box. The problem is, if I enter a positive digit, e.g. 10 into the box, I get the expected message box appearing and then straight after I get the error box appearing??
Any info on how I can fix this? Thanks.
Mark
-
October 10th, 2002, 10:13 AM
#2
TRY
If VAL(Text1) < 0 Then
MsgBox ("Only enter a positive number")
Else
MsgBox ("You have entered a correct digit")
End If
-
October 10th, 2002, 10:17 AM
#3
I tried this but you can still enter letters such as a,b,c an it will accept it.
I want it to produce the error message when non-numerical characters are entered.
Thanks anyway. Any more info...
Mark
-
October 10th, 2002, 10:17 AM
#4
Exit sub
Modify your code as follow to prevent the execution of the msgbox when all is good
Code:
...
End If
Exit Sub
Err1: MsgBox ("An Error has occured")
End Sub
/.*/{Guru AWK}
-
October 10th, 2002, 10:28 AM
#5
Thanks, got it working fine now.
Mark
-
October 10th, 2002, 12:15 PM
#6
You can also look for the CInt() function, and don't forget that Exit Sub (in a function, use Exit Function)
JeffB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|