ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Numeric or null value (https://www.excelbanter.com/excel-programming/387929-numeric-null-value.html)

Carlee

Numeric or null value
 
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

--
Carlee

Vergel Adriano

Numeric or null value
 
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


--
Hope that helps.

Vergel Adriano


"Carlee" wrote:

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

--
Carlee



All times are GMT +1. The time now is 01:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com