In Access 2007 (or 2010), I need to set the properties on a subform, embedded within the first subform, from the main form using VBA. To make it clear which form I'm talking about, I'll call the this form "subSubform" as I do in my code (well, subSubform is actually the name of the sub-subform control).
When the form loads I have a subform control on my first subform that's blank (does not contain a form source object). If needed, I fill out the SourceObject property of this control with the name of a valid form, as well as the LinkMasterFields and LinkChildFields properties. This all appears to work fine because I do get an expandable plus sign that otherwise wouldn't be there.
Next I try to set the RecordSource for the subSubform and I get an error:
2455 You entered an expression that has an invalid reference to the property Form/Report.
Here's the code I'm using:
Me!subform1.Form!subSubform.Form.RecordSource = sSubformSQL
'and I've tried this with the same bad results
Me.subform1.Form.subSubform.Form.RecordSource = sSubformSQL
'and this too
Forms("frmQuery").subform1.Form.subSubform!Form.RecordSource = sSubformSQL
'And I've tried this. It fails too, on the last line with the same error:
Dim frm As Form
Set frm = Forms("frmQuery").subform1.Form
Dim frm2 As Form
Set frm2 = frm.subSubform.Form
I've tried setting a timer and waiting one second to run the above code, just in case it takes some time for the form to load. But this makes no difference.
I've tried running code from the first subform instead of from the main form, but that doesn't help either. Still fails with the same error.
FWIW, both my subform and my subSubform are DataSheet views. I don't think that makes any different on what I'm trying to do here (although I'm well aware of the performance problems involved so don't scream at me).
I recognize that it's probably a very odd request. But I'm creating a dynamic query interface that needs this.
Any ideas how to set form properties on a subSubform?