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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch Validate data on Input box

Status
Not open for further replies.

Vack58

Technical User
May 30, 2008
19
US

If I accidently input a character in my input box I get a type mismatch Because I am trying to add leading zeros. Is there any way to force the user to enter a numeric value?



Dim intRCCount1, objRS1, result

Do
intRCCount1 = 0
PO = InputBox(Message, Title, "00", 5000, 4000)
if PO = "" then 'A
wscript.quit(9)
else
PO = ((right(PO + 100000000,8)))
strSQL11 = "Select ord_no from POORDHDR_SQL where ord_no='" & PO & "'"
Call GetPORecordSetCount(strSQL11, intRCCount1, objRS1)
if intRCCount1 = 0 then 'B
msgbox "PO Not on File",,"Quest IV"
else
Exit Do
end If 'B
end if 'A
Loop
 
Use the IsNumeric function to only proceed if a number is entered.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I tried that. If I enter a 4000 I receive a message PO must be numeric. If I enter DDD I get the type mismatch error.


Dim intRCCount1, objRS1, result

Do
intRCCount1 = 0
PO = InputBox(Message, Title, "00", 5000, 4000)
if PO = "" then 'A
wscript.quit(9)
else
if isnumeric(PO) then
msgbox "PO must be Numeric"
else
PO = ((right(PO + 100000000,8)))
strSQL11 = "Select ord_no from POORDHDR_SQL where ord_no='" & PO & "'"
Call GetPORecordSetCount(strSQL11, intRCCount1, objRS1)
if intRCCount1 = 0 then 'B
msgbox "PO Not on File",,"Quest IV"


else
Exit Do
end If 'B
end if 'A
end if
Loop
 
If [!]Not[/!] IsNumeric(PO) Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The if not isnumeric lets me enter 4000 but when I enter 45dk I still get a type mismatch error. Doesn't go to my msgbox "PO must be numeric"


Dim intRCCount1, objRS1, result

Do
intRCCount1 = 0
PO = InputBox(Message, Title, "00", 5000, 4000)
if PO = "" then 'A
wscript.quit(9)
else
if Not isnumeric(PO) then
PO = ((right(PO + 100000000,8)))
strSQL11 = "Select ord_no from POORDHDR_SQL where ord_no='" & PO & "'"
Call GetPORecordSetCount(strSQL11, intRCCount1, objRS1)
if intRCCount1 = 0 then 'B
msgbox "PO Not on File",,"Quest IV"
else
msgbox "PO must be numeric"
end if


else
Exit Do
end If 'B
end if 'A

 
How about a regular expression then...

pattern if you only expect whole numbers: ^\d+$

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Can you give me a little more info?

I am a beginner at VB, I don't understand your last post.
 
Dim RegEx : Set RegEx = New RegExp
RegEx.Pattern = "^\d+$"

Dim strInput : strInput = InputBox("Enter a number", "Enter Number", "0")

If RegEx.Test(strInput) Then
WScript.Echo "you entered a number"
Else
WScript.Echo "you didn't enter a number"
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
If you're going to check for IsNumeric(), it should be done immediately after the InputBox statement!
 
<Doesn't go to my msgbox "PO must be numeric">

thats because you have the Exit Do in the "else" of the "if Not" statement, your label 'B is not correct
if Not isnumeric(PO) then
PO = ((right(PO + 100000000,8)))
strSQL11 = "Select ord_no from POORDHDR_SQL where ord_no='" & PO & "'"
Call GetPORecordSetCount(strSQL11, intRCCount1, objRS1)
if intRCCount1 = 0 then 'B
msgbox "PO Not on File",,"Quest IV"
else
msgbox "PO must be numeric"
end if
else
Exit Do
end If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top