Microsoft Access runtime error 2455 when trying to access grandchildren forms from child form

后端 未结 2 1530
故里飘歌
故里飘歌 2021-01-19 21:38

I have three forms in an Access 2003 database (developing in Access 2007) that sit in a parent -> child -> grandchild relationship. In the \'Form_Load\' sub of the child fo

相关标签:
2条回答
  • 2021-01-19 22:05

    I will use Parent, Child, and GrandChild for referring to the respective forms (not the data sources).

    Generally the Form property of a subform control gets a "valid reference" only after the subform is shown. Thus, if you want to execute the code in Child.Form_Load, you have to make sure that GrandChild is visible when Parent opens.

    Solution

    Since I assume that in your case GrandChild is visible if you open Child (without opening Parent) but GrandChild is not visible when you open Parent, I would suggest the following solution without changing your UI:

    Move the code of Child.Form_Load, which accesses GrandChild.Form, into GrandChild.Form_Load. Whenever GrandChild loads it can access everything from Child (Me.Parent.Form) or even Parent (Me.Parent.Parent.Form).

    In other words GrandChild has to pull the information (from Child or Parent) and change itself instead of Child pushing the information down to GrandChild by changing GrandChild.

    Example:

    Let's say Parent has an 1:n relationship to Child and Child has an 1:n relationship to GrandChild. Parent presents Child as a datasheet thus GrandChild is not not shown when Parent opens. In this case any access to GrandChild.Form results in a 2455 runtime error since GrandChild is not shown.

    In this example each line of the Child datasheet would have a plus-symbol which allows to show GrandChild. Let's say you put a button on Parent which executes the code you currently have in your Child.Form_Load sub. Clicking on this button after Parent opens results in an error (see above), but if you click on one of the plus-symbols in Child and then click on the button the code would execute without the 2455 error since in this case GrandChild was made visible before the GrandChild.Form access was executed.

    0 讨论(0)
  • 2021-01-19 22:17

    Just above the line giving the problem type: On Error Resume Next

    Run it and that will solve your problem. After one run you can erase the line and will keep working.

    0 讨论(0)
提交回复
热议问题