Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Space in SQL (MS Access 2003)

    I had a query within a listbox that I am now putting externally as code. It had a space created between columns with the AS Persons being a dummy space, just to break up columns shown in a listbox.

    mysql = "SELECT * FROM (SELECT TOP 5 TXMASTERS.ID1, TXCLIPS.ID2, " " AS Persons, TXCLIPS.Comments,"

    Problem is the line above throws an error saying expected end statement, highlighting on my AS Persons part. Can someone tell me what the rule is here to fix it. Many thanks

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Space in SQL (MS Access 2003)

    If you want to include a quoted string within another quoted string, you must either use single quotes or double the double quotes. Otherwise VBA gets confused - it thinks that the string ends when it encounters a second double quote.
    So either
    <code>
    mysql = "SELECT * FROM (SELECT TOP 5 TXMASTERS.ID1, TXCLIPS.ID2, ' ' AS Persons, TXCLIPS.Comments,"
    </code>
    or
    <code>
    mysql = "SELECT * FROM (SELECT TOP 5 TXMASTERS.ID1, TXCLIPS.ID2, "" "" AS Persons, TXCLIPS.Comments,"
    </code>
    See <!post=Chr() function and quotes within strings (all),230516>Chr() function and quotes within strings (all)<!/post> for a more detailed explanation and yet another option.

  4. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Space in SQL (MS Access 2003)

    Many thanks Hans, sorted and explained very well. Sorry for delay getting back, I corrupted my boot.ini on my PC and had two days of it refusing to boot up. Won't do that again.Best regards

Posting Permissions

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