Error 2455 (associated with subform reference)

B

BruceM

Error message 2455 (You entered an expression that has an invalid reference
to the property Form/Report) suddenly started appearing when code references
the subform control. However, while the code in question is being run or
called from the form's Current event, the error only occurs when the form is
first opened. All other form navigation, and all code (see below) after
that works as it should. The form is a purchase order form, and the subform
is PO line items. The tables are properly related. I set the subform's
Products combo box (so that the list is only of products that vendor sells)
by using a public sub which is called at various times such as the form's
Current event. The called procedure is:

Dim strRowSource As String

strRowSource = "SELECT ProdDescr, ProductID, ProdCode, ProdUnit, " & _
"UnitPrice, SupplierID " & _
"FROM tblProduct " & _
"WHERE SupplierID = Forms!frmPO!SupplierID " & _
"ORDER BY ProdDescr, ProdUnit"

Forms!frmPO!fsubPO_Items.Form!cboDescription.RowSource = strRowSource

The last line is the one that started giving me problems. In earlier
versions of the database it worked OK. I was attempting to find a way to
lock some of the controls by looping through them. I seem to have
succeeded, but even after unlocking the controls I am still stuck with the
error message. If it makes any difference, I set the locked property by
setting the Tag property of the controls I wanted to lock (If ctl.Tag = "99"
Then etc.). I can provide that code, if it matters, but I doubt it does,
since the same subform reference seems to be causing a problem in the form's
Current event, in other code I am using to lock some controls if certain
conditions are met. I can't be certain the subform reference is the
problem, but I do know that it is something the problem code has in common.

I have checked references, compacted the database, decomplied with a command
line switch, compacted again, and still the problem remains. I also created
a new blank database, and imported all of the objects. I also tried
creating a new subform control, and re-writing the lines of code that are
misbehaving. No luck.

I can click through the error messages and the form works as it should, so I
could probably pass over the error message in the code's error handling, but
I don't really want to let an unresolved mystery be part of the database.
Any ideas?
 
B

BruceM

I realize now that I have started a new day that I was overcomplicating the
row source. Apparently all I need to do is to set the row source in the
Products combo box in the subform, and to set the criteria for VendorID to
the main form control (Forms!frmPO!VendorID). I requery the Products combo
box on the subform from the subform's Current event. However, the problem
with referencing a subform control still happens in the form's Current
event, but only when I open the PO form directly. When I open it from the
vendor form, which passes the VendorID as OpenArgs to the PO form, causing
the PO form to open with just the current vendor's POs, the problem does not
occur.
The good news is that I don't need to reference subform controls in the
form's Current event. The idea is that if the PO approval process has
started (i.e. one of the Approval text boxes on the PO form contains a
value), the PO is locked against further changes. I was attempting to do
that from the main form's Current event (if there is a value in one of the
approval text boxes, the subform is locked, and a subform control is
hidden). The main form's Current event still chokes on:
Forms!frmPO!fsubPO_Items.Form!cmdDelete.Visible = False
However, if I turn it around, so that the subform's Current event examines a
field in the main form's Record Source, and hides the control accordingly,
no problem:
If IsNull(Me.Parent.FinanceApproval) Then
Me.cmdDelete.Visible = True
Else
Me.cmdDelete.Visible = False
End If

It seems I experimented with both methods, and actually had both running at
once in some cases, which could have caused problems, I suppose. Or maybe
the main form's Current event that runs when first opening the PO as
described above (other than from the Vendor form) is too soon to reference a
control on the subform. I can, however, lock the subform control itself
from the main form's Current event:
If IsNull(Me.Parent.FinanceApproval) Then
True
Else
Forms!frmPO!fsubPO_Items.Locked = False
End If

I have it working as is required, but I would like to understand what is
going on. Previous versions of the form did not exhibit this behavior.
There is either an anomaly in Access (an inscrutable feature, perhaps), or I
changed something. In either case I hope to learn what happened, as it
could help in the future.
 

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

Similar Threads


Top