When the parent form is opened in datasheet view, I cannot reference the Form object of a subform control until the first row of the parent form has been expanded.
I would like to know a good workaround to this. I need to be able to requery this kind of subform even if the first row of the parent form datasheet has not yet been expanded.
Steps to reproduce the problem:
Create two tables:
CREATE TABLE Parent (
PK Text PRIMARY KEY
);
CREATE TABLE Sub (
PK Text PRIMARY KEY,
FK Text REFERENCES Parent (PK)
);
Insert some data:
INSERT INTO Parent (PK) VALUES ('A');
INSERT INTO Parent (PK) VALUES ('B');
INSERT INTO Sub (PK,FK) VALUES ('AA','A');
INSERT INTO Sub (PK,FK) VALUES ('BB','B');
Create two forms based on these tables and set the default view to Datasheet
.
Add Sub
form to Parent
form and link on sub.FK=parent.PK
.
Give the subform container control the name child
.
Open the Parent
form.
Expand the first row of the datasheet and then collapse it.
Attempt to requery the subform as follows:
Forms!Parent!child.Form.Requery 'This succeeds.
Close and re-open the Parent
form.
Expand the second row of the datasheet and then collapse it.
Attempt to requery the subform again using the same code.
This time it fails with the following error:
Run-time error '2455':
You entered an expression that has an invalid reference to the property Form/Report.
From this, I have to conclude that in datasheet view, a subform Form object is not reference-able until the first row of the parent form is expanded.
Detail
section not Footer/Header or you won't get an expandableDatasheet
. – ComputerVersteher