Solved

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

Posted on 2003-11-17
5
375 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

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

828 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