Validate number of digits inputted in a field in an access query

Is there a way to check the number of characters inputted into a field in access by using a query.

For example I have a field that should have a five digit filed inputted.  The field may have leading zeroes.
I am trying to determine those fields which have only four digits inputted which is an error.
 04589  is OK
4589  is not
How can I check for this?
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Or, to show those that don't meet your criteria:

SELECT * FROM SomeTable WHERE Len(YourField)<>5
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The quickest way would be to go to your text box's Properties, find the Input Mask property, and type 00000.

Also, whatever ControlSource this is bound to will have to be in text format, as numeric formats do not allow for trailing zeros.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
{correction}

The quickest way would be to go to your text box's Properties, find the Input Mask property, and type 00000.

Also, whatever ControlSource this is bound to will have to be in text format, as numeric formats do not allow for leading zeros.
0
 
LenaWoodCommented:
You could use the format property of the field in the table and put in 5 zeros:

00000

That will make the field be 5 digits.  If someone entered 4589 then Access would show it as 04589.  This is assuming that your field is a number field.

Does that help you in solving your issue?
Lena
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You could use a query to show you all records that meet your criteria:

SELECT * FROM SomeTable WHERE Len(YourField)=5
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.