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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep database from closing 1

Status
Not open for further replies.

MelissaT

Programmer
May 16, 2002
67
US
I have an Access 2000 database that is going to be used by the public and I would like the database to remain open until a staff member wants to shut it down. Obviously, I can just not put an exit button on the Main Menu, but that doesn't keep users from clicking on the "X" to close the program. I tried putting a docmd.cancelevent in the On_Close Event of the form, but it still closes. Anybody have any ideas? Melissa
Designing Access databases since 1999
 
Melissa,

You're thinking along the right lines.

Here's code from the unload event of my switchboard form, which is never closed (though it's often invisible):
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

Errortrap is my standard error handler. You'll want to change that to whatever you use.

AllowExit is a boolean function that checks the tag of the close button on this form. Here's that function:
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

Oh, and the event for cmdQuit first sets the tag to "allow exit" and then calls application.quit.

Hope this helps.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.


Remember to reward helpful tips with the stars they deserve.
 
Thanks!

I give it a try. Melissa
Designing Access databases since 1999
 
With a few modifications, that worked great! Thank you so much. You just saved me a lot of time.
Melissa
Designing Access databases since 1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top