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
Closing Access
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Closing Access
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.
This form should be opened when the database is opened, and remain open.
The code behind the form shows how it is done.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1488
- Joined: 05 Feb 2010, 22:25
Re: Closing Access
Hans you always make my day!!! I knew if anyone had a solution to this it would be you!
Thanks,
Leesha
Thanks,
Leesha
-
- BronzeLounger
- Posts: 1488
- Joined: 05 Feb 2010, 22:25
Re: Closing Access
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
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
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Closing Access
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
Hans
-
- BronzeLounger
- Posts: 1488
- Joined: 05 Feb 2010, 22:25
Re: Closing Access
Perfect! Thanks again!
-
- BronzeLounger
- Posts: 1488
- Joined: 05 Feb 2010, 22:25
Re: Closing Access
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
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
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Closing Access
You have to copy the line
Private CanClose As Boolean
and paste it above the two procedures, below Option Explicit and Option Compare Database.
Private CanClose As Boolean
and paste it above the two procedures, below Option Explicit and Option Compare Database.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1488
- Joined: 05 Feb 2010, 22:25
Re: Closing Access
That did the trick!
Thanks,
Leesha
Thanks,
Leesha