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
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