Solved

While closing access database

Posted on 2013-01-08
10
208 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
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.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

11 Experts available now in Live!

Get 1:1 Help Now