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.