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

5

7

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.

Interclavicle answered 23/4, 2015 at 17:18 Comment(10)
PS, I'm a professional Access developer with 15 years experience, and I've never seen this before. I showed the to a seasoned Access consultant, and he hadn't seen it before either. So, I'm kicking it out to the group.Interclavicle
Hi kismet, I am unable to reproduce this, can you provide a file? I only get this error when I explicitly set the detail to invisible. I build a form with several subforms with 5 levels of depth in total and I don't get an error even if each subform is of height 0.Orth
Hi Marek, thanks for checking it out! I will see if I can get a small demo working that fails so you can test this. I will send you a private message if I can do this.Interclavicle
I don't have 2007 handy, but it does fail in 2013 (but differently). This app is co-developed in 2010 and 2013. Is this bad practice?Interclavicle
Is this describing your problem? #10402001Irony
@MattHall: Thanks for the link. In my reading of that question, it is unclear to me what problem the OP was having, as 2455 can be caused by a number of things. Schlomo's answer did talk about the form needing to be visible in the subform control for the form to be 'active'. But, I just did a careful check, and the subform controls and their forms are all visible, and not changed in code. But, when a child form section containing the subform can't be shown in a parent subform control, Access appears to simply not activate any grandchild forms, regardless of property settings.Interclavicle
FYI: Upgraded to 2010 Service Pack 2 (14.0.7143.5000), and the problem still persists.Interclavicle
@Interclavicle any updates on the case? I'm having this problem right now, office 2016Aldaaldan
@Mafii: I have no more to add, sorry. Please try these things: * Make sure the subform works fine standalone. * Make at least part of the subform's detail section is visible in the subform control. * If that doesn't work, is there a way to redesign this form so that the sub-subforms are not needed? Maybe turn them into popup forms, or move them up as subforms under the main form?Interclavicle
I tried to find a solution for a few hours here, but couldn't find any, so I redisigned the program flow for that I don't need to access the reports subreports from the reports code. Accessing the controls from the subreport's code-behind itself works without any problem, it's weird. Thanks for your time anyways, it's working now :)Aldaaldan
L
8

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

Lea answered 16/7, 2017 at 14:50 Comment(3)
Good observation. It is irritating that a subform is unreachable when it has no records. The fix in your code would be to turn the subform reference into a function that returns an Access Form. I'd type the code in but Stack Overflow comments don't format code properly.Interclavicle
Thanks for the tip! I'll keep that in mind for next time. I found that the error disappears when removing the query reference from the parent forms RecordSource property in form design view and instead using code to set Form.Recordsource. Then the form opens properly, as expected, just without data if the query does not return any results, no errors appear.Lea
Interesting. A reminder: subforms initialize before their parent. It could be that you have a subform query that references a parent control. When the forms initialize, the subform query is invalid, because the parent control is still invalid. Setting the Form.Recordsource in the Form_Open or Form_Load events is a way to avoid the initial (invalid) query in the subform.Interclavicle
L
1

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
Leeann answered 16/2, 2016 at 22:5 Comment(1)
Intriguing. I will need to test this out. The only downside from my perspective is that I really have to to change that Recordsource in Form view.Interclavicle
G
1

The solution I employed was to use the form timer, to ensure that the report and sub reports had all loaded first. I was modifying the filter on sub reports, and getting the 2455 error until I added the timer.

Gauvin answered 4/3, 2021 at 0:8 Comment(1)
Good idea. Sounds like you have a lot of sub forms to requery!Interclavicle
D
1

For my case, the subform should have its .SourceObject = "" until the linked form is ready, then set it as .SourceObject = "linked_form_name", but somehow (because of other errors), I see it already populated with content in design view !

So setting it again as .SourceObject = "" in Design View solved the issue for me.

Dorweiler answered 23/3, 2023 at 13:51 Comment(0)
H
0

I know this question is old but I was able to solve this problem by making sure the form's Detail property was set to True. I have an If statement checking for a condition:

If Me.Detail.Visible = False Then Me.Detail.Visible = True.
Hooknose answered 13/7, 2020 at 19:1 Comment(1)
I will have to try this. Where in the code are you putting this line? (parent event, child event, ...)Interclavicle

© 2022 - 2024 — McMap. All rights reserved.