Where clause issues.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beebelbrox
    New Member
    • Aug 2007
    • 20

    Where clause issues.

    Okay like I must be blind and dumber than a box hammers but i cant figure out what wrong with this where clause

    Code:
    & "WHERE tblMasterDbList.[DBName]<> '" & filSub & "';"
    the error message say the ";" is missing at the end of the statment

    I've checked out the net and some other soruces and it looks right but............ ....

    here is the whole query, the query works with out the where clause;

    Code:
    DoCmd.RunSQL "INSERT INTO tblMasterDbList (DBName, DBPath)" _
    & "VALUES ( " & "'" & strFName & "'" & "," & "'" & filSub & "'" & " ) " _
    & "WHERE tblMasterDbList.[DBName]<> '" & filSub & "';"
    I'd be very appreciative if someone one could smack me upside my head with the blindingly obvious answer that, I cant for the life of me see.

    thanks

    B
    Last edited by Stewart Ross; Jun 25 '08, 08:23 AM. Reason: Added code tags to delineate code
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    Put your SQL in a string variable first and them use a Debug.Print or MsgBox to display it and you will see what is going on.

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      Hi. The error message is really saying that the SQL interpreter was expecting the statement to end. It is the use of the WHERE clause itself which is wrong - it is not valid to use WHERE with an append statement intended to add one record unconditionally through the use of a VALUES clause.

      If you are inserting one or more records selected from another table on some criteria you need the other form of the INSERT statement:

      Code:
      INSERT INTO tablename
      SELECT field1, field2 FROM anothertable
      WHERE somecondition
      -Stewart

      Comment

      Working...