Solved

setting Cancel in BeforeUpdate fired from closing form problem

Posted on 2013-12-17
4
950 Views
Last Modified: 2013-12-22
hey guys,

here's an empty database with a form to demonstrate this problem.BeforeUpdateCancel.mdb

when i press the "x" at the top right of the form to close the form, the beforeupdate event fires.

in the beforeupdate event i set the Cancel variable to True --> because i want to cancel the update.

the result of this is that this message box pops up.

you can't save this record at this time
goal: i want to cancel the form update when the user clicks the "x" at the top right of the form.

question --> 1) why is this msgbox popping up? could yall give me a technical insight into the mechanisms of it?
2) how do i achieve my goal of canceling the form update when the user clicks the "x"?

P.S. i found the solution is to only use the Me.Undo line without the Cancel = True --> and i do understand the difference between Undo and Cancel, but i just can't understand why the Cancel = True when the form is closing causes a problem? definitely i suspect that i'm "tinkering" around with the inner workings of Access cause the form is closing with presumably an automatic save and i am asking it to cancel the save

here are 2 great posts which helped me quite a bit but just shy of the final problem i've posted here
a) from EE PatHartman really helped me a lot on this but using her code somehow it's not working i'm not sure why http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_28259652.html
b) another developer facing the same problem who resorted to quite a long way of doing things i feel http://bytes.com/topic/access/answers/647206-cancelling-record-update-beforeupdate-event
0
Comment
Question by:developingprogrammer
[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
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 450 total points
ID: 39726270
Cancel = True will cancel the Update event, and Access won't be able to close the form (since it's dirty, and access won't close a dirty form without saving). If you want to NOT save changes, then just put Me.Undo, and let it go at that.

However, I think you need to further define the work flow of the form. If a user fills in data, and they want to save it, exactly how are they supposed to do that if the BU event is always undoing their work? In general, most users would expect the form to save the data and close when the explicitly ask it to do so - so why would you go against those expectations?
0
 
LVL 20

Assisted Solution

by:clarkscott
clarkscott earned 50 total points
ID: 39728713
I suppress the X top right corner and make my users click a CLOSE button.
You can add any data validation you need in a function and call the function before closing the form in code.

Most efficient way... no issues with "X's", or trying to figure out what event to "cancel" ....

Scott C
0
 

Author Comment

by:developingprogrammer
ID: 39734979
thanks LSMConsulting as always! = )

i have a variable which says whether to save or not in the BU event and so that helps define the workflow. i think your sentence

Cancel = True will cancel the Update event, and Access won't be able to close the form (since it's dirty, and access won't close a dirty form without saving)

beautifully summarises it = )

thanks Scott too! i guess i'm trying to challenge myself to fit into users expectations of having a x button on the top right (because they are trained by windows to expect that already). but thanks still for your tip! definitely helps! = )
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 39735086
Further.... When you build "system" apps, you must control it.  To do so most efficiently, you must bottleneck.  One way in - one way out.  If there's no exception, then there is no multiple methods for dealing with it.  It's really as simple as that.

I usually put a black-filled box behind my "close buttons".  This makes it very easy for users to see, and recognize, exactly how to close my forms.

PS.  I put a red-filled box behind my "Delete" options - same reason.

Thanks for the points and have a great Holiday Season !!

Scott C.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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