Solved

While closing access database

Posted on 2013-01-08
10
207 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
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.
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…

708 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

19 Experts available now in Live!

Get 1:1 Help Now