Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subform reference throws Error 2455: You entered an expression that has an invalid reference to the property Form/Report

Tags:

vba

ms-access

Yesterday, a form/subform that worked well for me for a long time suddenly started throwing Error 2455: You entered an expression that has an invalid reference to the property Form/Report.

Below is my diagnosis of the problem. It feels like a bug.

My question is: Have any of you ever seen this? If you are interested, could you try to duplicate the problem, and let me know what you find?

The Problem:

  • I had a form that worked perfectly standalone, setting recordsources for each of its subforms
  • But the form failed when it was put in a subform control, throwing error 2455 for every subform when trying to set the SubForm.Form.RecordSource property (but again, only when the form itself was a subform)

After lots of experimentation, I narrowed it down to this:

  1. The SubForm control was too short to show the form's Detail section. Only the Header was visible.
  2. Since the form's detail was not visible, Access silently disabled all of the subforms under the form!!!

My Workaround: Always ensure that at least part of the form's Detail section is visible in the SubForm control. Either:

  • Increase the height of the SubForm control
  • Move controls from the form Header to the detail, and make the Header shorter, or invisible, so only the detail shows.

Can you duplicate this? This is weird, so I would like some independent confirmation of this problem. So, please, if you have a little time, try these steps:

  1. Make a form with:
    • A subform control that holds a grandchild form
    • A header section, height 0.5 inches
  2. Add this form as a child in a parent subform control
  3. The working case:
    • Set the parent's subform height to .6 inches, so the child's detail section is visible
    • In code, refer to the child's subform.Form.RecordSource property (the grandchild).
    • Expectation: no error
  4. The failing case:
    • Now, set the parent subform height to .4 inches, so the detail is NOT visible
    • Rerun the code that touches the child's subform.Form.RecordSource property.
    • Expectation: Runtime Error 2455

My 'grandchild' forms have no RecordSource when loaded. The recordsource is set in code after the parent/child forms load.

Please, indicate the version of Access you are running, and what results you get. I'm running Access Version 14.0.7128.5000, which seems pretty up-to-date.

like image 666
kismert Avatar asked Apr 23 '15 17:04

kismert


1 Answers

Even though this is an old thread and the answer for OP was most certainly something else, I share this in hope it will help shed some light for others who have stumbeld on the "Error 2455: You entered an expression that has an invalid reference to the property Form/Report". Which may be pretty confusing and occure quite far from the actual cause of the error.

Happened to me today on Access 2016. While making some changes to a project, one of the forms started suddenly throwing Error 2455 in its Form_Load() event containing a single line of code:

Private Sub Form_Load()
    Set mevtReferenceToSubform = Me.frmASubform.Form
End Sub

As pointed out in stackoverflow.com/questions/5023631/... in the comments to the question:

"Controls bound to the recordsource of the parent form (including subforms with LinkChild/LinkMaster properties) do not load when there are no records."

Apparently the same goes for an unbound subform aswell. The subforms '.Form' property will not be accessible from its parent form if the parent form's RecordSource query does not return any records!

In my case the culprit turned out to be a TempVar declaration which I had replaced with another solution, elswhere in the code. But had failed to notice that the removed TempVar was even used by the now failing parent form's query, which didn't return any results...

like image 200
Kristian L Avatar answered Sep 19 '22 09:09

Kristian L