Solved

Sve or Cancel Changes on Exit of Subform

Posted on 2007-11-15
8
346 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

789 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