Results 1 to 2 of 2
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Problem with SQL Syntax in VBA Update Query

    Sql Server 2008 R2 back end connected via ODBC, Access 2007 front end, All tables are linked and show up in the Tables view, SA authority, Database is in development not production.

    I am writing a SQL Update query in VBA that executes on the AfterUpdate Event Procedure of a combo box. All of the Variables populate with the correct data. My SQL statement runs fine except the WHERE clause prompts me to enter the AttachID. It should get it from the variable IntAttach but it's not. As soon as I enter the AttachID = 9 in the prompt box, everything executes perfectly. I don't understand what is wrong with my WHERE statement. I am attempting to update the Access linked table dbo_PropertyEntity.

    Code:
    Private Sub PickNewEntity_AfterUpdate()
    Dim IntAttach As Integer
    Dim IntEnity As Integer
    Dim strName As String
    Dim strAddress As String
    IntAttach = Forms!Property!PropertyEntityJoin_SubFrm!AttachedID
    IntEntity = Forms!Property!PropertyEntityJoin_SubFrm!PickNewEntity.Column(2)
    strName = Forms!Property!PropertyEntityJoin_SubFrm!PickNewEntity.Column(0)
    strAddress = Forms!Property!PropertyEntityJoin_SubFrm!PickNewEntity.Column(1)
    stSQL = "UPDATE DBO_PropertyEntity" & " SET EntityID = EntityName = '" & strName & "', EntityAddress = '" & strAddress & "'" & " WHERE AttachID = " & IntAttach & ";"
    DoCmd.RunSQL stSQL
    Me.Requery
    End Sub
    Any suggestions?

    Thanks Phred

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What do you want to set EntityID = to?

    stSQL = "UPDATE DBO_PropertyEntity SET EntityID = " & something & ", EntityName = '" & strName & "', EntityAddress = '" & strAddress & "' WHERE AttachID = " & IntAttach

    What field type is EntityID?
    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.

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

Similar Threads

  1. Update Query Syntax - RTE 424
    By T 5 in forum Queries
    Replies: 3
    Last Post: 05-02-2014, 11:29 AM
  2. Replies: 10
    Last Post: 10-30-2013, 02:06 PM
  3. Syntax Error 3144 in SQL Update Query.
    By Phred in forum Programming
    Replies: 4
    Last Post: 03-02-2012, 02:39 PM
  4. Replies: 7
    Last Post: 12-29-2011, 03:12 PM
  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