Format US Zip

K

Kitty

How would I change this text box control format "00000\-9999;0;#" so that
the hyphen would not be included -- unless the user entered something for the
extension?

The control displays "#####-####", and the user enters the first five digits
as "12345". The table then contains "12345-".

I only want the hyphen in the table when the user would enter something like
"12345-6789", more than the basic five digits.

Thank you very much,
 
F

fredg

How would I change this text box control format "00000\-9999;0;#" so that
the hyphen would not be included -- unless the user entered something for the
extension?

The control displays "#####-####", and the user enters the first five digits
as "12345". The table then contains "12345-".

I only want the hyphen in the table when the user would enter something like
"12345-6789", more than the basic five digits.

Thank you very much,

You seem to be confusing the Control's Format property with the
Control's Input Mask property.

An Input Mask doesn't work the way you want it to.
1) Use 2 separate fields. [Zip] for the 5 digits and [ZipExtension]
for the occasional 4 digits.

Concatenate them when you need to print it out:
= [City] & ", " & [State] & " " & [Zip] & ("-" + [ZipExtension])
Note the use of the "+" above.

Or...
2) Remove the hyphen completely from the field.
Run an Update Query to remove the hyphen from existing records:
Update MyTable Set MyTable.Zip = Replace([Zip],"-","")

Then, for new data entry, if you must use an Input Mask, set the mask
to NOT be saved with the Data:
00000\-9999;;#

The mask will only 'help?' the user during data entry, the hyphen will
display in the control, but it will not be saved with the data.
Data will be saved as 32123 and 906569872

You will then need to have code when printing the Zip code to add the
hyphen, i.e.
= [City] & ", " & [State] & " " & IIf(Len(Zip])= 5,[Zip],Left([Zip],5)
& "-" & Mid([Zip],6)

3) Alternatively, you could continue with the data you already have
(that includes the hyphen) and use code to remove the un-needed hyphen
when printing the Zip:
=[City] & ", " & [State] & " " &
IIf(Len([ZIP])=6,Replace([Zip],"-",""),[ZIP])

My personal preference would be to not use an Input Mask.
 

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

Input Mask question 2
Format Zip Code 2
City State Zip in one field 4
zip codes 1
Text File Import 1
Show error message to user 1
Allow Numeric Characters Only In A Cell 5
Format Numeric Data For Export 3

Top