Stop users from closing forms by right clicking on the task bar

A

Adam Thwaites

All my database have forms with a Close button on them. This is so they
records they are in can be set to available when they are closed. I have
disabled all the Xs form the top left of the windows but users can still
close forms by right clicking it on the task bar and selecting Close.

I'v tried to put code in the Unload event but by the time this runs the form
has already closed so it is no use.

How do I disable the Close option on the task bar?
 
A

Allen Browne

Adam, you must use the BeforeUpdate event of the form if you wish to
validate the record before it is saved.

Otherwise you will go mad trying to block all the other possible ways the
record could be saved such as:
- Alt+F4
- Ctrl+F4
- Closing Access
- Closing Windows down
- Logging off Windows
- Closing the form
- Changing the sort order
- Pressing Shift+Enter
- Choosing Save Record from the menu
- Reassigning the form's RecordSource
- Moving to a different record
- Right-click, and change the sort
- Change the sort through the toolbar
- Right-click and filter
- Applying a filter through the toolbar
- Requerying the form (F9 or Shift+ F9)
- Cycling past the end of the tab order
- Using the navigation buttons to move record
- Using the toolbar to move record

Need we go on? Form_BeforeUpdate is your *only* choice.
 
A

Adam Thwaites

Hi Allen, the only problem i'm having is with that paticular close option, I
have stopped all the other ways of closing apart from the below, which my
users are well aware not to do.
- Closing Access (via Task Manager)
- Closing Windows down
- Logging off Windows

The forms BeforeUpdate almost works, but some of my forms have sub forms on,
which shifting focus to also triggers the BeforeUpdate.

Do you not know of a way to stop just the taskbar close option?
 
R

Rick Brandt

Adam said:
Hi Allen, the only problem i'm having is with that paticular close
option, I have stopped all the other ways of closing apart from the
below, which my users are well aware not to do.

But "closing" is not the only way for a record to be saved. Did you read
Allen's list?
 
A

Allen Browne

Adam, you are aware that each bound form (including your subform) has its
own Form_BeforeUpdate event?
 
C

Craig Alexander Morrison

Ignoring the issue of saving data which others have addressed.

If you want to stop a user from closing your form/application/access then
insert code like this in the Unload.

Private Sub Form_Unload(Cancel As Integer)

If Me.ShutDownConfirmed.Value Then
Cancel = False
Else
Cancel = True
End If

End Sub


This is a sample of code the we have that has a hidden checkbox
ShutDownConfirmed and unless it is checked you cannot close the
form/application/access.

Private Sub cmdShutDown_Click()

Me.ShutDownConfirmed.Value = True
DoCmd.Close

End Sub

The above is the code around the button that can close the form.

The main thing to remember is the use of Cancel = True will terminate an
unload event.

--
Slainte

Craig Alexander Morrison
Crawbridge Data (Scotland) Limited

Small Business Solutions Provider
 
A

Adam Thwaites

Excellent, I used a global variable set to false when the forms opens and
when a new record is loaded, and that is set to true when my close button is
clicked:

Private Sub Form_Unload(Cancel As Integer)
If varAllowExit Then
Cancel = False
Else
Cancel = True
End If
End Sub

Cheers Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top