Public Function CleanupPhonenos()
' thread705-583907 By John Barnett (tek-tips handle jrbarnett), 23 June 2003
Dim intCount As Integer
Dim strSource As String
Dim strTarget As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Tablename") ' must change this to name of table which data is stored in
Do While Not rs.EOF ' loop through each record in the table
strTarget = "" ' reset for each loop
strSource = rs!Phonenumber ' extract the phoneno field
For intCount = 1 To Len(strSource)
' move everything up
If IsNumeric(Mid$(strSource, intCount, 1)) Then
strTarget = strTarget & Mid$(strSource, intCount, 1) ' copy anything that is numeric across to the temp
End If
Next
Debug.Print "Replacing " & strSource & " with " & strTarget ' comment out if you don't want running commentary.
rs.Edit
rs!Phonenumber = strTarget ' and save it back in the table
rs.Update
rs.MoveNext ' move to next record
Loop
Debug.Print "Finished"
rs.Close
Set db = Nothing
End Function