Keith
Registered User.
- Local time
- Today, 02:17
- Joined
- May 21, 2000
- Messages
- 129
I have a table(tblMaster) with a field(SUBS1) that contains a string of names seperated by a space. I want to split the field into names and put each name together with the ID field into a separate table(tblBoatMember). I get an 'Invalid use of Null' error on the line vArr = Split(rsOrig("SUBS1"), " ") I have used the code a long time ago and it worked albeit with different tables. The Code compiles ok. Its probably something obvious but the grey matter is getting a bit old now. 
The code i'm using is:

The code i'm using is:
Code:
Public Function BreakToWords()
Dim rsOrig As DAO.Recordset
Dim rsNew As DAO.Recordset
Dim vArr As Variant 'array to hold the split phrase
Dim i As Integer 'counter
Set rsOrig = CurrentDb.OpenRecordset("tblMaster")
Set rsNew = CurrentDb.OpenRecordset("tblBoatMember")
If rsOrig.RecordCount <> 0 Then
'loop the rsOrig records
rsOrig.MoveFirst
While Not rsOrig.EOF
'split the phrase on a space delimiter
[COLOR="Red"]vArr = Split(rsOrig("SUBS1"), " ")[/COLOR]
'loop the array (words) and add to rsNew
For i = 0 To UBound(vArr)
With rsNew
.AddNew
.Fields("ID") = rsOrig("ID")
.Fields("Boat") = vArr(i)
.Update
End With
Next
rsOrig.MoveNext
Wend
End If
rsOrig.Close
rsNew.Close
Set rsOrig = Nothing
Set rsNew = Nothing
End Function