How to use me.Dirty event

I have a bound form, with a VBA procedure for the form's BeforeUpdate event. The first sentence in the procedure is
If me.dirty = False then
     goto Exit_Procedure
end if

I am unable to detect me.dirty = False, even when click nothing except the Prev, or the Next, or Stop buttons I have provided on the form. The code behind each of these buttons checks for me.dirty then saves the record.  That codes follows:

Private Sub btnStop_Click()
    If Me.Dirty Then
        MsgBox "Dirty Stop"
        DoCmd.Save
    End If
    DoCmd.Close
End Sub

Private Sub btnPrev_Click()
    If Me.Dirty Then
        MsgBox "Dirty Prev"
        DoCmd.Save
    End If
    DoCmd.GoToRecord , , acPrevious
End Sub

Private Sub btnNext_Click()
    If Me.Dirty Then
    MsgBox "Dirty Next"
        DoCmd.Save
    End If
    DoCmd.GoToRecord , , acNext
End Sub

Can you provide reasons these events always decide me.dirty = true? Even when I press no other keys except clicking on the Prev, Next, or Stop buttons?
SowleManRetiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I have a bound form, with a VBA procedure for the form's BeforeUpdate event. The first sentence in the procedure is "

Well ... the Form BeforeUpdate will *only* trigger IF ... the Form *is* Dirty ... so, no need to test in the BU event.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
The way you would typically use Dirty is in a Save button - to Save the Current record:

Private Sub btn_Save()
    Me.Dirty = False  ' this saves the record
End Sub

However ... IF .. you happen to have any validation in the Form's BeforeUpdate event - and if the validation fails (per your spec), and you Cancel the BU event ... then you need to take that into account in the Save button code.

Private Sub btn_Save()
    On Error Resume Next ' in case BU event is cancelled
    Me.Dirty = False  ' this saves the record
    On Error Goto 0  ' reset
End Sub
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
The other reason to use .Dirty is to  make a record dirty is to force the BeforeUpdate event outside of the user.

In the past, I used to flip a control to NULL and then back to force the record dirty.

I had control code in the Before/After update events to control record operations (display of Add, Edit, Save, Cancel Buttons).

Jim.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SowleManRetiredAuthor Commented:
Thanks. I have discovered that the following code is causing the Form BeforeUpdate event to trigger:

Private Sub Partner_Enter()
    Me.Partner = Me.Partner.ItemData(0)
End Sub

Partner is a bound ComboBox in the form. My intent with the Partner_Enter event is to display the first item in the drop down list rather than make the operator click the little down arrow (often, the first item in the drop down list is the desired item).

Is there any way to retain the Partner_Enter event code and yet exit the Form BeforeUpdate code if nothing else in the form is changed?  There is a lot of validation code in the Form BeforeUpdate event that I am trying to avoid if the user has made no changes to the form.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Well, it really has been changed if you push something in there for them.  

But there are a couple things you could do to avoid that:

1. Train them to use the alt/ down arrow to drop the box.

2. Just drop the list for them when they enter the control using the dropdown method.

I'd use #2.

Jim.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SowleManRetiredAuthor Commented:
That will work. Great alternative.
0
SowleManRetiredAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 200 points for JDettman's comment #a39953601
Assisted answer: 50 points for DatabaseMX's comment #a39952384
Assisted answer: 0 points for SowleMan's comment #a39953653

for the following reason:

I appreciate that Joe and Jim tried to help me. Jim's answer was better because, simply, it will make my code run the way I want it to.

Thank you.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I am unable to detect me.dirty = False,"
I believe I explained exactly why that was ... again because the BU event was already be activated since the record was being made Dirty elsewhere, which was clearly the case - via the Enter event.

Further, dropping down a combo box automatically  upon entry really isn't good UI design. If a user is just tabbing through controls, and suddenly the combo drops down - it's very annoying to the user - and potentially a small performance hit - if the list is big.

And also noting that F4 will also drop down the list.

mx
0
SowleManRetiredAuthor Commented:
Joe -  You are correct.  The scope of your reply did include the event that I neglected to consider.  In the future, I will view answers that I get with a wider lens.  I agree that you deserved more points. Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.