X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Stop Close Event Of Form, Access 2010    
post Sep 15 2017, 03:02 AM

Posts: 538
Joined: 11-January 09
From: UK

I am trying to stop the on-close event of a form. I want to create the same effect as a windows application form for e.g. Word or Excel - i.e. users clicks the top right "x" and if changes were made - it gives you an option to save, cancel or exit...

This is what i have on the said form's on-dirty event handler:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2169 Then
    DoCmd.SetWarnings False
    Response = acDataErrDisplay = False
    DoCmd.SetWarnings True
End If
End Sub

This is what i have on the form's Before Update event handler:

Private Sub Form_BeforeUpdate(Cancel As Integer)

On Error GoTo ErrorHandler
    If Me.Dirty Then
            Dim Result As Integer
            Result = MsgBox("Would you like to save your changes?", vbCritical + vbYesNoCancel, "Save Changes?")
    Select Case Result
                Case Is = vbYes
    'Call for the Main System Audit
                   If Me.NewRecord Then
                        Call AuditChanges("RatingID", "NEW")
                        Call AuditChanges("RatingID", "EDIT")
                   End If

        Case Is = vbNo
                    DoCmd.RunCommand acCmdUndo
        Case Is = vbCancel
                    Cancel = True
                Exit Sub
            End Select
End If

Everything works well - except when i click the Cancel button - it throws me out to the source form - and cancels the edit i made - in fact i want to cancel it so i can check whether the edits are something i want to commit - to i need the edits to remain in-tact.

Or is this just not possible? I know i can create another button and control everything that way (so hide the "x") - but the client wants the "windows effect"...and i'm stumped.

Go to the top of the page
post Sep 15 2017, 07:13 AM

UtterAccess VIP
Posts: 7,242
Joined: 24-May 10
From: Downeast Maine

Is it really necessary to ask after every new record or edit whether the user wants to save their changes? Sorry, just a pet peeve of mine. Why else would I have made the changes?

Also, as a user I would be puzzled as to what Cancel means in response to a yes/no question. I either want to save the changes, or I don't. What am I cancelling?
when i click the Cancel button - it throws me out to the source form - and cancels the edit i made

I'm not sure what you mean by "throws me out to the source form". If you mean you clicked the X at the top right, I believe what happened is that you cancelled the update and the form went ahead and closed. What is your expectation for the vbCancel option?
Go to the top of the page
post Sep 15 2017, 07:44 AM

UtterAccess Editor
Posts: 16,189
Joined: 27-June 06
From: England (North East / South Yorks)


Handling update events as you close bound forms is why many turn to unbound forms. (It can just seem messy with regard to messages otherwise.)
There's an example of trying to tidy up bound form messages in the examples page linked to in my sig below. (CancelUndo I believe it's called?)

I'd agree that unnecessary messages can be annoying, though if it's a business requirement of your application then so be it. (A confirmation for update or not upon closing can even be common in unbound forms - it's just easier to make it tidy there.)


Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    22nd March 2018 - 01:05 AM