Results 1 to 5 of 5

Thread: Syntax error sorting query

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    5
    I am trying to implement a sort function for displaying query results in a MSHFlexgrid from an access database. The user selects which field they would like to sort by from a list box. I am getting a syntax error on the following line:


    SelPM = "SELECT * FROM Pattern ORDERED BY " + Selected + ";"

    I have also tried:
    SelPM = "SELECT * FROM Pattern ORDERED BY """ + Selected + """;"

    and a few other combinations.

    The variable 'Selected' is specified by the user by filling in the sort dialog box. The proper value is being put into the 'Selected' variable, I can see it in the debugger. Any ideas would be appreciated. Thank you.

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    The syntax is ORDER BY not ORDERED BY, also instead of using the + to concatenate strings use the & symbol and I would also suggest putting Single quotes (') around the string unless you expect the value to inclued single quotes.

    Code:
    SelPM = "SELECT * FROM Pattern ORDER BY '" & Selected & "';"
    or if you expect the variable Selected to include single quotes then use this instead, Chr(34) returns a double quote......

    Code:
    SelPM = "SELECT * FROM Pattern ORDERED BY " & Chr(34) &  Selected & Chr(34) &  ";"
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    5
    Thank you. It works now. I had to leave out the single quotes though.?.

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Yeah, sorry about that, you only need the quotes around WHERE statements and the like, it was about 3 AM when I wrote that, sorry.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    5
    No problem, I appreciate the help. I'm only about 6 weeks into programming but I'm having fun.

Posting Permissions

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



Click Here to Expand Forum to Full Width