I have inherited a database which contains phone numbers with and without the hyphen. This has resulted in duplicate phone numbers and mistakes. The field in the table is currently set to record numbers without the hyphen. How can I reduce numbers with the hyphen to a number without or vice versa? Is there an advantage to one or the other?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Reduce Phone field (Access 2000 SR1)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Reduce Phone field (Access 2000 SR1)
- This topic has 8 replies, 4 voices, and was last updated 23 years, 5 months ago.
AuthorTopicWSPlainsman
AskWoody LoungerOctober 26, 2001 at 10:01 pm #362021Viewing 1 reply threadAuthorReplies-
WSJayden
AskWoody LoungerOctober 26, 2001 at 11:01 pm #548876Firstly, I believe that there is an advantage in not recording the hyphen. We can use input masks or format properties to control how the number are displayed when they do not have the hypehn, but if they cotnain spaces and hypehns, then we are more limited in what we can do (or at least it becomes more difficult).
So..my suggestion would be to record only the phone numbers themselves, no hyphens and no spaces.
Okay, so how can you remove all the hyphens and spaces from a field in a table? Easy. Use the function that I have supplied below (and look how it is used in the example file attached).
To use the below function, place it in a new module in the database with the data you want to modify. Make sure you take a backup (ie. copy it and call it something different) of the data that you are going to be editing, just in case something goes wrong.
You need to pass three variables to the function, all strings
The first variable is the character that you wish to remove (ie. “-“, or ” “)
The second variable is the name of the table (ie. “tblPerson”)
The third variable is the name of the field that you want to search through (ie. “PhoneNumber”)So calling the function would look something like this:
RemoveCharacter(“-“, “tblPerson”, “PhoneNumber”)
This would remove all hyphens from the PhoneNumber field in the table tblPerson.
Note that I haven’t included any error handling routines in this function, if you spell the table name or field name wrong. Just make sure you spell them right, or a funny error may occur (something like object not found in collection).
Hope that this helps
Public Function RemoveCharacter(strRemovalCharacter As String, strTableName As String, strFieldName As String)
‘===============================================================’
‘ Author: Jayden MacRae ‘
‘ Created: 27/10/2001 ‘
‘ Purpose: To remove any characters from a field in a table ‘
‘===============================================================’
Dim rstPerson As Recordset
Dim intHyphenPos As Integer
Dim strFieldValue As StringSet rstPerson = CurrentDb.OpenRecordset(strTableName, dbOpenTable)
With rstPerson
Do Until .EOF
Do
strFieldValue = .Fields(strFieldName)
intHyphenPos = InStr(1, strFieldValue, strRemovalCharacter)
If intHyphenPos > 0 Then
strFieldValue = Left(strFieldValue, intHyphenPos – 1) & _
Right(strFieldValue, Len(strFieldValue) – intHyphenPos)
End If
If strFieldValue .Fields(strFieldName) Then
.Edit
.Fields(strFieldName) = strFieldValue
.Update
End If
Loop Until intHyphenPos = 0
.MoveNext
Loop
.Close
End WithSet rstPerson = Nothing
End Function -
WSPlainsman
AskWoody Lounger -
WSJayden
AskWoody Lounger -
WScharlotte
AskWoody LoungerOctober 27, 2001 at 4:09 am #548919DAO 3.51 is the wrong version for Access 2000. A2k uses DAO 3.6. If you’re going to work with both object models (DAO and ADO), or even if you think you might, get accustomed to disambiguating your references on all model-specific objects. In other words, declare your objects as DAO.Database and DAO.Recordset to avoid confusing yourself and Access later on down the road. There are objects with the same name (like Recordset) in both models, and you can get some pretty odd compile and runtime errors if Access guesses at the wrong object model.
-
-
-
WSPlainsman
AskWoody LoungerOctober 26, 2001 at 11:49 pm #548883WOW! What a great function! I’m impressed. I did add an Nz to stringfieldvalue to handle null phone fields i.e. strFieldValue = Nz(.Fields(strFieldName)). Is there a better way to handle this or will this do? Many thanks. I am sure I will use this function many times in other databases.
-
WSJayden
AskWoody Lounger
-
WBell
AskWoody_MVPOctober 28, 2001 at 7:43 pm #549031I’ve been watching your challenges with phone numbers with some interest. We recently made a massive structural change to a database with about 300,000 phone numbers in it, and we concluded we needed to store the hyphens in it. The real driving force was that we needed to store a significant number of international numbers (not North American dialing plan), and we needed a way to indicate things like the country code, as the people entering the numbers had no clue how it should be formated. What we did was preface all international numbers with the US direct dial international code 011- and then put a – after the country code, and if there was an area code for the country, a – between it and the local number. We also let them store extensions by putting an X after the main number.
We then built some code to validate phone numbers that checked for the correct number of digits and other such things, and we prompt them with the country name when they enter a country code. Most of this came about because we had about 5% garbage in the table before we did that. Now we have almost none. Hope this gives you some additional insight.
-
WScharlotte
AskWoody LoungerOctober 29, 2001 at 1:15 am #549045When I’ve had to deal with international numbers, I only used an input mask for US and Canadian numbers and stored the mask with the data. I accepted whatever they entered for international numbers because they were too hard (read “impossible”) to validate and format. Of course, we weren’t trying to use the numbers for dialing, which would make a difference.
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
3 hours, 10 minutes ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
3 hours, 11 minutes ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
12 hours, 4 minutes ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
27 seconds ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
1 hour, 46 minutes ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
22 hours, 59 minutes ago -
Apple backports fixes
by
Susan Bradley
3 hours, 34 minutes ago -
Win 11 24H2 will not install
by
Michael1950
23 hours, 12 minutes ago -
Advice to convert MBR to GPT and install Windows 11 Pro on unsupported PC
by
Andy M
22 hours, 43 minutes ago -
Photos from iPhone to Win 10 duplicating/reformatting to .mov
by
J9438
8 hours, 23 minutes ago -
Thunderbird in trouble. Here comes Thundermail
by
Alex5723
23 hours ago -
Get back ” Open With” in context menus
by
CWBillow
1 day, 11 hours ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
3 hours, 52 minutes ago -
simple general stupid question
by
WSaltamirano
1 day, 9 hours ago -
April 2025 Office non-Security updates
by
PKCano
2 days, 2 hours ago -
Microsoft wants to hear from you
by
Will Fastie
1 day, 2 hours ago -
Windows 11 Insider Preview Build 22635.5160 (23H2) released to BETA
by
joep517
2 days, 6 hours ago -
Europe Seeks Alternatives to U.S. Cloud Providers
by
Alex5723
2 days, 11 hours ago -
Test post
by
Susan Bradley
2 days, 13 hours ago -
Used Systems to delete Temp files Gone WRONG what does this mean?
by
Deo
2 days, 15 hours ago -
SSD shuts down on its own
by
CWBillow
2 days, 7 hours ago -
OneDrive File Sharing Changes
by
David Clark
2 days, 23 hours ago -
OneDrive File Sharing Changes
by
David Clark
3 days, 1 hour ago -
Win 10 Pro 22H2 to Win 11 Pro 23H2 Conversion Guide
by
doneager
2 days, 1 hour ago -
Today is world backup day
by
Alex5723
2 days, 17 hours ago -
Windows .exe on Mint
by
Slowpoke47
3 hours, 51 minutes ago -
Reviewing your licensing options
by
Susan Bradley
11 hours, 49 minutes ago -
Apple has been analyzing your photos since September 2024
by
B. Livingston
1 hour, 40 minutes ago -
What Windows 11 24H2 offers beyond bugs
by
Lance Whitney
1 day, 18 hours ago -
Making sense of Settings in Windows 11
by
Simon Bisson
1 day, 19 hours ago
Recent blog posts
- MS-DEFCON 2: Seven months and counting
- Apple backports fixes
- April 2025 Office non-Security updates
- Microsoft wants to hear from you
- Reviewing your licensing options
- Apple has been analyzing your photos since September 2024
- What Windows 11 24H2 offers beyond bugs
- Making sense of Settings in Windows 11
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.