Flagging if record has been modified

  • Thread starter Thread starter Joe Williams
  • Start date Start date
J

Joe Williams

What is the easiest way to check a record to see if the user has modified it
and then to present a dialog box asking saying "The Record Has Been
Modified. Do you wish to save changes? YES/NO"

How do I do it and in what form event would I place this check?

Thanks

Joe
 
Hi, Joe.
How do I do it and in what form event would I place this check?

You can check the form's Dirty property in the form's BeforeUpdate( ) event.
Try the following sample code:

' * * * * Code Start * * * *

Private Sub Form_BeforeUpdate(Cancel As Integer)

On Error GoTo ErrHandler

Dim answer As Integer

If (Me.Dirty) Then
answer = MsgBox("The record has been modified." & vbCrLf & _
"Do you wish to save changes?", vbYesNo, "Save Changes?")

If (answer = vbNo) Then
Me.Undo
End If
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_BeforeUpdate( ) in" & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

' * * * * Code End * * * *

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
What is the easiest way to check a record to see if the user has modified it
and then to present a dialog box asking saying "The Record Has Been
Modified. Do you wish to save changes? YES/NO"

How do I do it and in what form event would I place this check?

If you put code in the Form's BeforeUpdate event, it will only be
executed if the user in fact changes something. And the event can be
cancelled. Try:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
iAns = MsgBox("The Record Has Been Modified. " & _
"Do you wish to save changes? YES/NO", vbYesNo)
If iAns = vbNo Then
Cancel = True
End If
End Sub


John W. Vinson[MVP]
 
Thanks, John.

I was forgetting that the user wasn't the only one that could make changes
to the record. But cancelling glues them to the same record with the
modifications remaining unchanged. This would frustrate my users, who
generally fire off the form's BeforeUpdate( ) event on an edited record when
moving on to the next record. Their reasoning is, "If I said I don't want
to keep the changes, then why am I still looking at them?"

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
I was forgetting that the user wasn't the only one that could make changes
to the record. But cancelling glues them to the same record with the
modifications remaining unchanged. This would frustrate my users, who
generally fire off the form's BeforeUpdate( ) event on an edited record when
moving on to the next record.

I actually have used a three-option choice:

strMsg = "Select Yes to accept these changes, No to go back to" & _
" this record, and Cancel to undo all your changes:"
iAns = MsgBox(strMsg, vbYesNoCancel)
Select Case iAns
Case vbYes
' do nothing, just accept the changes
Case vbNo
' set the Cancel parameter, put the user back in the record
Cancel = True
Case vbCancel
' Cancel the update and undo all changes
Cancel = True
Me.Undo
End Select

John W. Vinson[MVP]
 
Back
Top