Results 1 to 7 of 7
  1. #1
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501

    Syntax Error

    I am trying to get this query working. I want to update line items where the BID - xxxx And the URC is not 7 or1. I always get a bit confused in how to do multiple criteria like this.



    Currently I have tried:

    Code:
    strSQL = "Update tbl_ImportedRepairs " _         
    & "Set tbl_ImportedRepairs.AccountingCode = 21570 " _
             & "WHERE [tbl_ImportedRepairs].[BillingInvoiceId]= paramBID AND [UpdatedResponsibilityCode] = 7 OR [UpdatedResponsilityCode =1"
    And

    Code:
    Update tbl_ImportedRepairs Set tbl_ImportedRepairs.AccountingCode = 21570  WHERE [tbl_ImportedRepairs].[BillingInvoiceId]= "ALX-LB10802" AND [tbl_importedRepairs].[UpdatedResponsibilityCode] Not In (3,6)"
    The first one is my parameterized query and works fine if I only use the where BillingInvoiceID ANd UpdatedResponsibility code but fails when I add the OR [UpdatedResponsilityCode =1"

    The second one I am trying to manually put in the values to test but using the not in
    Thanks

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    Did you debug.print your sql variable and examine in the immediate window? That is basic troubleshooting 101.
    If you did and it looked good, then your eyes are missing something. Then you copy/paste the output into a new query in sql view and switch to datasheet view. Offending part is usually highlighted in sql view. The error message might actually pinpoint the exact cause.

    Do you see the problem?
    [UpdatedResponsilityCode = 1
    Last edited by Micron; 04-17-2023 at 10:08 AM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    Yes, I tried debug but it just gives me the whole line and doesn't who where the problem is. When I set it to use not in (3,6) it doesn't give any error at all but doesn't update the value like it is supposed to. The form just kind of blinks and nothing happens.

    Yes, sorry I corrected that bracket a while ago so that was not the issue.

  4. #4
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    Hey guys, Sorry, it appears it was a problem with access. I had copied the database to be able to test and somehow the the table for the data got messed up and when you went to the link section it was showing a bunch of numbers and not the table name. It s working with this:
    Code:
    "WHERE [tbl_ImportedRepairs].[BillingInvoiceId]= paramBID AND tbl_IMportedREpairs.[UpdatedResponsibilityCode] = 7 OR tbl_ImportedRepairs.UpdatedResponsibilityCode =1"

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Do yourself a favour.
    As recommended Debug.Print the sql string and copy and paste into the SQL window, when you cannot see the error after the Debug.Print
    Also I always start with a space at the start of the next concatenated string. That way you can see straightaway that a space exists, rather than scrolling all the way to the far right.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    274

    Reply

    Maybe it should be:
    Code:
    "WHERE [tbl_ImportedRepairs].[BillingInvoiceId]= paramBID AND (tbl_IMportedREpairs.[UpdatedResponsibilityCode] = 7 OR tbl_ImportedRepairs.UpdatedResponsibilityCode = 1)"

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Quote Originally Posted by CarlettoFed View Post
    Maybe it should be:
    Code:
    "WHERE [tbl_ImportedRepairs].[BillingInvoiceId]= paramBID AND (tbl_IMportedREpairs.[UpdatedResponsibilityCode] = 7 OR tbl_ImportedRepairs.UpdatedResponsibilityCode = 1)"
    That is how I would write it as well.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 15
    Last Post: 03-01-2021, 12:07 PM
  2. Replies: 6
    Last Post: 02-03-2020, 07:09 PM
  3. Replies: 5
    Last Post: 07-15-2019, 10:20 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

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