Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-17
5
Medium Priority
?
393 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 135 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 240 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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