Solved

How to use me.Dirty event

Posted on 2014-03-24
9
4,860 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2016 - query 23 61
Create report using crosstab query 11 29
Microsoft Access - Stopping Control - (minus) 4 32
Dcount help 2 16
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 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