Syntax error....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irisbu
    New Member
    • Jan 2008
    • 19

    #1

    Syntax error....

    I have this code:
    Code:
    Set rs = db.OpenRecordset("SELECT * FROM expressions order by heb WHERE '" & TextBox2.Text & "' = InStr(![heb], TextBox1.Text)")
    Can someone show me where the syntax error is and what is the correct way to write this line?

    I am desperate!!! :-(
    Last edited by NeoPa; Feb 17 '09, 01:41 PM. Reason: Please use the [CODE] tags provided
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    This post appears to be a duplicate of post 25 of this thread, a thread which is now closed to your satisfaction. Please do not double-post your questions as this wastes the time of the experts involved.

    You also provide no clue as to what error you are getting or the context of whatever 'this code' is.

    A revised version of your code which may have more of a chance of working is shown below.

    Code:
    Set rs = db.OpenRecordset("SELECT * FROM expressions WHERE [" & TextBox2.Text & "] = " & InStr(![heb], TextBox1.Text) & " ORDER BY heb;")
    I'd be surprised if just getting the syntax right means it will work straight away, however, as it may be OK for syntax and still not mean anything to Access...

    -Stewart

    Comment

    • irisbu
      New Member
      • Jan 2008
      • 19

      #3
      Prepare to be surprised

      The code is now working beautifully.... I hope I won't have to eat my hat later on... but it's working for now.

      Thank you for your reply.

      Iris

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Code:
        = InStr(![heb], ...
        is likely to suffer too, as you have an orphaned bang (!) within your SQL string. This syntax is only valid within a With clause of VBA. Not in SQL.

        Comment

        • irisbu
          New Member
          • Jan 2008
          • 19

          #5
          I have changed the

          ![heb] - to -
          instr(heb, '" & TextBox1.Text & "')

          so it's OK.

          Thank you for your kindness and for your caring.

          Have a great day!

          Iris

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            No worries,

            and Welcome to Bytes!

            Comment

            Working...