On Dirty

Rockape

Registered User.
Local time
Today, 11:46
Joined
Aug 24, 2007
Messages
271
Hi,

Would anyone please explain to me in simple terms or with an example when or how the "On Dirty " property works.

Thanks
 
Last edited:
When a record is accessed, the first time any bound control on a bound form has data entered/edited, the form becomes Dirty and the OnDirty event is executed. Sounds simple, but this is Access, so naturally it isn't!

This occurs only the first time! If the same control has data entered a second time or another control has data entered, the form is still Dirty, but the OnDirty event will not execute again.

If data is entered into a Control thru VBA code, say

Me.MyTextbox = "Some Value"

or any other way except physically entering the data, the form will be Dirty, but the OnDirty event will not execute!

If data is entered into a Control thru VBA, as noted above, the form will be Dirty but subsequent physically entering data into the form will not cause OnDirty to execute.

Lastly, data entered by way of a control's Default Value while it 'enters' data, does not make the form Dirty and it does not cause the OnDirty event to fire.

Linq ;0)>
 
Hmmmm.... not very clear.

When would OnDirty become useful? or when is it needed?
 
when is it needed? .... well that is up to you

there are hundreds of form and other events that your app can make use of. some of them are "obvious" - others are more subtle, and many are generally interchangeable, although there is a slight difference in the timing of the event, which may make one version more useful than others for a given effect.

eg - when a form opens there are these events (among others) - the first three do fairly similar things, but with some nuances. you can use any or none of these, depending what you want your app to do. The timing of them is slightly different, so eg, the open event can test things, and decide as a result to cancel itself - but the load event cannot abort.

open
load
activate
current

with respect to the dirty event - if you NEED your app to do something immediately at the moment when you edit a record, (ie so that it becoems dirty, and it will subsequently need saving), then the "dirty" event may be one for you to use, at that point. On the other hand, at the time the record is saved there is a beforeupdate event, and immediately after there is an afterupdate event. for a new record there is also a beforeinsert and an afterinsert event.


The Dirty event is certainly one used less frequently - as are KeyPress, and MouseMove events - but they are all useful tools to have available. Access (Windows) actually issues a constant stream of events. You just set your app to "listen for" and "react to" a subset of a selected number of these events.
 
Hmmmm.... not very clear.

When would OnDirty become useful? or when is it needed?

To provide an additional example:

I have a series of forms that are used by persons who are not very familiar with Access. They really like the idea of having a button they push that saves what they have entered.

So what I do, is I have a button on my form called "Save". The button is by default not enabled (greyed out). As soon as someone make any sort of change (i.e. "dirties it"), I make the button enabled. This seems to flow well with the users as they know anytime the button is not greyed out, they have made changes and they want to save them.
 
Hi,

Would anyone please explain to me in simple terms or with an example when or how the "On Dirty " property works.

Thanks
On Dirty is not a property, it's an event, so,

  • When does the On Dirty event work? All the time.
  • How does it work? When you write code in it.
But when does a form become 'Dirty' is a different question. It becomes dirty when a record is editted or changed. For new records, it becomes dirty when you first type into any bound control. Only bound forms have a dirty property. Once a record is saved, the form is no longer dirty. All of this missinglinq explained. The attached image shows you what the form looks like when it becomes dirty so play around with your form to understand when the icon appears.
 

Attachments

  • Is Dirty.JPG
    Is Dirty.JPG
    10.9 KB · Views: 1,412
Of course, it's also 'dirty' if you're clumsy and spill coffee on it!:D
 
You would process that at granular level....Instantly most likely.... however it not all black and white is it?
 
Or direct it at the CPU and hope for the best. Remember to backup :eek:
 
Thanks all, for your views....i might go now and have my unspilled coffee. ;)
 

Users who are viewing this thread

Back
Top Bottom