syntax error in select query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelesh kumar
    New Member
    • Mar 2007
    • 44

    #1

    syntax error in select query

    sir,
    suppose if the question is how many stations are there ,then if i give some word matching the question in table in the textbox named keyword ,i want to get that question
    docmd.applyfilt er "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "
    please help me
    thanks in advance
  • kepston
    Recognized Expert New Member
    • May 2007
    • 97

    #2
    Originally posted by neelesh kumar
    sir,
    suppose if the question is how many stations are there ,then if i give some word matching the question in table in the textbox named keyword ,i want to get that question
    docmd.applyfilt er "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "
    please help me
    thanks in advance
    You appear to be misusing Applyfilter

    Code:
    DoCmd.ApplyFilter(Queryname)
    or

    Code:
    DoCmd.ApplyFilter , "[question] like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "

    Comment

    • neelesh kumar
      New Member
      • Mar 2007
      • 44

      #3
      SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like ' * '" & [Forms]![frmsetquestions]!keyword & "' * '"
      DoCmd.ApplyFilt er SrcSQL4
      still giving syntax error.
      please help me

      Comment

      • kepston
        Recognized Expert New Member
        • May 2007
        • 97

        #4
        Originally posted by neelesh kumar
        SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like ' * '" & [Forms]![frmsetquestions]!keyword & "' * '"
        DoCmd.ApplyFilt er SrcSQL4
        still giving syntax error.
        please help me
        You must use a SAVED query or just the WHERE clause (but without the WHERE keyword).

        Comment

        • neelesh kumar
          New Member
          • Mar 2007
          • 44

          #5
          that query sntax is wrong sir
          thats what i am asking.
          please tell the correct query

          Comment

          • kepston
            Recognized Expert New Member
            • May 2007
            • 97

            #6
            Try putting a semi-colon ; at the end of the statement within your quotes

            Comment

            • JConsulting
              Recognized Expert Contributor
              • Apr 2007
              • 603

              #7
              Originally posted by neelesh kumar
              that query sntax is wrong sir
              thats what i am asking.
              please tell the correct query

              How about

              Code:
              "SELECT tblexam.*, tblexam.question FROM tblexam WHERE tblexam.question like * '" & [Forms]![frmsetquestions]!keyword & "'*;"

              Comment

              • neelesh kumar
                New Member
                • Mar 2007
                • 44

                #8
                sir,
                i wrote what u told.
                but still it is giving syntax error. My head is killing.
                From 3days i am working on that query.
                please help me.
                what i tried is
                SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like * '" & [Forms]![frmsetquestions]!keyword & "'*;"
                SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like ' * '" & [Forms]![frmsetquestions]!keyword & "'* ';"
                SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.questio n like "* '" & [Forms]![frmsetquestions]!keyword & "'*";"
                DoCmd.ApplyFilt er (SrcSQL4)
                with out semicolon at the end, also i tried all above
                thanks in advance

                Comment

                • kepston
                  Recognized Expert New Member
                  • May 2007
                  • 97

                  #9
                  This works for me:
                  Code:
                  SrcSQL4 = "SELECT services.* FROM services WHERE services.[service performed] like '* " _
                          & [Forms]![services1]![keyword] & " *'"
                  DoCmd.ApplyFilter SrcSQL4
                  I created a new form in my database, pasted your code into it and changed table, field and form names.
                  No syntax error. The query did not find what I searched for, so I tidied up the spaces and quotes, and now it finds the word in the keyword textbox. I tried the filter on both a text field and a memo field with success.
                  I am using Access 2003, but I doubt that will affect it.

                  Comment

                  • neelesh kumar
                    New Member
                    • Mar 2007
                    • 44

                    #10
                    sir,
                    thank u very much for ur help.
                    i got it finally.

                    Comment

                    Working...