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

Check for Non-numeric, or 'Ignore' clause in IF stmt

Status
Not open for further replies.

lorirobn

MIS
Mar 15, 2005
450
US
Hello everyone,

Is there a way to check for a NONnumeric value in a field? In addition, is there a way to have 'ignore' as the action in an IF statement?

I want to set an error message if the value in a field is not numeric.

for example: If RoomNumber is not numeric, set ErrorMsg.

Alternatively, I could also do:
If RoomNumber IS numeric
Ignore
Else set ErrorMsg

In COBOL, you can program 'Next Sentence' if you want to ignore a condition in an IF statement. Is there something comparable in VBA? You can also negate a test for numeric. Is there an opposite for ISNUMERIC?

I 'only' have 5 big Access books and can't find the answer in any, OR the help facility. Is it me??

Thanks in advance,
Lori
 
You can use the IsNumeric to check if an expression is numeric or not.

IsNumeric("Hello") returns False

IsNumeric("127") returns True
 
Is RoomNumber defined as numeric in the table and is the control on the form bound to the RoomNumber on the form?

You can also use properties of the control such as the Input Mask.
 
ByteMyzers suggestion will return whether or not the contents is numeric. To negate a test, just place the Not operator in front - the general if-then-else construct for VB/VBA could look something like this

[tt]if Not IsNumeric(strSomeVariable) then
msgbox "Not numeric..."
' perform some important code based on the field/variable...
' not being numeric
else
msgbox "Wow - it's numeric..."
' perform some more important code for the
' numeric outcome
ënd if
...[/tt]

If there are leading numbers, and characters at the end, have a look at the Val() function

[tt]msgbox Val("Test") ' would return 0
msgbox Val("123Hello") ' would return 123[/tt]

But the suggestion of Willir is perhaps most common, binding a control to a field with the correct datatype, so the validation is performed by the Jet engine.

Roy-Vidar
 
Thank you, everyone who replied!
'if not isnumeric' is exactly what I was looking for...

Lori
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top