[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Conditional formatting of UK telephone numbers

Posted on 2008-06-26
6
Medium Priority
?
446 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 1200 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 1200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

649 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