Solved

While closing access database

Posted on 2013-01-08
10
209 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
  • 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 84

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 - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 150 total points
ID: 38761427
Like so:

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

mx
0
 
LVL 84
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now