Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sve or Cancel Changes on Exit of Subform

Posted on 2007-11-15
8
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

604 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