Subform reference throws Error 2455: You entered a

2019-04-10 09:34发布

问题:

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.

回答1:

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...



回答2:

I think this has to do with the Form's CurrentView property. I had a similar case and simply avoided the case when the Form's CurrentView was 1 ("Form" view). This solution worked for me:

If Me.CurrentView <> 1 Then
  Me.sfrWPCN.Form.RecordSource = strSQL
End If