Solved

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

Posted on 2003-11-17
5
388 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
[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
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

635 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