View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Carlee Carlee is offline
external usenet poster
 
Posts: 155
Default Error Handling

Thanks for the help. It is almost working!!!
I only needed the first part of the code you listed (checking for numeric
data). When i enter non-numeric data, the message fires, and i can correct
the entry.

Problem:
I cannot move off the field. The system will not allow me to move to any
other field. Any suggestions on how to proceed? Code provided below:


Private Function EvaluateText(anyEntry As String, _
loLimit As Integer, upLimit As Integer) As Boolean

EvaluateText = True ' to set Cancel with
If Not IsNumeric(anyEntry) Then
MsgBox "This field accepts numeric data only. Please revise your entry
and try again."
Cancel = True
Exit Function ' exit with True
End If


End Function

--
Carlee


"JLatham" wrote:

Write one Function in the form's code module that evaluates a value passed to
it as numeric and then simply call that function from each _Exit() routine -
passing it the value of the individual text box and if you need to test for a
valid range of numbers that varies from box to box, then pass it those limits
also?

Maybe something like this?

Private Sub TextBox1_Exit(ByVal Cancel _
As MSForms.ReturnBoolean)

Cancel = EvaluateText(Me!TextBox1.Text, 5, 10)
End Sub

Private Function EvaluateText(anyEntry As String, _
loLimit As Integer, upLimit As Integer) As Boolean

EvaluateText = True ' to set Cancel with
If Not IsNumeric(anyEntry) Then
'generic not-a-number message
MsgBox "Entry is not numeric"
Exit Function ' exit with True
End If
If Val(anyEntry) < loLimit Or Val(anyEntry) upLimit Then
'invalid value entered message
MsgBox "Invalid Value Entered"
Exit Function ' exit with True
End If
EvaluateText = False ' passed tests, don't cancel
End Function


"Carlee" wrote:

Hi,

Short of writing code for each on_exit event of each field on my form that
is of 'numeric' type, is there code that i can use to notify the user when
they have entered invalid data in a field? I have about 80 text boxes on a
multipage userform.

Any suggestions would be fantastic!
--
Carlee