Dirty / Requery run-time error

S

Stephanie

Greetings-
I have code that does what it's suppose to do, in that it immediately
updates a rolling total for me.
My form is Individuals. Individuals has a subform DuesItemLine that itself
has a subform PaymentItemLine. My rolling total is on a subform
(sfrmITABucksSum2a) on form Individuals, and is affected by changes in
PaymentItemLine.

However, when I'm in the form and not updating the rolling total and then
exit the form, I get a run-time error '2450' Access can't find the form
'Individuals' refered to in vba code. I think my code may be referring to
the incorrect "level" of subform, and yet the code performs the update to the
rolling total correctly- but doesn't always have a smooth exit:

Private Sub Form_AfterUpdate() 'this is on PaymentItemLine
Me.Dirty = False
Forms!Individuals!sfrmITABucksSum2a.Form.Requery
End Sub


I'd appreciate any insight.
 
A

amiga1200

I am not certain, but it sounds like the form Individuals in not open, you
might need a statement that checks this or always open the form but change
its state from visible to invisible and back as required.

Regards
 
S

Stephanie

Interesting thought. The subform that has the requery is on the Individuals
form. I don't get the error message until I close Individuals. When I close
Individuals (and the subform), I don't want Individuals open.
 
S

Stephanie

Maybe what I need is a way for a subform to refer to it's "grand parent".
PaymentItemLine is the subform that has changes to it, and it's on form
DuesItemLine. DuesItemLine is on main form Individuals. sfrmITABucksSum2a
is also on Individuals.

Perhaps this code
Private Sub Form_AfterUpdate() 'this is on PaymentItemLine
Me.Dirty = False
Forms!Individuals!sfrmITABucksSum2a.Form.Requery
End Sub

is having trouble getting the link from PaymentItemLine to Individuals?
Also, the update works correctly. So I don't understand why the form can't
shut down cleanly.
 
S

Stephanie

Actually, I just figured it out:

Private Sub Form_AfterUpdate()
Me.Dirty = False

If IsLoaded("Individuals") Then
Forms!Individuals!sfrmITABucksSum2a.Form.Requery
End If

End Sub

This way, I still get the dirty update on sfrmITABucksSum2a, AND Individuals
closes down nicely.
 
Top