Form_Dirty problem

  • Thread starter BBC via AccessMonster.com
  • Start date
B

BBC via AccessMonster.com

After having read many "Dirty" problems I did not see my particular issue so
looking for help.
I have a subform where I enable/disable my own navigation controls (next,
prev., undo, delete, ...) via my own "dirty" routine which is normally
triggered by the Form_Dirty event. However, while the Form_Dirty event fires
properly when editing existing records is does not fire when editing a NEW
record which has just been added via:
DoCmd.GoToRecord , "" ,acNewRec
I do initialize some controls/textboxes/combos on the form via VBA code and
some have their default values set in their properties. None of these seem
to fire the F_D event (and don't expect them to). I'd prefer to use the forms
dirty event than have to put some code in every control & TB on the form to
call MY dirty routine (which I already do some of for those set via VBA).
Exactly the same (private) code is used to manage the dirty event on my main
form and it works fine.
The subform is PopUp & Modal
Help or suggestions appreciated.
 
D

Dirk Goldgar

BBC via AccessMonster.com said:
After having read many "Dirty" problems I did not see my particular issue
so
looking for help.
I have a subform where I enable/disable my own navigation controls (next,
prev., undo, delete, ...) via my own "dirty" routine which is normally
triggered by the Form_Dirty event. However, while the Form_Dirty event
fires
properly when editing existing records is does not fire when editing a NEW
record which has just been added via:
DoCmd.GoToRecord , "" ,acNewRec
I do initialize some controls/textboxes/combos on the form via VBA code
and
some have their default values set in their properties. None of these
seem
to fire the F_D event (and don't expect them to). I'd prefer to use the
forms
dirty event than have to put some code in every control & TB on the form
to
call MY dirty routine (which I already do some of for those set via VBA).
Exactly the same (private) code is used to manage the dirty event on my
main
form and it works fine.
The subform is PopUp & Modal
Help or suggestions appreciated.


If you dirty the form's record via VBA code, the form's Dirty event will not
fire for that record (unless you save the record and then subsequently dirty
it manually). The Dirty event fires when the form's current record is first
dirtied by user action; if your code dirties it, the event won't fire
because that's not user action, and subsequent user action won't be dirtying
a clean record, so it won't fire then, either.

Do you need to be modifying the values of bound controls with your VBA code,
rather than setting their Defaut Value properties? Setting the default
values instead would probably be the simplest solution.

A less good solution would be to save the record after you have initialized
the control values. The drawbacks are, of course, that (a) you may not be
able to save the record yet because it's incomplete, or (b) if you *can*
save the record you may end up with incomplete records saved in your table.

A third, somewhat awkward workaround, if you must actually set the value of
a control in code and want the Dirty event to fire, is to set the focus to a
control and set its Text property, instead of just setting its value
property. Like this:

With Me.txtFoo
.SetFocus
.Text = "bar"
End With

Setting the control's Text property *will* fire the Dirty event, if the form
is not already dirty.
 
B

BBC via AccessMonster.com

Thanks Dirk (you've helped me before)
1) I think the key point you mention
if your code dirties it, the event won't fire
because that's not user action, and subsequent user action won't be dirtying
a clean record, so it won't fire then, either

is the underlying problem (as I do do that).

2) I set items in VBA becasue of specific situations that can have multiple
dependencies on other fields (not too experienced at using "defaults" in
complex situations, guess have to do some reading)

3) Saving the record immediately is problematic for the reasons you mention

4) I did try to set the controls manually and got an error becasue I didn't
think about setting focus first (just moved on to trying other things), Have
re-think that as an option.

What I have done pending another solution was trigger my dirty routine by
putting a call to my routine into each controls individaul dirty event and
that is working OK. I was hoping to use the form_dirty but as per your
comments doesn't look possible.
Appreciate you feedback, not what I was hoping for but at least I now know
the limitations.

Dirk said:
After having read many "Dirty" problems I did not see my particular issue
so
[quoted text clipped - 20 lines]
The subform is PopUp & Modal
Help or suggestions appreciated.

If you dirty the form's record via VBA code, the form's Dirty event will not
fire for that record (unless you save the record and then subsequently dirty
it manually). The Dirty event fires when the form's current record is first
dirtied by user action; if your code dirties it, the event won't fire
because that's not user action, and subsequent user action won't be dirtying
a clean record, so it won't fire then, either.

Do you need to be modifying the values of bound controls with your VBA code,
rather than setting their Defaut Value properties? Setting the default
values instead would probably be the simplest solution.

A less good solution would be to save the record after you have initialized
the control values. The drawbacks are, of course, that (a) you may not be
able to save the record yet because it's incomplete, or (b) if you *can*
save the record you may end up with incomplete records saved in your table.

A third, somewhat awkward workaround, if you must actually set the value of
a control in code and want the Dirty event to fire, is to set the focus to a
control and set its Text property, instead of just setting its value
property. Like this:

With Me.txtFoo
.SetFocus
.Text = "bar"
End With

Setting the control's Text property *will* fire the Dirty event, if the form
is not already dirty.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top