[AccessD] Cancel the closing of a form

rusty.hammond at cpiqpc.com rusty.hammond at cpiqpc.com
Wed Sep 5 14:46:11 CDT 2007


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



More information about the AccessD mailing list