Phone with/without area code

G

Guest

Phone field is text without input mask.
I want to enter 7 digits and have it appear as ( ) xxx-xxxx
I want to enter 10 digits and have it appear as (xxx) xxx-xxxx
 
G

Guest

The input mask forces you to key stroke past the area code if there are only
7 numbers. If you just start typing numbers, it fills the area code first. In
reading other threads, someone mentioned using "format" but I don't know how.
 
G

Guest

Thanks Ken, I looked at the input mask I had tried in the past and it started
with an "!" so I assumed your solution would work the same. Your solution
works. Can you explain the difference between the 2 masks: !\(999")
"000\-0000;0;_ and !\(999\)\ 999\-9999? Also, after I enter your mask, why
does Access change it to: !\(999") "999\-9999"
 
K

Ken Snell \(MVP\)

!\(999") "000\-0000;0;_

This input mask uses the optional second and third parts. The 0 for the
second part tells ACCESS to store the "embedded literal characters" (namely,
the leading (, the trailing ) and space, and the hyphen) with the numerals
when the data are stored in the database. As such, ACCESS will store "(412)
555-1234" as the text string in the table's field instead of "4125551234"
when you put a 0 in the second part; putting a 1 in the second part will
store the data just as the numerals. The _ in the third part tells ACCESS
which placeholder character to show when the user is entering data in the
input mask; in this case, an underscore character.


!\(999\)\ 999\-9999

This input mask essentially is the same as the first one with respect to
the characters to be displayed (the leading (, the trailing ), the space,
and the hyphen); the only difference is that an escape character (the \) is
used for each character. In the first one above, the sequence
\)\ (note that there is a space after the second \ character
here)
has been changed by ACCESS to
") "
which is using a text string to represent the characters to be displayed
instead of escaping each character -- the result is the same and I assume
that ACCESS thinks it's more clear to the user to show the text string
instead of the escape character + literal character sequence. This mask also
leaves out the second and third parts, so ACCESS defaults to a value of 1
for the second part, and _ for the third part.


By the way, this behavior by ACCESS of putting text strings in place of
literal characters also can be seen when you type "date/time" formats into
the Format property (e.g., mmm dd, yyyy will be changed by ACCESS to mmm"
"dd", "yyyy).
 
G

Guest

Thanks Ken!

Ken Snell (MVP) said:
!\(999") "000\-0000;0;_

This input mask uses the optional second and third parts. The 0 for the
second part tells ACCESS to store the "embedded literal characters" (namely,
the leading (, the trailing ) and space, and the hyphen) with the numerals
when the data are stored in the database. As such, ACCESS will store "(412)
555-1234" as the text string in the table's field instead of "4125551234"
when you put a 0 in the second part; putting a 1 in the second part will
store the data just as the numerals. The _ in the third part tells ACCESS
which placeholder character to show when the user is entering data in the
input mask; in this case, an underscore character.


!\(999\)\ 999\-9999

This input mask essentially is the same as the first one with respect to
the characters to be displayed (the leading (, the trailing ), the space,
and the hyphen); the only difference is that an escape character (the \) is
used for each character. In the first one above, the sequence
\)\ (note that there is a space after the second \ character
here)
has been changed by ACCESS to
") "
which is using a text string to represent the characters to be displayed
instead of escaping each character -- the result is the same and I assume
that ACCESS thinks it's more clear to the user to show the text string
instead of the escape character + literal character sequence. This mask also
leaves out the second and third parts, so ACCESS defaults to a value of 1
for the second part, and _ for the third part.


By the way, this behavior by ACCESS of putting text strings in place of
literal characters also can be seen when you type "date/time" formats into
the Format property (e.g., mmm dd, yyyy will be changed by ACCESS to mmm"
"dd", "yyyy).
 
G

Guest

One more question...would you recommend the input mask go in the table or on
the entry form?
 
K

Ken Snell \(MVP\)

Most developers would recommend that you put the input mask on the field in
the table in this situation -- that way, all forms that you build that are
based on that table will inherit the input mask for the controls that are
bound to that field, and you won't need to repeat the input mask over and
over in each form. It also means that any data entry done directly in the
table (not that you would let your users do that, but you might) also will
enforce the input mask.
 
G

Guest

I went in today and some phone fields on the form are formatted correctly and
some don't have any format. I checked the table and it is holding correctly
formatted data. I checked field properties and the fields look the same. I'm
missing something but don't know where to look.
 
K

Ken Snell \(MVP\)

You need to give details about what "some don't have any format" means. Were
those data already in the table before you added the input mask -- if yes,
the input mask will not be applied to already existing data. What happens if
you re-enter the data -- does the value then show as "correctly formatted"?

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

Ken Snell (MVP) said:
You need to give details about what "some don't have any format" means. Were
those data already in the table before you added the input mask -- if yes,
the input mask will not be applied to already existing data. What happens if
you re-enter the data -- does the value then show as "correctly formatted"?
 
G

Guest

No format would be: 1234567890. After I added the input mask last week, I
went through the table and edited every phone field to comply with the mask.

On the form, when I enter a new number, it displays as 1234567890 after I
leave the field. When I check the table, it is not there. I go back to the
form and leave the record and return, the field in the form continues to read
1234567890 but the field in the table is (123) 456-7890.
 
K

Ken Snell \(MVP\)

Did you create the form before you added the InputMask property to the field
in the table? If yes, then that textbox did not inherit the InputMask from
the field because you'd already created the control before you created the
InputMask. Either add the input mask expression to the form's textbox, or
delete that control from the textbox and open the Field list in form's
Design view and drag the phone number field onto the form so that a new
textbox is created (which will inherit the properties of the field itself).
 
G

Guest

The form was created before the input mask. I followed your suggestions and
all is working well. Thank you.
 

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

Top