sfreeman@co.mer
Sam_F
- Local time
- Today, 02:46
- Joined
- Aug 2, 2004
- Messages
- 272
In trying to assist another member, I created a simple setup.
tblValues has one field named 'Value', which holds 3 random text records, each containing one or more strings separated by a comma and a space.
Value
434534
3454534, 7888, 44fxcew, eqeew
ewrqw, 5643, art4345, 32af
The Function 'ParseText' is intended to accept each record via a simple query...
"SELECT
ParseText([Value]) AS Val1
FROM
tblValues;"
and place each value into a new table 'tblValuesNew' [identical to first table].
/************************
Public Function ParseText(strSearchString As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strWord As String
Dim strChar As String
Dim i As Integer
Dim intLen As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tblValuesNew", dbOpenTable)
strWord = ""
intLen = Len(strSearchString)
For i = 1 To intLen + 1
strChar = Mid(strSearchString, i, 1)
If strChar <> " " And strChar <> "," And strChar <> "" Then
strWord = strWord & strChar
ElseIf strWord <> "" Then
With rst
.AddNew
!Value = strWord
.Update
strWord = ""
End With
End If
Next i
strSearchString = ""
Set db = Nothing
Set rst = Nothing
End Function
/************************
The expected recordset should contain 9 records:
434534
3454534
7888
44fxcew
eqeew
ewrqw
5643
art4345
32af
For some reason, the query seems to process the first record twice thereby inserting the values, one or several, twice.
Anyone?
tblValues has one field named 'Value', which holds 3 random text records, each containing one or more strings separated by a comma and a space.
Value
434534
3454534, 7888, 44fxcew, eqeew
ewrqw, 5643, art4345, 32af
The Function 'ParseText' is intended to accept each record via a simple query...
"SELECT
ParseText([Value]) AS Val1
FROM
tblValues;"
and place each value into a new table 'tblValuesNew' [identical to first table].
/************************
Public Function ParseText(strSearchString As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strWord As String
Dim strChar As String
Dim i As Integer
Dim intLen As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tblValuesNew", dbOpenTable)
strWord = ""
intLen = Len(strSearchString)
For i = 1 To intLen + 1
strChar = Mid(strSearchString, i, 1)
If strChar <> " " And strChar <> "," And strChar <> "" Then
strWord = strWord & strChar
ElseIf strWord <> "" Then
With rst
.AddNew
!Value = strWord
.Update
strWord = ""
End With
End If
Next i
strSearchString = ""
Set db = Nothing
Set rst = Nothing
End Function
/************************
The expected recordset should contain 9 records:
434534
3454534
7888
44fxcew
eqeew
ewrqw
5643
art4345
32af
For some reason, the query seems to process the first record twice thereby inserting the values, one or several, twice.
Anyone?