Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36

    Verifying phone numbers

    Hi,

    I have a form for entering records into a table, which includes a phone number field. I can't use an input mask because the data entry is done by copying and pasting from Word documents, websites, and the like. Therefore the data is entered in various formats, e.g. (xxx) xxx-xxxx, (xxx)xxx-xxxx, xxx-xxx-xxxx, and so on.

    How can I eliminate all spaces and symbols, and store the fields as numerical data only, so that they can easily be compared and checked for duplicates?



    I need the simplest solution possible because time is of the essence.

    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    The field should be a text (string) field and creating a procedure that would strip out all but the 0-9 values should be easy.

  3. #3
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    Okay, thanks.

    I figured that was the direction I need to go, but I have never actually created procedures in Access, so I need some advice on how to do that. I'm using the 2010 version.

    Thanks again.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here's a function and a test procedure that may be helpful.
    I'm removing any ( ) or - and spaces. The resulting string must be all digits and 10 chars long. You can adjust as you wish. Good luck.
    I'm using Acc2003 on XP

    Public Function PNum(wrkValue As String) As String
    Dim strValue As String
    strValue = wrkValue
    On Error GoTo PNum_Error

    strValue = Replace(strValue, "(", "")
    strValue = Replace(strValue, ")", "")
    strValue = Replace(strValue, "-", "")
    strValue = Replace(strValue, " ", "")
    If (Len(strValue) = 10 And Not strValue Like "*[!0-9]*") Then
    PNum = wrkValue & " resolves to valid phone " & strValue
    Else
    PNum = wrkValue & " Fail ***"
    End If
    On Error GoTo 0
    Exit Function

    PNum_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure PNum of Module AWF_Related"

    End Function
    test procedure

    Sub testPNum()
    Debug.Print PNum("(413)567-1271")
    Debug.Print PNum("(713525-1471")
    Debug.Print PNum("(713a425 1551")
    Debug.Print PNum(" 813)425 1431")
    Debug.Print PNum(" 813 6251781")
    Debug.Print PNum(" 8 13 6251781")
    Debug.Print PNum(" 8 1 3 6251x781")
    End Sub

  5. #5
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    I'm not sure I even know where to enter the code... This is the most involved database I've created in Access. Most of my experience is in Oracle. If you could direct me on where to look that would also be a help

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Put this is a Standard module:
    Code:
    Public Function NumericString(strIn As String) As String
    '-- Filter all but numeric characters from strIn
       Dim Marker As Long
       If Len(strIn & "") > 0 Then
          For Marker = 1 To Len(strIn)
             NumericString = NumericString & FilterIt(Mid(strIn, Marker, 1))
          Next Marker
       Else
          '-- Do not attempt any conversion
          MsgBox "Invalid entry for NumericString filter", vbExclamation + vbOKOnly
       End If
    End Function
    Public Function FilterIt(InChr As String) As String
    '-- Strip all but numeric characters
       Select Case InChr
          Case "0" To "9"
             FilterIt = InChr     '-- Valid character
          Case Else
             FilterIt = ""        '-- Strip this character
       End Select
    End Function

  7. #7
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    Okay, now I'm getting somewhere. I have entered the code in a module. Now where to I call the procedure from?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You could put it in the BeforeUpdate event of the control:
    Me.ControlName.Text = NumericString(Me.Controlname.Text)
    ...using YourControlName of course.
    You will also want to put it in an update query of the existing table to clean up the current records.

  9. #9
    waqas is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    117

    Wink

    hi

    call it in command button click event like below

    Private Sub Command3_Click()
    Me.txtget.Value = NumericString(Me.txtph.Value)
    End Sub
    txtph where you past different ph number
    second txtget is where you will get only digits

  10. #10
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    I'm making progress.

    I ran the update query, and the phone number column is clean of symbols now! So the procedure works.

    The problem now is with the Before Update event handler. It runs the procedure but then won't insert the new record. It gives me a runtime error 2115.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Change the BeforeUpdate code to:
    Me.ControlName = NumericString(Me.Controlname)
    ...which just removes the .Text from both entries. It will default to the .Value property instead.

  12. #12
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    I still get the same error, and now the text in the control does not change.

    I love this forum... such fast responses!

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    This is in the BeforeUpdate event right?

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Well darn. I guess you will need to move this:
    Me.ControlName = NumericString(Me.Controlname)
    ...to the *AfterUpdate* event and see what you think. I tested it in ac2010 and it works.

  15. #15
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    YES! It works now. Thank you so MUCH!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dashes in phone numbers and zip codes
    By JMack in forum Access
    Replies: 8
    Last Post: 11-18-2013, 01:56 PM
  2. Syntax to have phone numbers display
    By Juan4412 in forum Queries
    Replies: 7
    Last Post: 09-09-2011, 06:41 AM
  3. Custom format for phone#
    By SmokingMan in forum Access
    Replies: 4
    Last Post: 08-02-2010, 10:41 PM
  4. Phone number format
    By ManvinderKaur in forum Access
    Replies: 1
    Last Post: 06-24-2010, 08:07 AM
  5. Dialing Phone Numbers From Access
    By obrmb in forum Forms
    Replies: 0
    Last Post: 06-11-2009, 12:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums