John,
Its not really an issue, but for the life of me I can't figure out in Module2 what is being returned from the function. Its a Boolean, but NumberVal doesn't show up anywhere after it is called. The function is being called from this Private Sub
Private Sub TextBox_r_AfterUpdate()
Dim txtValue As Variant
If Val(Me.TextBox_r.Value) < 0 Or Val(Me.TextBox_r.Value) > 1 Then
MsgBox Me.TextBox_r.Name & " Value must be > 0 and less < 1"
Me.TextBox_r.Value = ""
Me.TextBox_r.SetFocus
Exit Sub
End If
txtValue = Me.TextBox_r.Value
Call NumberVal(txtValue)
If Numeric = False Then
Me.TextBox_r.Value = ""
Me.TextBox_r.SetFocus
Exit Sub
Else
End If
End Sub
It looks like operationally the NumberVal function toggles the Public Numeric between TRUE & FALSE. If that's so why must the Function NumberVal be declared as Boolean? Is there a reason? Sorry, as you can tell from my code which doesn't want to work, I'm by no means an expert at all the ins & outs of VBA. Your code works with a third of the code I had to use. Your function is below
Public txtValue As Variant
Public Numeric As Boolean
Option Explicit
Function NumberVal(txtValue) As Boolean
Dim LPos As Integer
Dim LChar As String
Dim LValid_Values As String
LPos = 1
LValid_Values = " .0123456789"
While LPos <= Len(txtValue)
LChar = Mid(txtValue, LPos, 1)
If InStr(LValid_Values, LChar) = 0 Then
Numeric = False
Exit Function
End If
LPos = LPos + 1
Wend
Numeric = True
End Function
Bookmarks