By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,968 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,968 IT Pros & Developers. It's quick & easy.

Set recordset field contents to string

P: n/a
Hi!

I'm trying to loop through records in a table, split the contents and
insert each subsequent string in the array into a new table. I need to
determine how to cast the current record in the record set as a string.
I'm very very new to access and VB and any help would be greatly
appreciated!

Below is what I have so far (see question marks in code...):

Public Sub splitinsert()

'Declare strings
Dim narratorStr As String
Dim anlcid As String
Dim rst As Recordset
Dim dbs As Database

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT Narrator from Denaina")
'Declare Array
Dim Arr()

'Loop through records in Denaina table until end of file
With rst
.MoveFirst
While Not .EOF

'set field to string
narratorStr = ?????

'if the string has semicolon, then split
If InStr(narratorStr, ";") Then

'Set Array to Split field
Arr() = Split(narratorStr, ";")

For Each I In Arr
Arr(I) = I
DoCmd.RunSQL "INSERT INTO person_test (person_test)
values(I)"
Next I
Else
Dim SQL As String
SQL = "INSERT INTO person_test (person_test) values('" &
narratorStr & "')"
DoCmd.RunSQL SQL
'End semicolon if
End If

.MoveNext
Wend
End With
End Sub

Feb 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
try

'set field to string
narratorStr = rst("Narrator")

hth
"sadiewms" <sa******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi!

I'm trying to loop through records in a table, split the contents and
insert each subsequent string in the array into a new table. I need to
determine how to cast the current record in the record set as a string.
I'm very very new to access and VB and any help would be greatly
appreciated!

Below is what I have so far (see question marks in code...):

Public Sub splitinsert()

'Declare strings
Dim narratorStr As String
Dim anlcid As String
Dim rst As Recordset
Dim dbs As Database

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT Narrator from Denaina")
'Declare Array
Dim Arr()

'Loop through records in Denaina table until end of file
With rst
.MoveFirst
While Not .EOF

'set field to string
narratorStr = ?????

'if the string has semicolon, then split
If InStr(narratorStr, ";") Then

'Set Array to Split field
Arr() = Split(narratorStr, ";")

For Each I In Arr
Arr(I) = I
DoCmd.RunSQL "INSERT INTO person_test (person_test)
values(I)"
Next I
Else
Dim SQL As String
SQL = "INSERT INTO person_test (person_test) values('" &
narratorStr & "')"
DoCmd.RunSQL SQL
'End semicolon if
End If

.MoveNext
Wend
End With
End Sub

Feb 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.