Re: Form_Dirty problem




"BBC via AccessMonster.com" <u49322@uwe> wrote in message news:98a395e4fdb27@xxxxxx
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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

.



Relevant Pages

  • Re: Pseudo Dirty Event Procedure
    ... On Dirty event and the necessary action can be taken. ... corresponding to the first data entry. ... point was never encountered after making data entry to any control. ... The *form's* BeforeUpdate and AfterUpdate events will only fire just ...
    (microsoft.public.access.formscoding)
  • Re: Dirty Access Question
    ... should fire when the user makes their first keystroke in a bound control. ... And the Dirty event is not firing for some reason. ...
    (microsoft.public.access.formscoding)
  • Re: Dirty Access Question
    ... should fire when the user makes their first keystroke in a bound control. ... And the Dirty event is not firing for some reason. ...
    (microsoft.public.access.forms)
  • Re: Dirty Access Question
    ... It appears that the on dirty event fires but the ... > should fire when the user makes their first keystroke in a bound control. ... rather than allenbrowne at mvps dot org. ...
    (microsoft.public.access.forms)
  • Re: Dirty Access Question
    ... It appears that the on dirty event fires but the ... > should fire when the user makes their first keystroke in a bound control. ... rather than allenbrowne at mvps dot org. ...
    (microsoft.public.access.formscoding)

Loading