split a string by comma and break it up into rows (1 Viewer)

lala

Registered User.
Local time
Today, 00:27
Joined
Mar 20, 2002
Messages
741
i have a string that i need broken up into rows

ID EMAIL
33455 1@yahoo.com,2@yahoo.com,3@yahoo.com,4@yahoo.com,5@yahoo.com,6@yahoo.com,7@yahoo.com,8@yahoo.com

is that possible? i know how to split it and get each value, but don't know how to insert it into a table one at a time

besides inserting each value, i also have to insert the ID, so for each row i have to insert one email address and the id, and repeat it 8 times

number of email addresses is always different

thank you
 

DCrake

Remembered
Local time
Today, 05:27
Joined
Jun 8, 2005
Messages
8,632
Are you using the Split() function to copy the items into an array? If so what cod have you got in place now?
 

lala

Registered User.
Local time
Today, 00:27
Joined
Mar 20, 2002
Messages
741
Code:
Private Sub SplitTest_Click()

Const TestString As String = "1yahoo.com,2yahoo.com,3yahoo.com,4yahoo.com,5yahoo.com,6yahoo.com,7yahoo.com,8yahoo.com"

Dim strText As String
Dim strParts() As String
Dim intCounter As Integer


strParts = Split(TestString, ",")

For intCounter = LBound(strParts()) To UBound(strParts())
    MsgBox strParts(intCounter)
Next intCounter
End Sub


again, not my code, off the internet and edited
 

lala

Registered User.
Local time
Today, 00:27
Joined
Mar 20, 2002
Messages
741
the code above gives me the email addresses as it loops through the string

how do i take the first emaill address and append it to the table? bu using an append query?
and literally just loop through and do them one by one?

if so, then i know what to do, if there's a better way then i need help.
 

lala

Registered User.
Local time
Today, 00:27
Joined
Mar 20, 2002
Messages
741
i got it!!!!
as long as there's not an easier way of doing it than appending them one by one - i got it to work
 

DCrake

Remembered
Local time
Today, 05:27
Joined
Jun 8, 2005
Messages
8,632
Try This

Code:
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset(YourTableHere)

For intCounter = LBound(strParts()) To UBound(strParts())
    Rs.AddNew
    Rs(YourEmailfield) =  strParts(intCounter)
    Rs.Update
Next intCounter

Rs.Close
Set Rs = Nothing
 

lala

Registered User.
Local time
Today, 00:27
Joined
Mar 20, 2002
Messages
741
this is much faster, thank you so much!!!!!!!!!
 

jjjones009

New member
Local time
Today, 00:27
Joined
May 30, 2014
Messages
1
I have a similar issue as above, but it has caused another issue that I cannot figure out on my own. I have gotten the below code to work (thank you for helping me with that), but I cannot get the selected groupid in the groupid listbox to populate in a second column in my table duplicating for each value of the classtext string. Here is the code and I attached an image to show the current output vs. the desired output.

The classtext string that I am entering is 214, 215
Add the value that I am selecting in my groupid list box is 4

Code:
Private Sub addclasses_Click()
Dim Rs As DAO.Recordset
Dim groupid As Integer
Dim strParts() As String
Dim intCounter As Integer
strParts = Split(classtext, ",")
groupid = groupidlist.ItemData(groupid)

Set Rs = CurrentDb.OpenRecordset("LU_REPORT_GROUPING_CLASS")

For intCounter = LBound(strParts()) To UBound(strParts())
    Rs.AddNew
    Rs("CLASS_ID") = strParts(intCounter)
    Rs("REPORT_GROUPING_ID") = groupidlist.ItemData(groupid)
    Rs.Update
Next intCounter

Rs.Close
Set Rs = Nothing
End Sub
Please help me, because I have been :banghead: for too long on this.

Thank You
 

Attachments

  • output.png
    output.png
    11.8 KB · Views: 440

Users who are viewing this thread

Top Bottom