By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Run On Close Form Event If DB is Closed

P: n/a
AP
IS there a way to run a procedure if the users close access directly
rather than closing a menu screen that I have built? There is an event
that works on close for this form, but it doesnt seem to run if the
form is open and the suer just closes access all together, is there a
way around this?
Thanks

Nov 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
One thing you can do that's a bit of a dirty trick is to run a hidden,
minimized form when your database opens. This form will have the code
you want to run when the dbase closes in its Form_Close event. When the
user closes the database, the hidden form's Form_Close event will
eventually get fired, and your code will run.

Nov 23 '05 #2

P: n/a
On 23 Nov 2005 10:19:00 -0800, "AP" <ap******@thompsongroup.com>
wrote:
IS there a way to run a procedure if the users close access directly
rather than closing a menu screen that I have built? There is an event
that works on close for this form, but it doesnt seem to run if the
form is open and the suer just closes access all together, is there a
way around this?


Something doesn't seem right. You are saying that you have an open
form and that open form has an event procedure in its On Close event
and that if a user selects the 'x' in the upper right hand corner to
close Access that your On Close event procedure doesn't fire?

If so, I fail to see how Steve's idea of adding a hidden form with
"just another" On Close event will help.

mike
Nov 24 '05 #3

P: n/a
Mike Preston wrote:
On 23 Nov 2005 10:19:00 -0800, "AP" <ap******@thompsongroup.com>
wrote:

IS there a way to run a procedure if the users close access directly
rather than closing a menu screen that I have built? There is an event
that works on close for this form, but it doesnt seem to run if the
form is open and the suer just closes access all together, is there a
way around this?

Something doesn't seem right. You are saying that you have an open
form and that open form has an event procedure in its On Close event
and that if a user selects the 'x' in the upper right hand corner to
close Access that your On Close event procedure doesn't fire?

If so, I fail to see how Steve's idea of adding a hidden form with
"just another" On Close event will help.


I believe his thinking is as so:

On startup open the first form as hidden whether this is done with an AutoExec macro or
setting the Startup Form option.

Because it is hidden the user can't close it themselves.

Because it is the first form opened it will be the last form closed.

Use the form's Unload event to run whatever code you need to execute prior to the instance
of Access closing.

--
'---------------
'John Mishefske
'---------------
Nov 24 '05 #4

P: n/a
On Thu, 24 Nov 2005 07:55:35 GMT, John Mishefske
<jm**********@SPAMyahoo.com> wrote:
Mike Preston wrote:
On 23 Nov 2005 10:19:00 -0800, "AP" <ap******@thompsongroup.com>
wrote:

IS there a way to run a procedure if the users close access directly
rather than closing a menu screen that I have built? There is an event
that works on close for this form, but it doesnt seem to run if the
form is open and the suer just closes access all together, is there a
way around this?

Something doesn't seem right. You are saying that you have an open
form and that open form has an event procedure in its On Close event
and that if a user selects the 'x' in the upper right hand corner to
close Access that your On Close event procedure doesn't fire?

If so, I fail to see how Steve's idea of adding a hidden form with
"just another" On Close event will help.


I believe his thinking is as so:

On startup open the first form as hidden whether this is done with an AutoExec macro or
setting the Startup Form option.

Because it is hidden the user can't close it themselves.

Because it is the first form opened it will be the last form closed.

Use the form's Unload event to run whatever code you need to execute prior to the instance
of Access closing.


Well, I certainly agree with your last comment. The unload event is
what I use to preclude exiting. However, that is because I don't want
the form to unload. While the On Close event can't be cancelled, it
most assuredly will run if the user clicks any "X" that will exit
Access. Won't it?

And if the OP's problem is that the OnClose of the open form isn't
firing, I'd be worried about that (corruption?).

mike
Nov 24 '05 #5

P: n/a
Use your Main MenuForm or a hiddenform.

Option Compare Database
Option Explicit
Dim blnDbCanClose As Boolean

Private Sub Form_Unload(Cancel As Integer)
If Not blnDbCanClose Then Cancel = True
End Sub

Private Sub BtnClose_Click()
If MsgBox("Want to quit?", vbInformation + vbOKCancel, "Log out") = vbOK Then
blnDbCanClose = True
DoCmd.Quit
End If
End Sub

If you use your Main MenuForm you will have to set the blnDbCanClose to True to go to design view ...
So if you are using a hidden form I guess it is more convenient.

Arno R

"Mike Preston" <mb******@pacbell.net.invalid> schreef in bericht news:43*****************@news.INDIVIDUAL.NET...
On 23 Nov 2005 10:19:00 -0800, "AP" <ap******@thompsongroup.com>
wrote:
IS there a way to run a procedure if the users close access directly
rather than closing a menu screen that I have built? There is an event
that works on close for this form, but it doesnt seem to run if the
form is open and the suer just closes access all together, is there a
way around this?


Something doesn't seem right. You are saying that you have an open
form and that open form has an event procedure in its On Close event
and that if a user selects the 'x' in the upper right hand corner to
close Access that your On Close event procedure doesn't fire?

If so, I fail to see how Steve's idea of adding a hidden form with
"just another" On Close event will help.

mike

Nov 24 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.