My answer to your problem got posted as a new message and not a
follow-up to this one:
Yes, there is a way of forbidding a form being closed if you create a
boolean variable (blnCanClose) in the form's Open and Unload event. I
didn't read all the responses, but I have just such a form that cannot
be closed using the close button. They must first select a button,
then the form closes. Here's the skeleton code:
In general declarations of form: Dim blnCanClose As Boolean
Private Sub Form_Open(Cance l As Integer)
' make sure bln is always false when form is opened
' can't be closed until variable = true
blnCanClose = False
End Sub
Private Sub Form_Unload(Can cel As Integer)
If blnCanClose = False Then
MsgBox "Please Select a Date!"
' input person needs to select a date
' code then uses selected date to perform something
' call function or press a command button
Cancel = True
Else
Cancel = False
End If
End Sub
Private Sub cmdPerformFunct ion_Click()
' code for whatever you want performed from this form
' variable = true, form can now be closed after function executed
blnCanClose = True
' close the form after this button is pressed
DoCmd.Close acForm, Me.Name
End Sub
Trevor Best <bouncer@localh ost> wrote in message news:<6i******* *************** **********@4ax. com>...
On 14 Oct 2003 16:02:54 GMT in comp.databases. ms-access, Peter yeshew
<fr*******@abv. bg> wrote:
Is it possible to forbid closing the form through the File- Close menu ?
On my form i have a command button called CmdDeleteInvoic e. When this
command button is visible ,i want to forbid the user from closing the
form through the menu commands file-close.I want to make him click the
button and not to allow him to do any other actions.And to disalloe the
forbid comand if the button is clisked.How can i do it ? Obviously i
have to build an If..Else clause
in the OnClause event ?
If deleting the invoice is the only course of action that can be
accomplished then why have a button to do it? Just delete it in the
close event of the form.