Error if input is wrong size

  • Thread starter Thread starter Cranky
  • Start date Start date
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
 
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
 
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
 
Hi Allen

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

S:)
 
Hi Tom

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

S:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error Msg Box 4
Date Format/ Input mask 1
Extending Input Mask 4
Input Mask Errors 2
General Input 1
Input Mask in tables 2
Two types of textbox input 1
input mask 4

Back
Top