Search code examples
formsms-accesserror-handlingpopup

How to prevent an Microsoft Access error message from populating when trying to close a form?


I have this form in Access with a bunch of drop down menu boxes. If I choose a value from the List and then change my mind and leave it blank again, click close, I always get this message:

the data has been changed

Another User edited this record and saved the changes 
before you attempted to save your changes

Re-edit the record.

I have 3 different macros in the background running for

Deal type
Loan Exception Comments
Update Flags

I don't think those macros would affect anything to give that error. But can I write something so that it catches this error message and ignores it and proceeds to close when I click close?

The main form VBA has this code:

Private Sub Close_Click()
 Me.FrmJobDetails.Form.Requery
 Me.subform1.Form.Requery

If Me.FrmJobDetails.Form.Dirty = True Then 'what I tried adding
 me.FrmJobDetails.Form.Dirty = False 'what I tried adding
End If
 If Me.subform1.Form.Dirty = True Then 'what I tried adding
 me.subform1.Form.Dirty = False 'what I tried adding
End If
    DoCmd.SetWarnings (WarningsOff)
    DoCmd.Save

    entry
    DoCmd.OpenQuery ("aqrySBORequestSiteDetail"), , acReadOnly


    DoCmd.Close
    DoCmd.SetWarnings (WarningsOn)

End Sub

In that code, with the comment "what I tried adding" is what I thought could prevent that error message from occurring.

Any suggestions?


Solution

  • I use this to handle the Write Conflict error (7787). When there's a write conflict, the first change goes through and the second one gets discarded.

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
        If DataErr = 7787 Then
            Response = acDataErrContinue
            On Error Resume Next
            With Me.Recordset
                .MovePrevious
                .MoveNext
            End With
            On Error GoTo 0
        End If
    End Sub