Solved

Sve or Cancel Changes on Exit of Subform

Posted on 2007-11-15
8
321 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 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
I think it keeps any changes because I am exiting the subform.  Does Undo work when exiting?
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
oh sorry did not see the OnExit event
yes, it will save the record on exit
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

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

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
you can use the Beforeupdate event or beforeinsert to make the undo work
0
 

Author Comment

by:Travidia
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

12 Experts available now in Live!

Get 1:1 Help Now