Closing Access

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Closing Access

Post by Leesha »

Hi,
I have a database that has a command button to close the database which works fine if the user chooses to use it. Inevitably someone will close the database by clicking the X to close the Access software. This results in an error if there is code on the close event of a form that was open when the user hits the Access X to close. I've tried using the docmd.setwarnings false but that doesn't work. I looked to see if there are settings for the database but didn't see anything. Is there a way around this?
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Closing Access

Post by HansV »

See the attached database for a way to prevent the user from closing the database except through a button on a form.
This form should be opened when the database is opened, and remain open.
The code behind the form shows how it is done.

NoClose.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Closing Access

Post by Leesha »

Hans you always make my day!!! I knew if anyone had a solution to this it would be you!
Thanks,
Leesha

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Closing Access

Post by Leesha »

Hi Hans,
When I go to put the form into design view to look at the code it won't go into design view. There is nothing saying to enable the database. When I click the close database button it does close however I can't seem to view the code. Can't wait to see what it says!
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Closing Access

Post by HansV »

Hold down the left Shift key when opening the database. This prevents the form from being opened automatically. You can then open it in design view.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Closing Access

Post by Leesha »

Perfect! Thanks again!

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Closing Access

Post by Leesha »

Hi Hans,
I Copied and pasted the 2 pieces of code into the database I'm working on. I'm getting a compile error that says "Variable Not defined" and CanClose is highlighted. If I import the form into the database the form works. I'm not sure what I'm doing wrong.
Thanks,
Leesha

User avatar
HansV
Administrator
Posts: 78233
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Closing Access

Post by HansV »

You have to copy the line

Private CanClose As Boolean

and paste it above the two procedures, below Option Explicit and Option Compare Database.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Closing Access

Post by Leesha »

That did the trick!
Thanks,
Leesha