Canceling record navigation

J

JoeRegulator

Hi.

I'm pretty new to programming in MS Access. I think this should be pretty
simple.

To prevent users from making accidental changes to a record and then
navigating away I've added code to the BeforeUpdate event of the form and I
test the Dirty property to find out if there have been changes. If there
have been I display a message box with the vbYesNoCancel buttons. If the
user selects yes then the record is saved and navigation proceeds. If no is
pressed the changes are not saved and navigation proceeds.

If the user presses cancel I want to stay on the current record and stay in
edit mode. How do I do that?

Here's the code I have so far;

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
Response = MsgBox("Changes have been made to the current mine record.
Do you want to save them before moving to the next record?", vbYesNoCancel,
"Confirm changes")
If Response = vbNo Then Me.Undoedit mode? <<<<<<<<<<<
End If
End Sub

Thanks for any help that you can provide.
 
J

JoeRegulator

Hi all.

I've figured it out on my own.

All I had to do was replace;
<<<<<<<<<<<

with;

If Response = vbCancel Then Cancel = True
 
D

Dirk Goldgar

JoeRegulator said:
Hi.

I'm pretty new to programming in MS Access. I think this should be pretty
simple.

To prevent users from making accidental changes to a record and then
navigating away I've added code to the BeforeUpdate event of the form and
I
test the Dirty property to find out if there have been changes. If there
have been I display a message box with the vbYesNoCancel buttons. If the
user selects yes then the record is saved and navigation proceeds. If no
is
pressed the changes are not saved and navigation proceeds.

If the user presses cancel I want to stay on the current record and stay
in
edit mode. How do I do that?

Here's the code I have so far;

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
Response = MsgBox("Changes have been made to the current mine
record.
Do you want to save them before moving to the next record?",
vbYesNoCancel,
"Confirm changes")
If Response = vbNo Then Me.Undo
edit mode? <<<<<<<<<<<
End If
End Sub

Thanks for any help that you can provide.


If the form's BeforeUpdate event is firing, then you don't have to test for
Dirty -- the form *must* be dirty, or the event won't fire. Your code
should probably look something like this:

'----- start of code -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

Select Case MsgBox( _
"Changes have been made to the current mine record. " & _
"Do you want to save them before moving to " & _
"the next record?", _
vbYesNoCancel, _
"Confirm changes")

Case vbNo
Me.Undo

Case vbCancel
Cancel = True

Case vbYes
' Do nothing -- let record be saved.

End Select

End Sub

'----- end of code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top