Solved

Conditional formatting of UK telephone numbers

Posted on 2008-06-26
6
441 Views
Last Modified: 2013-12-25
I manage a membership database for a professional organisation.   There are five different telephone fields (OfficePhone, Fax, DirectPhone, CellPhone and HomePhone).   For consistency I keep all the numbers as plain strings of continuous numbers but I use an input mask (00\ 000" - "000\ 000;;_) on the tables, queries and forms to format the numbers like 01 234 - 567 890.   This works for many of the numbers but unfortunately ih the UK we have different formats (and number lengths) in different parts of the country and I get the occasional complaint from people who do not like my universal format.   For example, Londoners like to be 02x xxxx xxxx and Geordies like to be 0191 xxx xxxx, and so on.
As far as I can see the conditional rules are:
For 01
If number = 011? - format = xxxx xxx xxxx
If number = 01?1  format = xxxx xxx xxxx
Else  format = xx xxx xxx xxx
For 02
If number = 02? then format = xxx xxxx xxxx
03 = xxx xxxx xxxx
05 = xxx xxxx xxxx
07 = xx xxx xxx xxx
08 = xxxx xxx xxxx
I am presuming that conditional input masks or conditional formatting are not possible so I will have to hold the numbers as strings containing the spaces which format the numbers.
If that is correct then ideally, what I would like is two things:
1   an EXIT MACRO for edited telephone fields which checks the contents and corrects as necessary (Deleting all spaces and then reinserting as necessary)
2   an UPDATE QUERY which I can run globally on each telephone field once a year (before I do the annual yearbook) to check and correct all the numbers.
My knowledge of Access and programming is not up to these tasks.  Can anyone help me solve this issue quickly please?
0
Comment
Question by:BorderBox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 300 total points
ID: 21875042
you will need a function to do that, place this codes in a module

function getCorrectFormat(sTel as string) as string

select case left(stel,2)
     case "01","08"
         getCorrectFormat=Format(stel,"@@@@ @@@ @@@@")
     case "02","03","05"
         getCorrectFormat=Format(stel,"@@@ @@@@ @@@@")

     case "07"
         getCorrectFormat=Format(stel,"@@ @@@ @@@ @@@")



end select

end function
0
 

Author Comment

by:BorderBox
ID: 21877353
That looks really promising .   Am I right in thinking that just changes the format and that the data is still just a string of numbers without spaces?
But please forgive my ignorance.  How do I apply that module to a control on a form?   Can I also apply that module globally to all telephone fields in a database?
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 300 total points
ID: 21877385
<Am I right in thinking that just changes the format and that the data is still just a string of numbers without spaces?>
 yes, if you don't update the field using the function,
<Can I also apply that module globally to all telephone fields in a database?>
Yes

to test - create a query like this

select  OfficePhone, getCorrectFormat([OfficePhone]) from TableName
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BorderBox
ID: 21891545
Thanks.   I am definitley making progress.

How do I apply that module to a control on a form?
How would I use the function to update the field rather than just formatting it?
The test for 01 numbers involves four characters.  How do I combine that with the test for two characters.   I have tried converting the string to 4 and using "?" and "#" but without success.
0
 

Author Comment

by:BorderBox
ID: 21900665
[Groan] Sorry about the mistype on "definitely".

Any thoughts on the three queries?  I would be grateful for your help.
0
 

Accepted Solution

by:
BorderBox earned 0 total points
ID: 22041812
No further response so I have:
1    Used the following code
Function getPhoneFormat(sTel As String) As String
Select Case Left(sTel, 4)
     Case "0110" To "0119"
        getPhoneFormat = Format(sTel, "@@@@  @@@  @@@@")
     Case "0121", "0131", "0141", "0151", "0161", "0171", "0181", "0191"
        getPhoneFormat = Format(sTel, "@@@@  @@@  @@@@")
     Case "0200" To "0699"
         getPhoneFormat = Format(sTel, "@@@  @@@@  @@@@")
     Case "0800" To "0899"
         getPhoneFormat = Format(sTel, "@@@@  @@@  @@@@")
     Case Else
         getPhoneFormat = Format(sTel, "!&& &&&  &&&  &&&&&")
End Select
End Function

2   Since I don't know how to get the module function to work on exit from a form control I have arranged for the Autoexec macro to edit all the telephone fields by deleting all the spaces and then reapplying the formatting module.  Now even if the user makes a mess of the formattiing it will be corrected on the next opening.   No doubt very clumsy but the best I could manage.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question