Looking for alternatives to Form_Close (1 Viewer)

JC10001

Registered User.
Local time
Today, 13:05
Joined
Sep 24, 2003
Messages
48
Hi guys,

I have a form with a few text fields in it. What I want to do is have a msg box pop up if the user leaves the form and the form is dirty. The msg box would then give the user the opportunity to save the changes or cancel before moving to the next form.

What I've done that works, is place the code into the click events of all of the buttons on the form. This gets the job done but it also needlessly duplicates code. I then tried to do the same thing with a form_close event and the form just closes and saves the changes without prompting the user first.

Are there any form events that will allow me to do what I would like to do or will i just have to place all of the code into a function and then place a call to that function in each buttons' click events?

Thanks.
 

Mile-O

Back once again...
Local time
Today, 13:05
Joined
Dec 10, 2002
Messages
11,316
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Dirty Then
        If MsgBox("Would you like to save the changes?", vbQuestion + vbYesNo, "Save Changes?") = vbNo Then
            Cancel = True
        Else
            DoCmd.RunCommand acCmdSaveRecord
        End If
    End If
End Sub
 

Fuga

Registered User.
Local time
Today, 14:05
Joined
Feb 28, 2002
Messages
566
What does it mean when a form is "dirty".:confused:

Fuga.
 

JC10001

Registered User.
Local time
Today, 13:05
Joined
Sep 24, 2003
Messages
48
Fuga said:
What does it mean when a form is "dirty".:confused:

Fuga.

It means that one of the text fields has changed. The form has been altered, tainted, therefore dirty.
 

Fuga

Registered User.
Local time
Today, 14:05
Joined
Feb 28, 2002
Messages
566
Ok, thanks. Didn´t know that.

Fuga.
 
R

Rich

Guest
You don't need to test for Dirty, the Before Update Event of the form will only fire when the form is dirtied anyway
 

Users who are viewing this thread

Top Bottom