[AccessD] Cancel the closing of a form

rusty.hammond at cpiqpc.com rusty.hammond at cpiqpc.com
Wed Sep 5 08:40:41 CDT 2007


Steve,

When I put that code in the BeforeUpdate the form still closes.

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


Rusty,

Simply use the Before Update event of the form.

If the current record has not changed, the Before Update event will not 
occur.

If the current record has changed, the code that fires could be along 
these lines:

    Dim answer As Integer
    answer = MsgBox("Save changes?", vbYesNoCancel)
    If answer = vbNo Then
       Me.Undo
    ElseIf answer = vbCancel Then
       Cancel = True
    End If

Regards
Steve


rusty.hammond at cpiqpc.com wrote:
> I have a form that when I close it either from a close button on the form
or
> from the built in close button, I want to test if the current record has
> changed.  If it has changed, I want to prompt the user to either Save the
> record and go ahead and close the form, not save the record and close the
> form, or not save the record and not close the form via a YesNoCancel
> message box.
> 
> If I use the close event of the form testing for me.dirty doesn't work
> because the record is already saved.
> 
> Is there any way to do this?
-- 
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