Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old February 21st, 2006, 08:15 PM
sadiewms
Guest
 
Posts: n/a
Default Set recordset field contents to string

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




  #2  
Old February 21st, 2006, 09:45 PM
tina
Guest
 
Posts: n/a
Default Re: Set recordset field contents to string

try

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

hth


"sadiewms" <sadiewms@gmail.com> wrote in message
news:1140551889.741615.291710@z14g2000cwz.googlegr oups.com...[color=blue]
> 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
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.