MS Access: Extract Special characters only to a new column

I stuck up with a peculiar access task to extract only special characters available in the given string. Usually we always remove junk characters and normalize the data eliminating special chars. But here I needed to extract junk and put them in to the adjacent column.I achieved it by developing this below code.
Public Sub ExtrctspecialCharsOnly()
Dim n As Integer
Dim tbl As TableDef, fld As Field
Set db = CurrentDb
Dim str(7) As String

Dim i As Integer
db.Execute "UPDATE Table1 SET SpecialChars= len([InputString])"
db.Execute "UPDATE Table1 SET SpecialChars= '0' WHERE (((SpecialChars) Is Null))"
n = DMax("CInt([SpecialChars])", "Table1")
db.Execute "UPDATE Table1 SET SpecialChars= ''"
db.Execute "UPDATE Table1 SET InputString = trim([InputString])"
For i = 1 To n
db.Execute "UPDATE Table1 SET SpecialChars= [SpecialChars]+Mid([InputString]," & i & ",1) WHERE ((Mid([InputString]," & i & ",1) Not Like '*[^a-z]*') and Mid([InputString]," & i & ",1) Not Like '*[^0-9]*')"
Next i

End Sub

No comments:

Post a Comment