ACC: Sample Function to Remove Alphas from a Numeric FieldLast reviewed: August 29, 1997Article ID: Q99938 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. This article describes how to create a sample Microsoft Access function called RemoveAlphas() to remove 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 social security number field. The following strings contain parentheses, dashes, and spaces:
"(206) 635-7050" "206-635-7050" "535-87-4529"After the RemoveAlphas() function is run, these strings will be:
"2066357050" "2066357050" "535874529"This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0
MORE INFORMATIONThe following example demonstrates how to create the RemoveAlphas() function, and how to use it either while data is being entered, or in an update query to remove nonnumeric characters from phone numbers in a table.
How to Create the RemoveAlphas() Function
How to Use the RemoveAlphas() Function in Data EntryYou can use the RemoveAlphas() function to remove dashes or parentheses while phone numbers are being typed into a field. For a field called Phone, add the following code to the AfterUpdate property to the Phone text box on a form:
Private Sub Phone_AfterUpdate() Me![Phone] = RemoveAlphas(Me![Phone]) End Sub How to Use the RemoveAlphas() Function in an Update Query
|
Additional query words: ssn hyphens
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |