Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if the value entered is 5 digits?

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

i need to check if the value entered in the field is numeric, 5 digits and starts with 9

Please help

Thanks
 
These are the things you need to check:
Code:
if (not isnumeric(txtField)) or ((isnumeric(txtField)) and ((left(txtField,1) <> '9') or (len(txtField) <> 5))) then

       msgbox &quot;error&quot;

end if
 
If this is for a form,you could use an Input Mask for the text box:

\90000
 
the input mask will just require 5 digits... not check it...


if len(me!textbox) > 5 then
msgbox &quot;The number has more then 5 digits...&quot;
else
msgbox &quot;The number has 5 or less digits...&quot;
end if

;-)

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Code:
Public Function basChkVal(frm As Form, Ctrl As Control) As Boolean

    If (Not IsNumeric(Ctrl)) Then
        basChkVal = False
        GoTo ErrExit
    End If

    If (IsNumeric(Ctrl)) And _
       ((Left(Ctrl, 1) <> &quot;9&quot;) Or (Len(Ctrl) <> 5)) Then

       MsgBox &quot;error&quot;
       basChkVal = False

     Else

        basChkVal = True

    End If
 
ErrExit:

End Function

Called as in:

Code:
Private Sub txtMyNumbText_AfterUpdate()
    If (basChkVal(Me, Me.txtMyNumbText) <> True) Then
        MsgBox &quot;Error in Entry Value.&quot; & vbCrLf & &quot;Please Re-Enter The value in &quot; & Me.ActiveControl.Name
        txtMyNumbText = &quot;&quot;
    End If
End Sub

Wondering about all of the complexity of it all.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top