Solved

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

Posted on 2003-11-17
5
345 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hey TR!! Haven't seen you much 'round these parts,... welcome back!
0
 
LVL 28

Expert Comment

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

Author Comment

by:Mitleid242
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now