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!

Prevent exiting Access problem

Status
Not open for further replies.

wacker

Programmer
Aug 12, 2002
7
EU
I have written a database(Acess97) that prevents the user from exiting the database unless they click
on my 'Exit' button which contains the code:

forms![frmHiddenForm]!chkCanClose.Value = True
'allows frmHiddenForm to close and thus the database
docmd.quit 'continue with exit

It works as follows:
The following code is added to a form called frmHiddenForm.
On this form is a check box called [chkCanClose]. The default value = false.
This form opens up at startup and stays open but hidden.

Option Compare Database
Option Explicit
Private mfCanClose As Boolean
' Private variable to control whether form
' (and thus database) can be closed--set by
' public Property Let statement

Private Sub chkCanClose_AfterUpdate()
' Checking the check box lets the user
' close the form
mfCanClose = Me![chkCanClose]
End Sub

Property Get CanClose() As Boolean
' Property Get for the CanClose property--
' returns the value of the form variable
CanClose = mfCanClose
End Property

Property Let CanClose(fCanClose As Boolean)
' Property Let for the CanClose property--
' sets the value of the form variable and
' sets the state of the form's check box
mfCanClose = fCanClose
Me![chkCanClose] = fCanClose
End Property

Private Sub Form_Unload(Cancel As Integer)
' This code prevents the form from closing
' if the CanClose poperty is False--to
' close the form the user must click the
' check box or OLE automation code must
' set the value of CanClose to True
If Not Me.CanClose Then
' Cancel the close
Cancel = True
End If
End Sub

When the user clicks my 'Exit' button the [chkCanClose] = true and hence the database can close.

This all works fine, however, the user is unable to 'compact' the database from the tools menu.
I've tried to get around this by making the toolbar bar available only when a certain form is opened
and making the [chkCanClose] = true when this form is opened but it still does not work.

Has anyone got any thoughts, ideas etc on this.
Thanks Glen
 
Just a quick interrupt....check out faq702-1870 for in my opinion a much simplier method to prevent the closing of a form or a database.....

As for your ultimate question, in order to make this work you are probably going to have to code the compact yourself, because you hidden form is stopping the closing.....do a search and you should find a couple of examples. The secret to creativity is knowing how to hide your sources. - Albert Einstein [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top