Solved

Setting up a close form "cancel" method...

Posted on 2003-11-17
5
366 Views
Last Modified: 2008-03-17
I'm trying to set up a system in my database VB where I can sort of "cancel" a form close action on a whim. For example, I'd like to be able to set up a check in my BeforeUpdate event that can confirm whether or not the current record has been saved or not, and if there is a problem cancel a possible form closing accordingly. I'm not sure exactly how to set the Cancel to True in the Unload event during run time.. I've tried using global variables, but that can get a bit ugly as far as reseting them/checking them goes... I'm sure a more experienced coder than myself knows what I'm talking about... Any ideas?
0
Comment
Question by:Mitleid242
  • 2
  • 2
5 Comments
 
LVL 32

Assisted Solution

by:jadedata
jadedata earned 45 total points
ID: 9767001
Hey Mitleid242!

  The best and easiest way that I have found is to always have a "Close" button on the form where I can control the code that it functions with.  Then I remove the top "X" boxes and Min/Max buttons.

  Doing this the Private Sub cmdClose sub is under your control.  You may cancel at will without closing the form.  Excellent when you need to checkup on your users to see if they are entering all requirements in one pass.

regards
Jack
0
 
LVL 28

Accepted Solution

by:
TextReport earned 80 total points
ID: 9767679
Mitleid242, the way I handle this is as follows

1. Create a Close Button that has an event procedure that sets the module level variable

    mbooClose = True
    docmd.close scform, me.name

2. Set the Form UnLoad even to
    cancel = not mbooClose

You can use the mbooClose = True on any code you wish to allow it.

Cheers, Andrew
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9771042
Hey TR!! Haven't seen you much 'round these parts,... welcome back!
0
 
LVL 28

Expert Comment

by:TextReport
ID: 9771146
too busy but Ive got a few hours so here goes. Cheers, Andrew
0
 

Author Comment

by:Mitleid242
ID: 9771493
Thanks fellas. I appreciate the input. What I ended up doing was using a variable to control whether or not the form is allowed to unload. Then I just had a function that ran after clicking a close button to validate all of my required values, and if any problems arose it just set the variable to cancel = true.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

773 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