Solved

How to use me.Dirty event

Posted on 2014-03-24
9
4,501 Views
Last Modified: 2014-03-25
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?
0
Comment
Question by:SowleMan
  • 4
  • 3
  • 2
9 Comments
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 50 total points
ID: 39952384
"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
 
LVL 75
ID: 39952389
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
 
LVL 57
ID: 39952902
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
 

Author Comment

by:SowleMan
ID: 39953551
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 200 total points
ID: 39953601
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
 

Author Comment

by:SowleMan
ID: 39953653
That will work. Great alternative.
0
 

Author Comment

by:SowleMan
ID: 39954069
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
 
LVL 75
ID: 39953840
"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
 

Author Comment

by:SowleMan
ID: 39954063
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now