Results 1 to 2 of 2
  1. #1
    mrsgwen is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2009
    Posts
    2

    trying to update a record

    i have an access database with some vba code behind it. i have a table called "Files" that holds some records and i have 2 forms. one form opens a new file and the other form closes the file. When i close the file the record should be updated with a "closed" status. But the problem is i keep getting the error: "Write Conflict - this record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other user made." then it gives the option to copy to clipboard or drop changes. Any help will be greatly appreciated.
    Here is my code:

    Private Sub cmdCloseFile_Click()
    On Error GoTo Err_cmdCloseFile_Click

    Dim Result
    Dim rst As ADODB.Recordset
    Dim adocmd As ADODB.Command

    Set adocmd = New ADODB.Command
    Set rst = New ADODB.Recordset
    With adocmd
    .ActiveConnection = CurrentProject.Connection
    .CommandType = adCmdText
    .CommandText = "Select * from dbo_tbl_Files where Status = 'closed' and FileNo = " & Me.FileNo
    End With

    rst.CursorLocation = adUseClient
    rst.Open adocmd, , adOpenStatic, adLockReadOnly
    If rst.RecordCount > 0 Then
    MsgBox "This File has already been closed.", vbCritical, "FileNo Confirmation"


    Result = vbNo
    DoCmd.Close
    DoCmd.OpenForm "Legal Files Main"
    Else
    Result = MsgBox("Are you sure you want to close File No. " + Str$(Me.FileNo) + "?", vbYesNo, "Add File")
    If Result = VbMsgBoxResult.vbNo Then
    Me.Room = ""
    Me.BoxNo = ""
    Me.DateClosed = ""


    DoCmd.Close
    DoCmd.OpenForm "Legal Files Main"

    End If
    End If


    rst.Close
    Set rst = Nothing
    Set adocmd = Nothing

    If Result = vbNo Then
    Exit Sub
    End If


    Dim rstFile As New ADODB.Recordset
    Dim fld As ADODB.Field
    Dim strField As String
    Dim sqlstmt As String

    sqlstmt = "SELECT * FROM dbo_tbl_Files WHERE FileNo=" & Me.FileNo

    rstFile.Open sqlstmt, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    rstFile!Status = "Closed"

    rstFile.Update
    rstFile.Close


    MsgBox "File Successfully Closed."

    Msg = "Do you want to close another file?"

    Response = MsgBox(Msg, vbYesNo)
    If Response = vbYes Then

    DoCmd.Save
    DoCmd.Close
    DoCmd.OpenForm "Close File"
    Else
    DoCmd.Close
    DoCmd.OpenForm "Legal Files Main"
    End If

    Exit_cmdCloseFile_Click:
    Exit Sub

    Err_cmdCloseFile_Click:
    MsgBox Err.Description
    Resume Exit_cmdCloseFile_Click




    End Sub

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,170
    HI,

    one reason could be that the record is open in the form and is dirty. This way it is been changed in the form (=user 1), and the code (user 2) tries to modify the same record.
    Try to save the record in the form (docmd.RunCommand acCmdSaveRecord) before running the status update command.

    success
    NG

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

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  2. Replies: 9
    Last Post: 12-18-2010, 12:51 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 new record when leaving form
    By jpkeller55 in forum Access
    Replies: 6
    Last Post: 09-08-2010, 06:35 AM
  5. Run Update Query on Current Record in Form
    By c3pse in forum Queries
    Replies: 3
    Last Post: 08-14-2010, 05:40 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