Validation rule (1 Viewer)

dmbfan73

Registered User.
Local time
Today, 15:22
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!
 

RV

Registered User.
Local time
Today, 15:22
Joined
Feb 8, 2002
Messages
1,115
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
 

dmbfan73

Registered User.
Local time
Today, 15:22
Joined
Nov 21, 2002
Messages
13
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.
 

RV

Registered User.
Local time
Today, 15:22
Joined
Feb 8, 2002
Messages
1,115
It (the idea) works though.

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

RV
 

Fornatian

Dim Person
Local time
Today, 15:22
Joined
Sep 1, 2000
Messages
1,396
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
 

dmbfan73

Registered User.
Local time
Today, 15:22
Joined
Nov 21, 2002
Messages
13
Tried that too, and I still get the error even if I put in a valid format. Am I missing something obvious?
 

pdx_man

Just trying to help
Local time
Today, 07:22
Joined
Jan 23, 2001
Messages
1,347
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).
 

dmbfan73

Registered User.
Local time
Today, 15:22
Joined
Nov 21, 2002
Messages
13
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

Top Bottom