I am trying to write code that looks at a field in a recordset. I want to check a string in the RS to see if it has a hyphen or a numeric character at the end of the string.
If there is a hyphen like this 3493- I want to remove the hypen and leave 3493. If there is a letter like this 4893-A I want it to leave the string alone. Any ideas of how to achieve this? I have this code that I gleamed from another string manipulation that I was doing but I have not been successful in converting it for my current needs.
If there is a hyphen like this 3493- I want to remove the hypen and leave 3493. If there is a letter like this 4893-A I want it to leave the string alone. Any ideas of how to achieve this? I have this code that I gleamed from another string manipulation that I was doing but I have not been successful in converting it for my current needs.
Code:
Dim objDB As Database
Dim objRS As Recordset
Dim AllowedCharacters As String
Dim TempString As String
Dim ctr As Integer
AllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
Set objDB = CurrentDb()
Set objRS = objDB.OpenRecordset("JobNumbers1", dbOpenDynaset)
While Not objRS.EOF
TempString = ""
For ctr = 1 To Len(objRS![JobNumber])
If InStr(1, AllowedCharacters, _
Mid(objRS![JobNumber], ctr, 1)) <> 0 Then _
TempString = TempString & _
Mid(objRS![JobNumber], ctr, 1)
Next
With objRS
.edit
![JobNumber] = TempString
.Update
.MoveNext
End With
Wend
End Sub
Last edited: