Excel VB Macro coding problem.

I am writing a VBA Macro that will allow user to create a custom query to our AS400 for a file by selecting which fields to select for the query.  I am having a problem creating the code once the field names have been selected.  The code needs to end up looking like this:
Sql = "SELECT CMASCP.CPCUS, CMASTR.CU_NME, CMASCP.CPDIV, CMASCP.CP_CID, CMASCP.CPCDTE, CMASCP.CPCSMN, CMASCP.CPTYP, CMASCP.CPCDET, CMASCP.CPSEQ " & _
"
How do I get the front quotation mark and end quotation marks to appear in the code.  I have included my code below that is not working.
Thanks
I have set the variable quotes equal to " by setting a cell equal to that value and then making quotes equal to that cell.  The loop reads through a sheet with values for field names entered.
sqlcode = quotes & "SELECT "
Do While Cells(1, indx) <> ""
    If indx = 1 Then
        sqlcode = sqlcode & "CGIBASE." & Cells(2, indx)
    Else
        sqlcode = sqlcode & ", " & "CGIBASE." & Cells(2, indx)
    End If
    indx = indx + 1
Loop
sqlcode = sqlcode & " " & quotes

Open in new window

GeorgeVAsked:
Who is Participating?
 
Rory ArchibaldCommented:
You don't need the quotes. The SQL will be a string anyway.
Regards,
Rory
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.