I am trying to remove a space from a text field [Name] in a table called RegText. The text comes in imported from a text file in this form: LastName, FirstName. After executing a function module called RemoveSpace, I was hoping to remove the space after the comma so it now becomes LastName,FirstName. However, when I call the function using a macro, my Access 2000 stops responding. Here is the code which I adapted from some users in this forum:
Function RemoveSpace()
On Error GoTo TrapError
Dim DAO_DB As DAO.Database
Dim DAO_RS As DAO.Recordset
Dim strTemp As String, strField As String
Dim x As Integer
Set DAO_DB = CurrentDb()
Set DAO_RS = DAO_DB.OpenRecordset("RegText", dbOpenDynaset)
While Not DAO_RS.EOF
If Not IsNull(DAO_RS![NAME]) Then
strField = DAO_RS![NAME]
For x = 1 To Len(strField)
If Mid$(strField, x, 1) = " " Then
strTemp = strTemp & Mid$(strField, x, 1)
End If
Next x
With DAO_RS
.Edit
![NAME] = strTemp
.Update
.MoveNext
End With
End If
Wend
ExitHere:
Exit Function
TrapError:
MsgBox Err.Description
Resume ExitHere
End Function
What am I doing wrong?
Function RemoveSpace()
On Error GoTo TrapError
Dim DAO_DB As DAO.Database
Dim DAO_RS As DAO.Recordset
Dim strTemp As String, strField As String
Dim x As Integer
Set DAO_DB = CurrentDb()
Set DAO_RS = DAO_DB.OpenRecordset("RegText", dbOpenDynaset)
While Not DAO_RS.EOF
If Not IsNull(DAO_RS![NAME]) Then
strField = DAO_RS![NAME]
For x = 1 To Len(strField)
If Mid$(strField, x, 1) = " " Then
strTemp = strTemp & Mid$(strField, x, 1)
End If
Next x
With DAO_RS
.Edit
![NAME] = strTemp
.Update
.MoveNext
End With
End If
Wend
ExitHere:
Exit Function
TrapError:
MsgBox Err.Description
Resume ExitHere
End Function
What am I doing wrong?