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
-
7 tips to get the most out of Windows 11
by
Alex5723
2 hours, 32 minutes ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
2 hours, 14 minutes ago -
I installed Windows 11 24H2
by
Will Fastie
6 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
3 hours, 14 minutes ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
1 hour, 37 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
3 hours, 27 minutes ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
4 hours, 48 minutes ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
16 hours, 8 minutes ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
20 hours, 30 minutes ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
1 day, 5 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
7 hours, 19 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
13 hours, 28 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
1 day ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
2 days, 15 hours ago -
50 years and counting
by
Susan Bradley
6 hours, 27 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 22 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
3 days, 2 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
3 days, 2 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
3 days, 3 hours ago -
OneNote and MS Word 365
by
CWBillow
3 days, 4 hours ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
3 days, 5 hours ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
3 days, 5 hours ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
20 hours, 38 minutes ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
3 days, 16 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
3 days, 16 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
4 days, 1 hour ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
3 days, 13 hours ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
2 days, 14 hours ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
4 days, 10 hours ago -
Apple backports fixes
by
Susan Bradley
3 days, 17 hours ago
Recent blog posts
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.