How to prevent Access (Form) from being closed inadvertently

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I like code something like this:

In Module:
Option Compare Database
Option Explicit
Dim SwExit As Boolean

Public Sub AutoExec () ' Called in macro AutoExec
SwExit = False
DoCmd.OpenForm "frmNotToBeClosed Inadvertently"
End Sub

in frmNotToBeClosed Inadvertently:

Private Sub Form_Unload(Cancel As Integer)
Dim Rc

If WindowsIsClosing Then SwExit = True

If Not SwExit Then

Rc = MsgBox("You are about to close frmNotToBeClosed Inadvertently '" & _
vbCrLf & " " & _
vbCrLf & "Are you sure you want to close?" _
, vbExclamation + vbYesNo + vbDefaultButton2, _
"Closing Form")

If Rc <> vbYes Then Cancel = True

End If

End Sub

The question is how do I code function WindowsIsClosing?

Jos
 
Have you considered disabling the close/form and Quit/App
using the (X) and disabling the file/close/exit on the
menubar and adding a Close/Quit Application button on you form.

Chris
 
Chris,

I have considered your suggestion, but it would not solve my problem; what I
actually want is that the database and the form (that is used for printing
labels on a Dymo Label Writer) that are started at PC powerup and logon to
windows, cannot be closed inadvertently (since it polls the server for
printdata every once in a second via the on Timer event) but should be closed
without for the user eiry messages that the program is not responding etc at
logoff and shutdown of the PC, because the users are handicapped people and
are a little afraid of computers.

If I make a button to close the form and Access, they could still close the
application inadvertently using this button and would be required to use this
button at logoff time, but the application is always minimized, so they would
not be aware of the program running.

So my question still is how to distinguish between an attempt to close down
the form and/or access and a logoff from windows?

Jos
Jos
"Chris Reveille" schreef:
Have you considered disabling the close/form and Quit/App
using the (X) and disabling the file/close/exit on the
menubar and adding a Close/Quit Application button on you form.

Chris
 
I have visually impaired users. We use the software JAWS.
I added to the close form for access a message asking if
that is what they want to do. If they are closing down
Windows Access will close anyway. I guess I am not sure
what you are trying to accomplish.

chris
-----Original Message-----
Chris,

I have considered your suggestion, but it would not solve my problem; what I
actually want is that the database and the form (that is used for printing
labels on a Dymo Label Writer) that are started at PC powerup and logon to
windows, cannot be closed inadvertently (since it polls the server for
printdata every once in a second via the on Timer event) but should be closed
without for the user eiry messages that the program is not responding etc at
logoff and shutdown of the PC, because the users are handicapped people and
are a little afraid of computers.

If I make a button to close the form and Access, they could still close the
application inadvertently using this button and would be required to use this
button at logoff time, but the application is always minimized, so they would
not be aware of the program running.

So my question still is how to distinguish between an attempt to close down
the form and/or access and a logoff from windows?

Jos
Jos
"Chris Reveille" schreef:
 
Chris,

What I am trying to accomplish, is that the (impaired) user gets a critial
message if he/she want to close the form or access itself, but gets no
message if he/she signs off from windows. If one signs of from Windows with
Access running minimized with the code I have now (without the
WindowsIsClosing function) than an alert message appears that Access is not
responding. This I want to prevent, as they get paniccy of such a message. To
that purpose I will have to know if they try to close access by means of the
red cross in the upper right corner or if access is notified to close because
windows is closing. Perhaps some windows message is being passed around that
I can look for by means of an API, but I would not know which API and what to
look for or perhaps there is a simpler way?
 
Back
Top