Results 1 to 3 of 3
  1. #1
    Cheez is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    9

    Invalid use of . (dot) or ! operator or invalid use of parentheses.


    Hello all. I'm learning how to write SQL statements. can someone look this statement over and see where i went wrong. I know it's in the where clause.

    SQL = "INSERT INTO tblTransactionsArcives (TransactionID, CheckingID, CategoryID, ChkDate, Description, Cleared, Withdrawals, Deposits, Notes) " _
    & "SELECT tblTransactions.TransactionID, tblTransactions.CheckingID, tblTransactions.CategoryID, tblTransactions.ChkDate, tblTransactions.Description, " _
    & "tblTransactions.Cleared, tblTransactions.Withdrawals, tblTransactions.Deposits, tblTransactions.Notes " _
    & "FROM tblTransactions " _
    & "WHERE tblTransactions.ChkDate >= #" & [txtFirstDay] & "# AND < #" & [txtLastDay] & "# AND tblTransactions.CheckingID >0 " _
    & "ORDER BY tblTransactions.ChkDate;"

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Have to repeat the ChkDate field for each date parameter when using relational operators:

    & "WHERE ChkDate >= #" & [txtFirstDay] & "# AND ChkDate< #" & [txtLastDay] & "# AND CheckingID >0 " _

    Your criteria excludes txtLastDay from the date range. If you really want to include it consider BETWEEN AND:

    & "WHERE ChkDate BETWEEN #" & [txtFirstDay] & "# AND #" & [txtLastDay] & "# AND CheckingID >0 " _

    Don't have to prefix each field with the table name since there is only one table in the SELECT and if there were multiple tables, only if same field name is in multiple tables.
    Code:
    SQL = "INSERT INTO tblTransactionsArcives (TransactionID, CheckingID, CategoryID, ChkDate, Description, Cleared, Withdrawals, Deposits, Notes) " _
    & "SELECT TransactionID, CheckingID, CategoryID, ChkDate, Description, Cleared, Withdrawals, Deposits, Notes " _
    & "FROM tblTransactions " _
    & "WHERE ChkDate >= #" & [txtFirstDay] & "# AND ChkDate < #" & [txtLastDay] & "# AND CheckingID >0 " _
    & "ORDER BY ChkDate;"
    However, moving records to an 'archive' table isn't really necessary. Could just have another field in tblTransactions that sets record as "not active" - can be a yes/no field. Then, just run UPDATE action sql.

    BTW, Arcives is a misspelling of Archives.

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Cheez is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    9
    Thank you June7 that solved the problem. I will also look into your suggestion to just add a yes/no field and do a update action sql. That will be good practice for me.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 18
    Last Post: 02-26-2018, 03:42 PM
  2. Replies: 5
    Last Post: 07-22-2014, 06:58 AM
  3. Invalid Relational Operator Error
    By KelleyM in forum Queries
    Replies: 5
    Last Post: 11-08-2012, 10:53 AM
  4. Replies: 7
    Last Post: 08-28-2011, 02:07 PM
  5. Invalid use of me
    By kman42 in forum Access
    Replies: 1
    Last Post: 04-28-2011, 12:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums