Numeric or null value

G

Guest

Hi all,

I use the following function to evaluate the contents of a text box on my
userform.
i want the code to allow either Numbic OR Null values. If the value in the
textbox is text, i want the system to fire a message stating the field does
not except text values.

Problem: This code does not allow the user to tab past an empty cell.
Instead, if the user doesn't provide a value, the message fires.

Can anyone assist with this one?

Function:
Public Function EvaluateText(anyEntry As String) _
As Boolean

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


On Exit Event of Textbox:

Private Sub txtPLSFlow_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = EvaluateText(Me!txtPLSFlow.Text)
End Sub
 
G

Guest

Hi Carlee,

Try:

Public Function EvaluateText(anyEntry As String) _
As Boolean

EvaluateText = False ' all is well

If anyEntry="" then Exit Function '<=== added this line to allow null
strings.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top