+ Reply to Thread
Results 1 to 7 of 7

SQL Code does not fit in one line in Excel VBA, automatically moves down one line

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    Hello,

    I have a big SQL Code which does not fit in one line in Excel VBA. When I try to insert it, the Microsoft Basic Visual Editor automatically moves down by one line the code and put an "" at the end of the first line.
    Example, lets say here is my SQL code, which is big, but I will put a sample:
    sSQL = "SELECT ... "

    When I try to add the rest of the code it automatically moves down to below line, does not allow me to continue, as the "" is automatically inserted at the end. Is there a way to prevent this from happening? Maybe concatenating the SQL code? how should I do that?

    Here is my code, if needed, but I do not think it will be needed:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    you must split the SQL into multiple strings
    Please Login or Register  to view this content.
    for instance or repeatedly concatenate new strings with the current variable
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    Have you tried building the query into a string variable, piece by piece, and then passing the string variable rather than just a text string?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    JosephP I tried your first option it did not work when I put WHERE in a different line. It says there is no WHERE statement.... Now, I will try your second option.

    TMShucks I have not treid that, how can I do that, please?

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    the first option does work if you write it as it was posted ;-)

  6. #6
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    I am really sorry JosephP I see where is the issue. There was no space between the WHERE and its above line. Thank you so much!!!!!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,364

    Re: SQL Code does not fit in one line in Excel VBA, automatically moves down one line

    My suggestion was basically the same as Joseph's part 2, but he gave an example.


    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1