Results 1 to 3 of 3
  1. #1
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125

    SQL UPDATE in vba

    Trying to run an sql update in vba. I don't get any errors, I've looked at the debug. print and the statement and values (where statement too) all look correct, but it is just not updating the record. This was working a few days ago, I might have changed something but I'm not aware of what.

    code in form:



    Code:
    Private Sub txtDetWgt_AfterUpdate()
    Dim dbCMC As DAO.Database
    Dim strSQL As String
    Dim datActSubDate As Date
    Dim lngChgNum As Long
    Dim datChgDate As Date
    datChgDate = Date
    datActSubDate = Date
            Set dbCMC = CurrentDb
            strSQL = "UPDATE dbo_tblSubmittals " & _
            "SET [DetWgt] = " & Me.txtDetWgt.value & " And [ActSubDate] = #" & datActSubDate & "# " & _
            "WHERE [JobNum] = '" & Me.cboJobNum.value & "' And [Segment] = '" & Me.cboSegment.value & "' And [Desc] = '" & Me.cboDesc.value & "'"
            Debug.Print strSQL
            dbCMC.Execute strSQL, dbFailOnError
    End Sub
    debug:

    Code:
    UPDATE dbo_tblSubmittals SET [DetWgt] = 31000 And [ActSubDate] = #4/21/2011# WHERE [JobNum] = '1123705000' And [Segment] = 'Sitework' And [Desc] = 'SITEWORK'
    I checked the table about a million times, there's a record that has JobNum = 1123705000, Segment = "Sitework", and Desc = "Sitework" so there seems to be a match. I'm not sure why, if it wasn't updating, it wouldn't at least give me an error.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    have you tried replacing the "and"s with actual commas?? I've never seen "and"s used in statements like that before.

    I'm sure it works, as you've stated, but its worth a try.

    and what about taking out the "dbfailonerror" part?? is that why you're not getting an error, perhaps?? It's it's in error, it will fail I'm sure, as the command states.

  3. #3
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Man it's always something supid I did. You're right, I'm used to using the And, which works in the WHERE statement, but I changed the "And" after SET to a comma and now it works.

    Thanks for your help.

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

Similar Threads

  1. Update 2 tables with one Update Query
    By Douglasrac in forum Queries
    Replies: 4
    Last Post: 04-14-2011, 08:33 AM
  2. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  3. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM
  4. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 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