Error if input is wrong size

C

Cranky

Hi

I want to have an error message pop up if the input into a text box
(number) is not 12 digits long. Because the field is optional, it can
be empty, although if there is any input at all, the number but be 12
digits long.

I can't seem to do this and am just learning Access. Please can anyone
offer up some advice on how to do this?

Thanks in advance.

Cranky
 
A

Allen Browne

If this text box is bound to a Number field, or is unbound but must accept a
Number, set its Validation Rule to
Is Null Or (Between 100000000000 And 999999999999)

If it is Text, use the BeforeUpdate event procedure to test it:
With Me.Field1
If Len(.Value) <> 12 Then
Cancel = True
MsgBox "Must be 12 characters long."
End If
End With
 
T

Tom Wickerath

Hi Cranky,

There's no need to be cranky <smile>. You can try the following validation
rule at the table level:

If Data Type is text
Validation Rule: Like "############" Or Is Null
Validation Text: Enter a 12 digit number, or leave blank.

If Data Type is numeric
Validation Rule: Len([FieldName])=12 Or Is Null
Validation Text: Enter a 12 digit number, or leave blank.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

:

Hi

I want to have an error message pop up if the input into a text box
(number) is not 12 digits long. Because the field is optional, it can
be empty, although if there is any input at all, the number but be 12
digits long.

I can't seem to do this and am just learning Access. Please can anyone
offer up some advice on how to do this?

Thanks in advance.

Cranky
 
C

Cranky

Hi Allen

Thanks for the advice. I've tried both yours and Tom's advice on
different forms. Works great; thank you.

S:)
 
C

Cranky

Hi Tom

Thanks for the advice. I've tried both yours and Allen's advice on
different forms. Works great; thank you.

S:)
 
Top