[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

Conditional formatting of UK telephone numbers

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
BorderBox
Asked:
BorderBox
  • 4
  • 2
3 Solutions
 
Rey Obrero (Capricorn1)Commented:
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
 
BorderBoxAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
<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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BorderBoxAuthor Commented:
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
 
BorderBoxAuthor Commented:
[Groan] Sorry about the mistype on "definitely".

Any thoughts on the three queries?  I would be grateful for your help.
0
 
BorderBoxAuthor Commented:
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now