Validation rule

dmbfan73

Registered User.
Local time
Today, 06:39
Joined
Nov 21, 2002
Messages
13
I need some help with a validation rule.

I have a field with ID numbers, and don't want users to be able to put dashes in the numbers. (I have my report set up to automatically put the dashes in the right places)

I've tried using ="aaaaa", but of course this restricts the amount of letters/numbers the user can type in. I need users to be able to put in as many letters and numbers that they want.

I don't think I can use an imput mask either, because the ID numbers will be different lengths.


Any suggestions?
Thanks, I've learned so much from this board!
 
I assume you're using a form to enter data.
Open the form in design mode.
On the tabpage called Data, define a

1) Validation Rule for your IDNumber textbox:

InStr(1;[TextBoxName];Chr(46))=0
TextBoxName = name of your forms textbox

2) Define validationtext, for example:

Dots are not allowed in ID numbers

HTH,

RV
 
Thanks for the reply, but I tried that and it didn't work. I entered a number without dashes and I still get the error.
 
It (the idea) works though.

Have you degfined the validation rule ON your textbox?
Have you used the correct name for your textbox?

RV
 
This VBA works

Code:
Private Sub Text0_KeyPress(KeyAscii As Integer)
Const aDot = 46
Const aDash = 45
If KeyAscii = aDot Or KeyAscii = aDash Then KeyAscii = 0
End Sub
 
Tried that too, and I still get the error even if I put in a valid format. Am I missing something obvious?
 
What is the worst-case scenario for the length of the textbox? Use that number of a's in the Input Mask. From Access Help for Input Mask, InputMask Property:

a Letter or digit (entry optional).
 
Thanks pdx_man! I had thought about using an imput mask before, but when I was using the wizard I didn't realize you could make your own. Works great now! Thanks again!
 

Users who are viewing this thread

Back
Top Bottom