[AccessD] Cancel the closing of a form

Charlotte Foust cfoust at infostatsystems.com
Wed Sep 5 14:56:20 CDT 2007


You should be able to leave the close button.  The Unload event has a
cancel argument.  If fires when you try to close the form, so you can
cancel the close in the Unload event.

Charlotte Foust

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
rusty.hammond at cpiqpc.com
Sent: Wednesday, September 05, 2007 12:46 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Cancel the closing of a form

I was afraid of that.  I was hoping to be able to leave the native close
button.

Thanks for the help.

-----Original Message-----
From: Steve Schapel [mailto:miscellany at mvps.org]
Sent: Wednesday, September 05, 2007 1:40 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Cancel the closing of a form


Rusty,

I would expect the form to still close if you click either 'Yes' or 'No'

on the message box.  I thought that would be the desired behaviour.

In the case of 'Cancel', you don't want the form to close, right?  Ok, I
now see that the idea I suggested before was over-simplistic.  Sorry. 
If you remove the native [X] Close button, and close the form via a
command button on the form, I think this will work:

Private Sub YourCommandButton_Click()
    On Error GoTo abandon
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close acForm, Me.Name
abandon: If Err.Number = 2501 Then Exit Sub End Sub

... and then the Before Update code as I suggested before:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim answer As Integer
    answer = MsgBox("Save changes?", vbYesNoCancel)
    If answer = vbNo Then
       Me.Undo
    ElseIf answer = vbCancel Then
       Cancel = True
    End If
End Sub

Regards
Steve


rusty.hammond at cpiqpc.com wrote:
> Steve,
> 
> When I put that code in the BeforeUpdate the form still closes.
> 
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

**********************************************************************
WARNING: All e-mail sent to and from this address will be received,
scanned or otherwise recorded by the CPI Qualified Plan Consultants,
Inc.
corporate e-mail system and is subject to archival, monitoring or review
by, and/or disclosure to, someone other than the recipient.
**********************************************************************
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list