I would like to know if anyone could tell me of a validation Rule that only allows 8 character reference number in a field. I have tried things like '00000000' and '????????'.
I looked for something like this for awhile then decided to approach it from a different way.
I used an afterupdate event to check for character length.
******code start*****
Private Sub Text0_AfterUpdate()
If Len(Text0) > 8 Then
Me!Text0 = vbNullString
Me!Text0.SetFocus
MsgBox "8 character maximum has been exceeded.", vbOKOnly, "OOPS!"
Exit Sub
End If
End Sub
*****end code*****
In the example above, if the characters in my textbox exceed 8, i clear the box and give the users an error message.
Let me know if this helps. Also, maybe someone will be able to share a validation rule, but until then... there is usually more than one way to accomplish what we need.
If your intent is to allow 8 or less characters in the field the answer is really very elementary; in Design View of the underlying table enter 8 as the field size. Access will then only allow a maximum 8 characters to be entered.
If you have to have exactly 8 characters in the field, change the first line of nathan1967's code to If Len(Text0) < 8 Then and change the message to suit.
Hope this helps.
The Missinglinq
"It's got to be the going,
not the getting there that's good!"
-Harry Chapin
In case 2 above (need exactly 8 characters) I should have said set the field size to 8 (to prevent more than 8 characters) AND change the first line of nathan1967's code to prevent less than 8 characters.
The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
Thanks guys i unfortunately forgot to state that i have originally tried Rules similar to these but they would only work if the "Data Type" for your field is set to "Number". My intention is for the "Data Type" to be an "AutoNumber" and still not have it less than 8 characters long. So basically if i can get an Automatically generated number which could somehow accept the Validation Rule: >10000000 and <20000000.
As I understand it, Field Values for Autonumbers are assigned by Access and cannot be manipulated by either developer or user. The only option you have for Autonumbers is whether they're incremented by one for each record added or whether they are randomly assigned. The randomly assigned Autonumbers option is usually used in replicated dbs. If you have to have an eight character designation for this field you're going to have to go a route other than Autonumber.
The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.