Solved On dirty reset possible? (1 Viewer)

Local time
Today, 17:37
Joined
Feb 2, 2020
Messages
54
I am trying to generate an event each time the user changes a field on a single record. In other words, the user changes one field, then the event gets triggered, when the user moves to another field on that same record and changes that field another event would be generated.

I can get the first event to trigger by using On Dirty, but I can't re-set the form to be able to re-generate the next event once the user moves on to another field.

Thank you.
 
Last edited:

Minty

AWF VIP
Local time
Today, 22:37
Joined
Jul 26, 2013
Messages
10,366
The form has an OnDIrty event that (and I'm guessing because I haven't ever used it) probably fires whenever the form becomes dirty.
Worth a look at?
 
Local time
Today, 17:37
Joined
Feb 2, 2020
Messages
54
The form has an OnDIrty event that (and I'm guessing because I haven't ever used it) probably fires whenever the form becomes dirty.
Worth a look at?
Sorry, I meant to say that I am using On Dirty, but once a single field is changed any subsequent fields that are changed does not trigger On Dirty any more. I need to re-set On Dirty or find a different way. Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:37
Joined
May 21, 2018
Messages
8,525
As was stated the on dirty fires on the first time the form becomes dirty, I do not believe it fires on subsequent occasions if you set dirty = false.

If you want to do it each time the user changes a field and you have lots of fields and do not want to write multiple event procedures.
1. Make a common function
2. call this function in each controls on enter event. You can select all controls at once and type in the function name.

Public Function CommonEvent()
'if you need to do something specifically with the control calling the function then
'dim ctrl as access.control
' set ctrl = activecontrol
end function

in the onenter type in
=PublicFunction()
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:37
Joined
May 21, 2018
Messages
8,525
see demo
 

Attachments

  • EventDemo.accdb
    564 KB · Views: 257

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:37
Joined
May 21, 2018
Messages
8,525
I would not use the on change event. If it is a textbox that will occur on every letter typed.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:37
Joined
Feb 28, 2001
Messages
27,138
Here is the problem: Access won't tell you anything you didn't tell it first. Access has a Form "Dirty" flag but not a "control" dirty flag. That is because it is really more associated with the RECORD's information, not the form. It is saying the RECORD is potentially dirty. (It is also why there is no DIRTY flag on an unbound form.) If you want to know if an INDIVIDUAL field has changed, then you have to plan ahead for that question. The method I used was in parts:

1. Every field for which I had an interest in "change" was either bound or unbound. This recording was in the "OnCurrent" event. For unbound forms it was trickier since there IS no OnCurrent event for such forms. For the unbound cases, I had variables set aside to record the old values. I usually had a "ResetForm" subroutine that would go through and reset the contents of a form. If it was a form for which I wanted to setup up the "change" event you described, that is where the "old value" resets would occur.

2. For every control where I wanted this information, I used the LostFocus event to compare the current contents of the form vs. the .OldValue (if it had one) or the stored prior value (if not bound). I also had a flag that told me if the user had tab-cycled through all of the fields a second time so that I wouldn't trigger the action a second time on the same control.

3. Because the last control on the form was tab-cycled back to the first (no auto-navigate), I had a separate action control button to do the Save. Since clicking that control DID generate a LostFocus from that last data control, there were no holes in the coverage.

Just one man's take on the problem.
 

Users who are viewing this thread

Top Bottom