ms-accessvbagrandchild

MS Access: Execute code for every instance of a subsubform


I've got an MS Access 2013 form containing a child form within a child form (a grandchild), both in datasheet view.

Now I've got some controls on the main form with which one should be able to filter the records in both the child and the grandchild form.

Filtering the child form works totally fine with

Dim strSQL As String
strSQL = ...
Me!child.Form.RecordSource = strSQL
Me!child.Requery

But if I want to set up filters for the grandchild with

Dim strSQL As String
strSQL = ...
Me!child.Form!grandchild.Form.RecordSource = strSQL
Me!child.Form!grandchild.Requery

I get error 2455. With this question I solved the error by expanding one or more of the subform's rows.

But I now want to set the RecordSource for every grandchild row, while my current code is only working for the very first row, independent of which row I'm expanding/collapsing.

How do I change the RecordSource for every subsubform record in my main form, at best without manually expanding any row before filtering?

EDIT: Gustav provided a no-code solution that helped me. Nonetheless I wonder how to generally change form properties of a grandchild from the master form for all instances.


Solution

  • You don't need to adjust the recordsource.

    Adjust the Master/Child link fields of the grandchild subform control, and the filtering will be automatic.