Cancel when hitting the form X

stevenblanc

Registered User.
Local time
Today, 13:19
Joined
Jun 27, 2011
Messages
103
Hi there folks,

So little issue losing a form here.

Here's the setup:
- I have a parent form bound to a parent table with a subform bound to a subtable.

- The parent does not allow data entry and has its sole field filled by a listbox.

- The subForm is a data entry form which contains two buttons in addition to it's fields: btnCancel and btnOK

-btnOK checks to ensure that all required fields are filled out and then saves and closes the parent form. - ALL OK

- btnCancel closes undoes any changes andcloses the form - ALL OK


The issue I have is with the user utilizing the Parent form x button to close the form. For uniformity I would like to not remove this button but would like it to prompt the user whether to discard the changes if the form is dirty.

I attempted the following on both the parent and sub forms to no avail. I can't even get the event to trigger:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rspSaveorDiscard As VbMsgBoxResult
rspSaveorDiscard = vbYes

    If Me.Dirty Then
        intSaveorDiscard = MsgBox("Are you sure you want to close without saving?", vbYesNo, "Discard Changes")
        
        If rspSaveorDiscard = vbNo Then
            Cancel = True
        Else
            Me.Undo
        End if

    End If
End Sub

I was under the impression that when closing a form using the x button the before_update event was triggered first, then the close event, then the unload event.

How should I handle this?
 
To double check: I put msgbox "BeforeUpdate Firing" into both the main and sub forms and closed. No message boxes appeared.
 

Users who are viewing this thread

Back
Top Bottom