Stop users from closing access via close button on application Con

T

Todd C

Currently, I am running a database for my command. I have set it up with a
log that records how long individuals are logged on for trend analysis.
However, even after telling the users to use the installed close button, they
still insist on using the X in the upper right corner. I think the answer is
no, but is there any way to remove or hide that button?
 
M

MikeJohnB

Yes in the answer

With the form you want them to close using the close button. in design mode
for that form, select the properties of the form. Top left hand side of the
form is a little square box. if you click on it, the centre should turn
black, right click on that and select properties for the form. Now troll down
the list of option until you find Close Button, set that to no, the close
cross on the form will now be disabled.

Ok?
 
K

Ken Sheridan

I think you are probably referring to the application window's close button,
rather than that of a form. You can force a user to quit via a button on a
form by cancelling the form's Unload event procedure if they try quit in any
other way. The form won't then close, so the application itself won't close.
First you have to include a module-level variable in the form's module to
track whether the close button has been pressed, so the code for the form's
module would be like this:


Option Compare Database
Option Explicit

Dim blnCloseMe As Boolean

Private Sub cmdClose_Click()

' set value of module level variable
' to true when custom close button clicked,
' thus enforcing closure only via this button
blnCloseMe = True
Application.Quit

End Sub

Private Sub Form_Unload(Cancel As Integer)

' prevent closure of form other than
' by custom close button
Cancel = (blnCloseMe = False)

End Sub


Ken Sheridan
Stafford, England
 
B

Beetle

I would second what Ken said, but you might want to add a message
box for those "special" users who will sit there clicking the X over and
over and over. Something like;

Private Sub Form_Unload(Cancel As Integer)

' prevent closure of form other than
' by custom close button
If blnCloseMe = False Then
MsgBox "Please use the 'Close' button on the form"
Cancel = True
End If

End Sub
 
M

MikeJohnB

Mmmm, yes that is probably right Ken, the form item seemed a little simple.
Perhaps I need training in iterpretation of questions before answering them
LOL

Kindest regards
 

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