Apply an Input Mask to already entered data?

K

Ksanders

Hi. I was wondering if there was a way to apply an input mask to already
entered data in a table that follows the format of the input mask?
 
F

fredg

Hi. I was wondering if there was a way to apply an input mask to already
entered data in a table that follows the format of the input mask?

Do you mean you have data stored in the table as, for example,
123456789 and you wish to change the data to 123-45-6789 so that
existing data is in the same form as newly entered data?

You can run an Update query:

Update YourTable Set YourTable.FieldName =
Format([FieldName],"@@@-@@-@@@@")

After you run this update query, you can set an Input Mask on the form
control to
000\-00\-0000;0;_

Of course you need to change the above query and mask to whatever your
actual needs are.
 
J

John Spencer

Also be careful that you filter out records that already are in your formatted
version. IF you don't you might end up with extra dashes

For instance
Format("12345-12-12","@@@@@-@@-@@") returns --> 12345--1-2-12
while
Format("123451212","@@@@@-@@-@@") returns --> 12345-12-12

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Hi. I was wondering if there was a way to apply an input mask to already
entered data in a table that follows the format of the input mask?

Do you mean you have data stored in the table as, for example,
123456789 and you wish to change the data to 123-45-6789 so that
existing data is in the same form as newly entered data?

You can run an Update query:

Update YourTable Set YourTable.FieldName =
Format([FieldName],"@@@-@@-@@@@")

After you run this update query, you can set an Input Mask on the form
control to
000\-00\-0000;0;_

Of course you need to change the above query and mask to whatever your
actual needs are.
 
K

Klatuu

This will fix it:
Assume SomeField = "12345-12-12"

FixedUp: Format(Replace(SomeField,"-",""),"@@@@@-@@-@@")

--
Dave Hargis, Microsoft Access MVP


John Spencer said:
Also be careful that you filter out records that already are in your formatted
version. IF you don't you might end up with extra dashes

For instance
Format("12345-12-12","@@@@@-@@-@@") returns --> 12345--1-2-12
while
Format("123451212","@@@@@-@@-@@") returns --> 12345-12-12

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Hi. I was wondering if there was a way to apply an input mask to already
entered data in a table that follows the format of the input mask?

Do you mean you have data stored in the table as, for example,
123456789 and you wish to change the data to 123-45-6789 so that
existing data is in the same form as newly entered data?

You can run an Update query:

Update YourTable Set YourTable.FieldName =
Format([FieldName],"@@@-@@-@@@@")

After you run this update query, you can set an Input Mask on the form
control to
000\-00\-0000;0;_

Of course you need to change the above query and mask to whatever your
actual needs are.
 

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