UtterAccess.com
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    
 
   
Brepea
post Sep 15 2017, 03:02 AM
Post#1



Posts: 515
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:

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


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

CODE
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")
                   Else
                        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.

Thanks
Go to the top of the page
 
BruceM
post Sep 15 2017, 07:13 AM
Post#2


UtterAccess VIP
Posts: 7,022
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?
QUOTE
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
 
LPurvis
post Sep 15 2017, 07:44 AM
Post#3


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


Hi

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

Cheers

--------------------
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    15th December 2017 - 09:00 AM