Undo changes

Hello experts ,
i have a problem with ms access 2010.I am using navigation control and each tab opens a single form.What i want to do is that when i am in a form and i enter the primary key value (fill data to an object for example a date object) i want if i point to another tab of the navigation control to be prompted if i want to save the record or not.If i choose no i want to discard changes . i have tried the code below in the unload and close events of the form and it didn't work .Am i missing something ?
If Me.Dirty Then
        MsgBox "changes discarded"
        RunCommand acCmdUndo
End If

Open in new window

LVL 1
stathisxAsked:
Who is Participating?
 
stathisxConnect With a Mentor Author Commented:
i finally did it. What i did is :
1)Declared a constant variable which gets value 1 on form dirty event (const_exit_epi)
2)on form before update i entered the following code :

That did the trick. If there is another solution i would be glad to hear !
If Screen.ActiveControl.Name <> cmdButton.Name Then
If const_exit_epi = 1 Then
Me.Undo
End If
End If

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
you have to use the Beforeupdate event of each form or subform to trigger the message and to cancel the changes
0
 
stathisxAuthor Commented:
can you please post a sample code to do that ?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
try this

private sub form_beforeupdate(cancel as integer)

if me.dirty then
  if (msgbox("do you want to save changes made?",vbyesno))=vbNo then
     me.undo
     cancel=true
     exit sub
  end if
end if

end sub
0
 
stathisxConnect With a Mentor Author Commented:
yes this seems to work but i have buttons in my form to insert a new record so the code above if i dont't use the messagebox performs an undo and i get error.I want the code above to work only when i select another tab in my navigation control . How can i achieve this ?
0
 
stathisxAuthor Commented:
Capricorn comments were very good and helpfull to point me to the right direction.The complete solution though was by the code posted in the last comment.thank you !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.