Referring to a subform in code:Error 2455

W

Warmy

I have a form with no recordsource that has to continious forms on it. We can
call them fsub1 and fsub2. I have code underneath the fsub1.OnCurrent to
update the recordset on fsub2. Here's what I've tried:
Me.Parent.Controls("fsub2").Form.RecordSource = sSQL
Forms!frmInHouseInventory!fsub2.Form.RecordSource = sSQL
Forms("frmInHouseInventory").Controls("fsub2").Form.RecordSource = sSQL

I keep getting error #2455. Invalid reference to a form.

TIA
--Warmy
 
A

Allen Browne

Open the main form in design view.
Right-click the edge of the 2nd subform, and choose Properties.
What is the Name property of this subform?
It may not be the same as the name of the form that gets loaded into it (its
SourceObject.)

If the name is correct, when do you get this error? Is it when the form
first loads? Access has to load one of the subforms before the other, so the
message may indicate that the other subform has not loaded yet when the
first subform's Current event fires first.
 
A

Allen Browne

The loading order is not defined anywhere I am aware of.

In practice, I suspect it's in the order you placed the controls to the
form.

You could try programmatically looping through the Controls collection of
the form to see if it matches that order.

If it is just the initial load that generates the problem, you could use
error handling to ignore the error.
 
A

Allen Browne

If the error occurs only at the start (i.e. when you initially load the
form), and your code does refer to other subforms (which may not yet be
loaded), then yes, this probably the issue.
 

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