I am trying to set up a small bit of error checking code in order for my end users to get a "second chance" at entering valid data.
They wanted the ability to "add" numbers together while counting documents without using a calulator (or God forbid they use their head!!!) SO they are entering a string such as:
"5+10+5+15" into a text box and getting the results displayed in a new text box.
BUT
I know my end users!!! So what if they try to enter a - (minus) sign??
IF they do, the error message that is displayed is "run-time error 13: type mismatch" Why does the following code not work to trap this particular instance of the error.
Please help me understand why this doesn't work! I've been searching out here all morning to hopefully help myself but can't seem to find the exact answer.
All assistance is much appreciated!
Dan
They wanted the ability to "add" numbers together while counting documents without using a calulator (or God forbid they use their head!!!) SO they are entering a string such as:
"5+10+5+15" into a text box and getting the results displayed in a new text box.
BUT
I know my end users!!! So what if they try to enter a - (minus) sign??
IF they do, the error message that is displayed is "run-time error 13: type mismatch" Why does the following code not work to trap this particular instance of the error.
Code:
Dim arr
Dim t As Variant
arr = Split(Me.txtCount, "+")
Dim TotalCount As Integer
TotalCount = 0
For Each t In arr
If t = "" Then
GoTo ExitLoopBlank
ElseIf Err.Number = 13 Then
GoTo ExitLoopTMisMatch
Else
TotalCount = TotalCount + t
End If
Next t
Me.txtTotal = TotalCount
ExitLoopBlank:
Me.txtTotal = TotalCount
Exit Sub
ExitLoopTMisMatch:
MsgBox "There has been a type mismatch, ... " & Chr(13) & Chr(10) & "Please check the data that was entered and try again.", vbCritical, "Entry Error!"
Me.txtTotal.SetFocus
Me.txtCount.SetFocus
Exit Sub
All assistance is much appreciated!
Dan