?
Solved

While closing access database

Posted on 2013-01-08
10
Medium Priority
?
212 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 800 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 800 total points
ID: 38757223
you can also attach similar code to the On Close event on the form
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 600 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 600 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

801 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