HOW TO: Sample Function to Remove Alpha Characters from a Numeric Field in Access 2000
This article was previously published under Q210537
This article has been archived. It is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.
IN THIS TASK
This article shows you how to create a sample user-defined functionnamed RemoveAlphas() that removes alpha, or nonnumeric, characters from an alphanumeric string. All nonnumeric characters will be removed.
A common use for the RemoveAlphas() function is to remove the parentheses, dashes, and spaces from a telephone number or a social security number field. For example, the following strings contain parentheses, dashes, and spaces:
"(206) 635-7050"After you run the RemoveAlphas() function, these strings will look as follows:
"2066357050"The following example demonstrates how to create the RemoveAlphas()function, and how to use it, either while someone is entering data, or in an update query to remove nonnumeric characters from phone numbers in atable.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. back to the top
How to Create the RemoveAlphas() Function
- Create a new module.
- Type the following function in the Module window:
Function RemoveAlphas (ByVal AlphaNum as Variant) Dim Clean As String Dim Pos, A_Char$ Pos = 1 If IsNull(AlphaNum) Then Exit Function For Pos = 1 To Len(AlphaNum) A_Char$ = Mid(AlphaNum, Pos, 1) If A_Char$ >= "0" And A_Char$ <= "9" Then Clean$ = Clean$ + A_Char$ End If Next Pos RemoveAlphas = Clean$End Function
- Save the module with any unique name.
How to Use the RemoveAlphas() Function in Data EntryYou can use the RemoveAlphas() function to have dashes or parentheses removed while someone is typing phone numbers into a field.
For a field called Phone, add the following code to the AfterUpdateproperty to the Phone text box on a form:
Private Sub Phone_AfterUpdate() Me![Phone] = RemoveAlphas(Me![Phone])End Sub
back to the top
How to Use the RemoveAlphas() Function in an Update Query
- Create a new query based on the table with the phone number field.
- Place the phone number field in the first column of the query grid.
- On the Query menu, click Update.
- In the Update To row, enter the following for a field named Phone:RemoveAlphas([Phone])
- Run the query.
inf ssn hyphens
Article ID: 210537 - Last Review: 12/05/2015 11:33:55 - Revision: 2.2
Microsoft Access 2000 Standard Edition
- kbnosurvey kbarchive kbhowto kbhowtomaster kbprogramming KB210537