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?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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, 7 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
-
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
55 minutes ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
6 hours, 11 minutes ago -
Stop the OneDrive defaults
by
CWBillow
1 hour, 43 minutes ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
11 hours, 39 minutes ago -
X Suspends Encrypted DMs
by
Alex5723
13 hours, 51 minutes ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
14 hours, 9 minutes ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
14 hours, 46 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
15 hours, 23 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
3 hours, 33 minutes ago -
Enabling Secureboot
by
ITguy
10 hours, 33 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
23 hours, 17 minutes ago -
No more rounded corners??
by
CWBillow
19 hours, 6 minutes ago -
Android 15 and IPV6
by
Win7and10
8 hours, 51 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
1 day, 11 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
1 day, 14 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
1 day, 8 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
1 day, 21 hours ago -
May preview updates
by
Susan Bradley
1 day, 9 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
1 day ago -
Just got this pop-up page while browsing
by
Alex5723
1 day, 13 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
1 day, 10 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
13 hours, 6 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days, 13 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
9 hours, 53 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
3 days, 1 hour ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
23 hours, 49 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days, 14 hours ago -
Another test post
by
gtd12345
3 days, 15 hours ago -
Connect to someone else computer
by
wadeer
3 days, 9 hours ago -
Limit on User names?
by
CWBillow
3 days, 12 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.