Sunday, July 29, 2007

To Save or Not to Save Records

Sometimes people like to know when a record has been changed before closing a form
This function will help you in that regard

Public Function ConfirmRecordChanges() As Boolean

'Confirm record changes

Dim intSaveChanges As Integer
On Error Resume Next
ConfirmRecordChanges = False
If Forms(CurrentObjectName).Dirty Then

intSaveChanges = MsgBox("Do you want to save the changes?", vbYesNo, "This Record has been modified")
If intSaveChanges = vbYes Then
On Error GoTo errHandler
RunCommand acCmdSaveRecord
ConfirmRecordChanges = True
Else
RunCommand acCmdUndo
End If
Else
ConfirmRecordChanges = True

End If

Exit Function

errHandler:
MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbExclamation, "Problem Saving Record"

End Function

No comments: