Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

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

0
stathisx
Asked:
stathisx
  • 4
  • 2
3 Solutions
 
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
 
Rey Obrero (Capricorn1)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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
stathisxAuthor 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:
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now