Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Access with title bar "x" or Exit? 1

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
US
I've been told that when one closes Access with the "x" on the title bar, locking problems occur with multiple users, but if Access is closed using Quit for File menu/Exit, this problem doesn't occur. Has anyone heard of this? If so, can the titlebar "x" be inactivated? Thanks, Dan.
 
Hi Eric, thanks for the link. I pulled this from the link:

"Please note that this technique affects the Close button on the application window of Microsoft Access, not the Close button on the Database window."

I'm not sure if the problems with table locking comes from the close button on the Database window vs. the application window. Have you heard either way? Dan.
 
I honestly haven't had any problems with either close button. (Access 2002, Windows 2000)
But if you want to keep people from closing the database window you could create a navigation form and hide the database window. Tools/startUp uncheck display database window.

HTH,
Eric
 
Yes, you can disable the X. But I think there's a misunderstanding somewhere. Closing Access with the X is not any different from closing with the quit menu item, so far as I know. But there are good closings and bad closings.

It's much better to make sure that all of your connections to the back end (data side) of the database are closed before closing Access. And there are often clean-up tasks that get performed in code when a database closes. So it is usually best to control how a user closes the database. You can't stop a user from giving the old three-finger salute, hitting the power button, or kicking out the power cord. But you can give the user a good indication of how you want the database closed.

I have never bothered to disable the X. There's a way to do it with a lot less code, and to actually give the user some feedback. Here's how I go about it...

First, make one of your forms stay open the entire time the user is in the database. I always have some sort of switchboard form in my applications (not built by a wizard, but it does the same task--gets the user to whatever function he or she wants), so I use that one. You can make the form invisible, if you want, but make it the first form opened and make sure it never gets closed.

In the Unload Event of this form, put code something like this:
[tt]Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Error
If AllowExit = False Then
Cancel = True
End If
Exit Sub
Error:
ErrorTrap Err.Number, Err.Description, "Form Unload", "frmSwitchboard"
End Sub[/tt]

Here's the AllowExit function:
[tt]Public Function AllowExit() As Boolean
'(c)Copyright 2/6/01 Jeremy Wallace
On Error GoTo Error
Dim sSql As String
If Forms!frmswitchboard!cmdQuit.Tag = "allow exit" Then
AllowExit = True
Else
AllowExit = False
MsgBox "To close this application, first close all forms and the click 'Quit' on the" _
& " Switchboard form.", vbExclamation
End If
Exit Function
Error:
ErrorTrap Err.Number, Err.Description, "AllowExit"
End Function[/tt]

In the button you want users to use to close your database, put this code:
[/tt]Private Sub cmdQuit_Click()
On Error GoTo Error

Forms!frmswitchboard!cmdQuit.Tag = "allow exit"
db.Close
Set db = Nothing
Application.Quit

Exit Sub
Error:
ErrorTrap Err.Number, Err.Description, "cmdQuit Click", "frmSwitchboard"
End Sub[/tt]

That's all there is to it. Now, when a user tries to close the database by clicking on that lovely little X, he or she will get a polite message, with instructions on how to properly close the database.

The ErrorTrap function is documented on my website. You can just yank it or use your own.

Hope this helps.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Thanks JeremyNYC for getting me on track. Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top