Solved

Sve or Cancel Changes on Exit of Subform

Posted on 2007-11-15
8
340 Views
Last Modified: 2008-02-01
I have a subform that can only be changed once a button on the main form is clicked.  Then when the user exits the subform I have a prompt.  I searched EE for a prompt and found this one.  This is my code OnExit:

If MsgBox("Do you want to save? (click 'No' to undo)", vbYesNo, "Save") = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Me.Undo
End If
     
     Me.lbxParent.SetFocus
     Me.frmParentDetails.Locked = True
     Me.Command27.Enabled = True
    Me.frmParentDetails.Form!Status.Enabled = False
    Me.frmParentDetails.Form!AccountOwner.Enabled = False
    Me.frmParentDetails.Form!AccountLead.Enabled = False

It asks me if I want to save it and when I click no, it changes focus and keeps the changes.  I want to avoid a temp table.  
0
Comment
Question by:Travidia
  • 5
  • 3
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20291531
are the data you are saving/discarding are those that are in the subform?

If MsgBox("Do you want to save? (click 'No' to undo)", vbYesNo, "Save") = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
'Me.Undo

Me.frmParentDetails.undo
'or

'Me.frmParentDetails.form.undo
End If
0
 

Author Comment

by:Travidia
ID: 20291573
The data is on the subform.  Which one should I use.  Me.frmParentDetails.undo doesn't work.  Me.frmParentDetails.form.undo saves when Yes but doesn't cancel changes.
0
 

Author Comment

by:Travidia
ID: 20291593
I think it keeps any changes because I am exiting the subform.  Does Undo work when exiting?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20291606
oh sorry did not see the OnExit event
yes, it will save the record on exit
0
 

Author Comment

by:Travidia
ID: 20291617
any way to cancel changes on exit?  I still don't have a cancel working as I want.  
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 20291638
you can use the Beforeupdate event or beforeinsert to make the undo work
0
 

Author Comment

by:Travidia
ID: 20291718
I get runtime error 2115 - 'the function set to the BeforeUpdate property for this field is preventing Access from saving the data...'
0
 

Author Comment

by:Travidia
ID: 20291745
I made an addition to handle the error.  Here's the code now:

On Error Resume Next
DoCmd.Hourglass (True)
DoCmd.SetWarnings False
     
If MsgBox("Do you want to save? (click 'No' to undo)", vbYesNo, "Save") = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Else
Me.Undo

'Me.frmParentDetails.Undo

'Me.frmParentDetails.Form.Undo

End If

DoCmd.SetWarnings True
DoCmd.Hourglass (False)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now