Solved

Sve or Cancel Changes on Exit of Subform

Posted on 2007-11-15
8
363 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing 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 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

707 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