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

TELEPHONE FEILD MASKS 2

Status
Not open for further replies.

Nikelo11th

Programmer
Feb 9, 2003
7
0
0
DE
hi there.
i have a form in access which has a feild called telephone number. This feild is linked to a feild in my database. so when people fill out the feild, then the feild in the datbase will update aswell.

my problem is that i dont want anyone to type more or less than 11 numbers in that telephone feild......
so they have to type in 11 numbers.... no less and no more.... i tried using input masks and everything but couldn't find a way to do it. i also used validation but got baffled walfway through..............

plz help me someone......... i would be grateful......... i need to make them type only 11 charecters........................

thanks...........
 
Hi, Nikelo

A simple way to do this is:
First of all use a text field for the Telephone numbers as opposed to a numeric one.
Set the length of the text field to 11 characters.
Next, add the following code to the BeforeUpdate event of the field. Don't forget "telephone" = the name of your field!


Private Sub telephone_BeforeUpdate(Cancel As Integer)

If Len(Me![telephone]) < 11 Then
MsgBox &quot;Telephone Field must be exactly 11 characters long.&quot;
Cancel = True
End If

End Sub

You can, of course, make up your own custom msgbox.

Hope this helps.......


Dave
 
On a similar note - I have a problem when I only want the user to enter in no more than 20 characters. They can select 19, 18, 17 etc, but no more than 20 characters.

I know that there is a rule which a person can put in the validation rule box, but I cannot remember, what the rule is suppose to be like. Can anyone help me?

Thank you very much



 
goodwork...... i can do that one.......
go to your database and select the field which you want that 20 charecter to be........ then...... go to design view and set the feild length to 20......... now they can type in up to 20 charecters but no more.........

hope this was helpful...... bye
 
sorry - i don't mean that way

I want a msgbox to come up and say &quot;Sorry - only 20 characters allowed&quot;

This means that the field size must be more than 20 characters

thanks

 
sorry

should read

msgbox &quot;field size must be no more than 20 characters&quot;

thanks
 
Goodwork, cannot understand why you would want a message box to come up. If you want to limit the field to 20 characters, then just set the field length to that.

However, if you want a message to appear then do the following without limiting the length of the field.

Private Sub Nameofyourfield_BeforeUpdate(Cancel As Integer)
If Len(Me![Nameofyourfield]) > 20 Then
MsgBox &quot;Field size must be no more than 20 characters.&quot;
Cancel = True
End If
End Sub

This will alert the user to the fact that he/she cannot enter more than 20 characters. It will not allow the record to be saved until the field is limited to up to 20 characters.

Is this what you want?

Dave

Nickelo - Glad to have helped :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top