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

VALIDATION RULE number of characters allowed

Status
Not open for further replies.

baybie

IS-IT--Management
Oct 5, 2002
68
GB
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 '????????'.

Gracias
 
Hi baybie,

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. :)

HTH Have A Great Day!!!, [bigglasses]

Nathan
Senior Test Lead
 
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

&quot;It's got to be the going,
not the getting there that's good!&quot;
-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 &quot;It's got to be the going,
not the getting there that's good!&quot;
-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 &quot;Data Type&quot; for your field is set to &quot;Number&quot;. My intention is for the &quot;Data Type&quot; to be an &quot;AutoNumber&quot; 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.

Sorry i didn't clarify in the first post.
 
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 &quot;It's got to be the going,
not the getting there that's good!&quot;
-Harry Chapin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top