Results 1 to 3 of 3
  1. #1
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Syntax Error on Update Statment

    The system is giving a syntax error message and I swear I can't find it.



    The idea is to update a table where the billingdate (integer) = BillDt (variable) and the DateBilled (i.e. the invoice date = null). Is supposed to set the BillingDate to todays date (variable InvDt).

    DoCmd.RunSQL "UPDATE tblCompanyExtras " _
    & "JOIN tblCompanyExtras ON CompanyInformation.CompanyAccountNo = tblCompanyExtras.CompanyId " _
    & "SET tblCompanyExtras.DateBilled = " & InvDt & " " _
    & "WHERE (((tblCompanyExtras.DateBilled) Is Null) AND ((CompanyInformation.CompanyBillingDate)= " & BillDt & "));"

    I originally create the query in the query grid and copied the sql code to my sub routine. The original code said update the CompanyInformation table and was giving me data validation errors. The tblCompanyExtras is the table where I need to set the invoice date to date().

  2. #2
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    You might try changing "WHERE (((tblCompanyExtras.DateBilled) Is Null) AND ((CompanyInformation.CompanyBillingDate)= " & BillDt & "));"

    to
    "WHERE (((tblCompanyExtras.DateBilled) Is Null) AND ((CompanyInformation.CompanyBillingDate)= #" & BillDt & "#));"

    Dates need the pound signs in the criteria....assuming CompanyBillingDate is a date field...

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I believe you also need to specify the join, ie INNER, LEFT or RIGHT.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Syntax error in UPDATE statement HELP!
    By asmith78 in forum SQL Server
    Replies: 5
    Last Post: 09-07-2011, 05:50 PM
  2. Error message for criteria statment
    By macattack03 in forum Queries
    Replies: 1
    Last Post: 04-23-2011, 11:21 AM
  3. sql UPDATE syntax help
    By ducthang88 in forum Programming
    Replies: 1
    Last Post: 12-04-2010, 12:12 PM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. UPDATE query syntax
    By jgelpi16 in forum Programming
    Replies: 10
    Last Post: 08-21-2010, 07: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