[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel VB Macro coding problem.

Posted on 2009-02-20
1
Medium Priority
?
343 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:GeorgeV
1 Comment
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 23692069
You don't need the quotes. The SQL will be a string anyway.
Regards,
Rory
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question