Solved

IsNumber() not available for Validation Rules

Posted on 2011-09-20
7
569 Views
Last Modified: 2013-11-29
I'm trying to validate that characters 2 through 5 of a table's text field should be numeric. However, IsNumeric() doesn't seem to be available (Access 2003).
0
Comment
Question by:Milewskp
7 Comments
 
LVL 10

Expert Comment

by:Michael Vasilevsky
ID: 36569960
IsNumeric should work in VBA and in a SQL statement. What do you mean it doesn't seem to be available? What are some strings you're trying to validate?

MV
0
 
LVL 75
ID: 36570185
VBA:

If IsNumeric(Mid(sFldText, 2, 4)) Then
   ' what ever

Query:

SELECT IsNumeric(Mid([FIELD1],2,4)) AS Expr1
FROM Table1;

or

SELECT IIf(IsNumeric(Mid([FIELD1],2,4)),"Yes","No") AS Expr1
FROM Table1;

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36570937

Or you could use something like:

SELECT * FROM yourTable WHERE [yourField] not like "?[0-9][0-9][0-9[0-9][0-9]*"

This will identify all records where the first character allows any character, then the next 5 characters are numeric, and then has any number of other characters.  The NOT will identify any records that violate this rule.

I'm not certain whether this is available in the Validation, but could be used in the BeforeUpdate event to test the value in the control.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:Milewskp
ID: 36573507
I should have been more clear: I was trying to use IsNumeric() in the Validation Rule property of a table's text field. It didn't work, and when I clicked Build, I discovered that IsNumeric is not included in the list of built-in functions. Therefore I assume it's not avaialble for validation rule properties (even though it may be avaiable in VBA and SQL).
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 36573547
try:

Validation Rule: Like "?[0-9][0-9][0-9][0-9][0-9]*"

0
 
LVL 1

Author Comment

by:Milewskp
ID: 36574267
Thanks fyed, you're a genius.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36574283
Glad to help,

I generally prefer to put my validation tests in the Form_BeforeUpdate
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question