Did Don's suggestion of manually setting the Form.RecordSour ce after the .SourceObject and then .Requery not work for you?
Problem with programatically changing subform properties
Collapse
X
-
Solved!
It's working now...using the original setup I had (see post #4). In the course of implementing Don's solution, I found the root problem:
If both the subform and the parent form's recordsources are pulling data from their respective tables including "ID" fields that are named the same, the subform will not display data.
NOTE: This only happens when programatically switching the subform control's "Sourceobje ct".
Here are the details....
The 3 tables all have an ID field with the same name "ID" (it's an autonumber field & Primary key on all 3 tables). We'll call them "ParentForm_Tbl ", "FormA_Tbl" , "FormB_Tbl" .
The Parent form's recordsource was set to the table "ParentForm_Tbl ".
The Query for the subform's recordsource pulls data from "FormA_Tbl" (or "B"). I had the "ID" field as the criteria (WHERE statement), but also included in the SELECT statement as a field to retrieve data from. I removed it from the SELECT statement, then all worked fine!
So I did some more testing and put it back into the SELECT statement, but renamed the "ID" field in the Subform table to something different (e.g. "IDformA") than the ID field in the Parentform table. It also worked fine!
I don't know why this is happening. I tried recreating the problem by renaming other fields to have the same name in both the Parentform table and Subform tables, but did not have any problem. Maybe it has something to do with the ID fields all being Primary keys.
So, this issue appears solved. I don't understand the problem, but it's kind of a moot point now, I guess.
Thanks again for all your assistance. I'm sure I would not have found the solution without your help!Comment
Comment