Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Parsing one field into multiple records

Avatar of Kenneth Marks
Kenneth MarksFlag for United States of America asked on
Microsoft Access
9 Comments1 Solution772 ViewsLast Modified:

This is an addition to a previously asked question:

Everything works great except for some of the customer names has an Apostrophes within the name. I am getting this error when writing to the new table.

Run-time error 3075
Syntax error (missing operator) in query expression "Today's Shopper",'08032');'.

When I remove the Apostrophe everything works fine.

Public Function SplitUsers()
    Dim RS As DAO.Recordset
    Dim Accts() As String
    Dim I As Integer
    Dim SQL As String
    Set RS = CurrentDb().OpenRecordset("ROI2")
    Do Until RS.EOF = True
        If RS.EOF = True Then Exit Do '<-- may cause you to miss the last record.
        If InStr(1, Nz(RS![Zips Served], ""), ",") < 1 Then
            SQL = "INSERT INTO TblTempProcessing " & _
            "([Temp_ID], [Temp_Customer_Number], [Temp_Customer_Name], [Temp_Zip]) " & _
            "VALUES ('" & RS![ID] & "', '" & RS![Customer Number] & "', '" & _
                    RS![Customer Name] & "', '" & Nz(RS![Zips Served], "") & "');"
            DoCmd.SetWarnings False
            DoCmd.RunSQL SQL, False
            DoCmd.SetWarnings True
            'Split by comma into a string array
            Accts = Split(RS![Zips Served], ",")
            'Go thru array and populate final table
            For I = 0 To UBound(Accts)
                SQL = "INSERT INTO TblTempProcessing " & _
                "([Temp_ID], [Temp_Customer_Number], [Temp_Customer_Name], [Temp_Zip]) " & _
                "VALUES ('" & RS![ID] & "', '" & RS![Customer Number] & "', '" & _
                        RS![Customer Name] & "', '" & Trim(Accts(I)) & "');"
                DoCmd.SetWarnings False
                DoCmd.RunSQL SQL, False
                DoCmd.SetWarnings True
            Next I
        End If
        'Check next record
    Set RS = Nothing
End Function
Avatar of Rey Obrero (Capricorn1)
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answers