How to Identity Whther a Subform is "Dirty"

  • Thread starter Thread starter Mike Thomas
  • Start date Start date
M

Mike Thomas

In a form with a subform where the name of the suibform is "PartSub" and the
name of the subform control is "fmPartSub", I am trying to learn how to
determine whether any records in the subform have been changed, deleted,
appended, etc in any way.

I call the code below which is in a Procedure in the parent form. It is
called whenever the user tries to leave the current parent record. The
"Me.dirty" refers to the controls in the parent form and works fine.

The "Form_PartSub.Dirty" pertains to the subform. It always returns False,
even though lines have been added.

This is the code:

If Me.Dirty = True Or Form_PartSub.Dirty Then
'' do something
END IF

Do I need to somehow call a procedure in the subform rather than trying to
query it directly from the parent form? If I put a Proc into the subform
called "ReturnState", how would I call it from the parent?

Many thanks
Mike Thomas
 
First, don't reference the form object directly as you are doing:

Form_PartSub.Dirty

The above is just a fluke it is working for you. I don't know where you
picked up that bad habit...but dump it this habit.

You should use:

me.SubFromContorl.Form.Dirty.

Assuming your sub-form control is the same, then you would use:

if me.PartSub.Form.Dirty = True

I repeat DO NOT use the base class object of "form_youform".

Now, lets look at your dirty problem. The problem however is that the dirty
flag is only for a give record. So, if the user into the sub modify some
data, then the form is dirty, but instant the user moves to another record
in the sub-form, then dirty will be FALSE.

Thus, you need to realize that it is NOT the form that gets dirty, but only
the current record is dirty when modified (a big difference).

What you could do is in the sub-forms before update event, go


MyDirty = True

At the sub-forms module level, you define a public var like:

Public MyDirty as boolean


You then in the main form on-current event go:

me.PartSub.Form.MyDitry = false

Now, any time a record is updated in the sub-form, your variable MyDitry in
the sub form will be true.
 
Back
Top