Results 1 to 4 of 4
  1. #1
    v7davisa is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    3

    Question BeforeUpdate: Could not update; currently locked.

    Background: SharePoint linked table is being updated by a form which calls code module in the beforeupdate event.

    Desired End Result: When field in record changes to a value different than existing and not "GREEN", populate "Date Started" field with current date for tracking purposes.

    Problem: When change is made that fits criteria, error returned is "Could not update; currently locked.". Have attempted workarounds described here ("http://support2.microsoft.com/kb/331594") to no avail. I've tried various things and am now running out of ideas for an "easy" fix.

    As I understand, the form and code module are both attempting to update the same record and thus it is becoming locked. I was curious if there is a method of passing the information from the form transaction, cancelling, and then passing said information to the transaction occurring in the code. Please, let me know what the best way I can do this would be or if the below code is salvageable. I am relatively new to VBA so please excuse my lack of comments. If I get it to work, that will be my next step. Thank you. Credit goes to Martin Green (www.fontstuff.com) for the code structure which I followed from his tutorial and have now tailored for other purposes.

    Code:
    Option Compare Database
    Sub AuditChanges(IDField As String)
        On Error GoTo AuditChanges_Err
        Dim conn As ADODB.Connection
        Dim ctrl As Control
        Dim rst As ADODB.Recordset
        Dim datCheck As Date
        Dim newvalue As String
        Dim ctrlsource As String
        Set conn = CurrentProject.Connection
        conn.CursorLocation = adUseClient
        Set rst = New ADODB.Recordset
        rst.Open "SELECT * FROM [Table Name] WHERE [_ID] = " & (Screen.ActiveForm.Controls(IDField).Value) & "", conn, adOpenDynamic, adLockOptimistic
        datCheck = DateValue(Now)
        For Each ctrl In Screen.ActiveForm.Controls
            If ctrl.Tag = "Audit" Then
                If Nz(ctrl.Value) <> Nz(ctrl.oldvalue) And Nz(ctrl.Value) <> "GREEN" Then
                    With rst
                   ' newvalue = Nz(ctrl.Value)
                    'ctrlsource = ctrl.ControlSource
                     'Screen.ActiveForm.RecordLocks = 0
                    .Fields("Date Started") = datCheck
                    '.Fields(ctrlsource) = newvalue
                    .Update
                    End With
                End If
            End If
        Next ctrl
    AuditChanges_Exit:
        On Error Resume Next
        conn.Close
        Set rst = Nothing
        Set conn = Nothing
        Exit Sub
    AuditChanges_Err:
        MsgBox Err.Description, vbCritical, "ERROR!"
        Resume AuditChanges_Exit
    End Sub


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I though YOU have the record locked, so you must run the code in AFTERUPDATE. If you run BEFORE, its still locked.

  3. #3
    v7davisa is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    3
    I set the afterupdate event to call the following code module but met the same error when change made to record 108 via form.

    Sub test1()
    Dim cnn As ADODB.Connection
    Set cnn = CurrentProject.Connection
    cnn.Execute "UPDATE [Table Name] SET [Date Started] = '9/23/2014' WHERE [_ID] =108"
    End Sub
    Last edited by v7davisa; 09-26-2014 at 09:10 AM. Reason: Code tags removed and table name obscured.

  4. #4
    v7davisa is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    3
    Ok, so now I got it to work by doing a ctrl.undo before attempting to update the rst.field("Date Started") value in the afterupdate event.
    The only issue I am having now is the condition (If Nz(ctrl.Value) <> Nz(ctrl.oldvalue) And Nz(ctrl.Value) <> "GREEN") Then is not coming back as true. It came back as true in the beforeupdate event. I've been debugging for hours.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-31-2013, 09:33 PM
  2. Could Not Update, Currently Locked
    By jlclark4 in forum Forms
    Replies: 5
    Last Post: 11-17-2011, 01:21 PM
  3. Err# 3218: Could not update; currently locked.
    By reachvali in forum Access
    Replies: 3
    Last Post: 06-30-2011, 05:13 PM
  4. Error: Can not update record; currently locked
    By waldzinator in forum Programming
    Replies: 4
    Last Post: 03-29-2011, 08:40 AM
  5. Replies: 0
    Last Post: 11-10-2008, 12:35 PM

Tags for this Thread

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