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.
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)
sqlcode = sqlcode & ", " & "CGIBASE." & Cells(2, indx)
indx = indx + 1
sqlcode = sqlcode & " " & quotes