Solved

While closing access database

Posted on 2013-01-08
10
211 Views
Last Modified: 2013-01-14
Dear Experts,
Can somebody help me to get a vba code to- pop up a message box - when a user closing the access database? The user can continue or quit the database based on the yes or no message from the pop up.Please help
0
Comment
Question by:gtmathewDallas
[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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 75
ID: 38756995
Unfortunately, there is no Event that occurs when the Access App window closes. So, this is the standard alternative:

http://access.mvps.org/access/general/gen0005.htm

mx
0
 
LVL 70

Accepted Solution

by:
KCTS earned 200 total points
ID: 38757219
you can use a message box

If MsgBox("Are you sure you want to quit?", vbQuestion + vbYesNo + vbDefaultButton2, "Quit") = vbYes Then
DoCmd.Quit
End If
0
 
LVL 70

Assisted Solution

by:KCTS
KCTS earned 200 total points
ID: 38757223
you can also attach similar code to the On Close event on the form
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 150 total points
ID: 38758155
I use a hidden form that is opened when the database starts. In the UnLoad event of that form, I include code like KCTS suggests above, except I use the Cancel argument as needed:

Private Sub Form_Unload(Cancel As Integer)
  If Msgbox("Are you sure you want to exit?", vbYesNo,"Confirm Exit) <> vbYes Then
    Cancel = True
    '/  you might reopen the default form - like a menu - ere
  End If
End Sub

Access cannot close until all Forms are closed, so if you Cancel the Unload event of your form, Access will stay open.

You could also do this on a form that is always open - but in my experience, users will find a way to close that one as well! They can't close a hidden form ...
0
 
LVL 75
ID: 38759107
just noting the Hidden form ideal is basically that of the MVPS KB.

mx
0
 

Author Comment

by:gtmathewDallas
ID: 38760201
I am not able to set the form as hidden..
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 150 total points
ID: 38761427
Like so:

docmd.OpenForm "YourFormName",,,,,acHidden

mx
0
 
LVL 85
ID: 38762360
just noting the Hidden form ideal is basically that of the MVPS KB.
sorry Joe, I didn't note that. I read the part about the public variables and thought it was that trick.

I am not able to set the form as hidden.
See mx's example, but if that's not what you meant, tell us what you mean by "not able to set the form as hidden". If you mean you have a Startup form that must be displayed, then that's understandable - you wouldn't want that to be hidden. In cases like that, you would add a new form and open that one as hidden, using mx's example. You could do this in the Open or Load event of that Startup form.
0
 
LVL 75
ID: 38763020
oh no problem.  In fact, I had to double check the kb to be sure it was using the hidden form.
0
 

Author Comment

by:gtmathewDallas
ID: 38775215
Thank you All
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

688 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