Results 1 to 6 of 6
  1. #1
    SIMMS7400 is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2016
    Posts
    25

    How come you can't use NZ with update query?

    Hi Folks -



    I have an update query that I need to modify. There are situations where the CCTEMP.Short_Code is not unique and order to make it unique, I need to bring in another column.

    This is my current code:
    Code:
        strStep = "Step 5 : Update Cost Center Info"
        strSQL = "" & _
                "UPDATE [Global_Monthly_Headcount]" & _
                "INNER JOIN [CCTEMP]" & _
                "ON [Global_Monthly_Headcount].[Cost Center - Short Name] = [CCTEMP].[Short_Code]" & _
                    "SET" & _
                        "[Global_Monthly_Headcount].[Cost Center - Long Name] = Nz([CCTEMP].[Long_Code], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Division] = Nz([CCTEMP].[Division], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Function] = Nz([CCTEMP].[Function], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Subfunction] = Nz([CCTEMP].[Subfunction], Null);"
        db.Execute strSQL, dbFailOnError
    But I want to use this but it just runs and runs and runs and doesn't complete. How would I go about achieving this?
    Code:
        strStep = "Step 5 : Update Cost Center Info"
        strSQL = "" & _
                "UPDATE [Global_Monthly_Headcount]" & _
                "INNER JOIN [CCTEMP]" & _
                "ON [Global_Monthly_Headcount].[Cost Center - Short Name]+Nz([Global_Monthly_Headcount].[Cost Center - Division],""foo"") = [CCTEMP].[Short_Code]+Nz([CCTEMP].[Division],""foo"")" & _
                    "SET" & _
                        "[Global_Monthly_Headcount].[Cost Center - Long Name] = Nz([CCTEMP].[Long_Code], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Division] = Nz([CCTEMP].[Division], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Function] = Nz([CCTEMP].[Function], Null)," & _
                        "[Global_Monthly_Headcount].[Cost Center - Subfunction] = Nz([CCTEMP].[Subfunction], Null);"
        db.Execute strSQL, dbFailOnError

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    The Nz function is used to create an alternate value when a field value is null. It makes no sense to set that alternate value to be Null even if it were possible.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm not sure you can use a + in a join expression in Access.
    You could get away with it in T-SQL .

    Have you debug.printed your strSQL as I don't think that would work ? ""Foo"" should be in single quotes 'Foo'

    Unless that's just you anonymising your code a bit?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    try not to use code sql, instead create queries. They always get the syntax right.

  5. #5
    SIMMS7400 is offline Novice
    Windows 8 Access 2007
    Join Date
    Mar 2016
    Posts
    25
    Thanks all! So is there no way to solve my issue?

  6. #6
    CarlettoFed is online now Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    The second SQL statement is wrong, you cannot relate more tables by writing in that way. You should post a sample file to be sure we can help you.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  2. Replies: 1
    Last Post: 10-27-2016, 12:14 PM
  3. Replies: 14
    Last Post: 08-12-2014, 06:33 AM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 2
    Last Post: 08-30-2012, 07:59 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