Results 1 to 6 of 6
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Syntax Error in UPDATE Statement

    Hi,



    I am running a SQL script through VBA with the runSQL command.

    Basically, I am updating fields, 1 and a time, and checking to see if that field value is null... if it is, then update the field value.

    However, I keep getting an error associated with the syntax of the SQL statement. Here is the statement, as it it is in VBA.

    DoCmd.RunSQL ("UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT." & strQuery(i) & " = [ProjectsLink]." & strQuery(i) & " WHERE (((ProjectsT." & strQuery(i) & ") Is Null));")

    strQuery(i), is the name of each field that I am updating. I can't figure out where... but somewhere in this is a syntax issue and I have no idea where.

    Any help is appreciated.

    Thanks,

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Instead of DoCmd.RunSQL

    add a statement that says
    Debug.print "UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT." & strQuery(i) & " = [ProjectsLink]." & strQuery(i) & " WHERE (((ProjectsT." & strQuery(i) & ") Is Null));"

    Then look in the immediate window to see what Access understood.

  3. #3
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Not sure what I am looking for exactly. It all looks the same.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    The debug.print will print the rendered Sql statement to the immediate window.
    Try running your vba, then check the immediate window.

  5. #5
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    It's completely skipping "Inherent_Risk". Notice that the skip is blank and that it shows up AFTER Controls too.

    NOT A CLUE WHY

    strQuery(1) = "Legal_Analysis"
    strQuery(2) = "CD_Applicability"
    strQuery(3) = "CD_Applicability_Reason"
    strQuery(4) = "Legal_Applicability"
    strQuery(5) = "CD_Legal_Agreement"
    strQuery(6) = "Stage_2_Status"
    strQuery(7) = "Inherent_Risk"
    strQuery(7) = "Controls"
    strQuery(9) = "Residual_Risk"
    strQuery(10) = "Analysis_Completion"
    strQuery(11) = "Stage_3_Status"
    strQuery(12) = "Target_Completion"
    strQuery(13) = "Completion"

    UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT.CD_Legal_Agreement = [ProjectsLink].[CD_Legal_Agreement] WHERE (((ProjectsT.CD_Legal_Agreement) Is Null));

    UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT.Stage_2_Status = [ProjectsLink].[Stage_2_Status] WHERE (((ProjectsT.Stage_2_Status) Is Null));

    UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT.Controls = [ProjectsLink].[Controls] WHERE (((ProjectsT.Controls) Is Null));

    UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT. = [ProjectsLink].[] WHERE (((ProjectsT.) Is Null));

    UPDATE ProjectsLink INNER JOIN ProjectsT ON ProjectsLink.ID2 = ProjectsT.ID2 SET ProjectsT.Residual_Risk = [ProjectsLink].[Residual_Risk] WHERE (((ProjectsT.Residual_Risk) Is Null));

  6. #6
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    This is going to sound dumb. But look at my count! I count strQuery as 7 - 7 in one part! So stupid! It works now.

    Thanks for teaching me about the Immediate Window, that did prove useful when I looked at the code and noticed there was a step wrong in that particular portion!

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

Similar Threads

  1. Syntax error in SQL UPDATE statement
    By Pietro in forum Modules
    Replies: 1
    Last Post: 02-20-2015, 05:09 AM
  2. Replies: 1
    Last Post: 09-22-2014, 08:54 AM
  3. Error 3144: Syntax error in UPDATE statement??
    By Paintballlovr in forum Programming
    Replies: 7
    Last Post: 03-26-2014, 12:53 PM
  4. sql update statement syntax error
    By osupratt in forum Queries
    Replies: 7
    Last Post: 10-18-2013, 07:42 AM
  5. Syntax error in UPDATE statement HELP!
    By asmith78 in forum SQL Server
    Replies: 5
    Last Post: 09-07-2011, 05:50 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