how to refer to parent from subform's control row source

Mr.K

Registered User.
Local time
Yesterday, 22:49
Joined
Jan 18, 2006
Messages
104
I have a main form with a subform. On a subform I created a combobox which I want to populate with ClassIDs that match the main forms Individual. I know the criteria in VBA for the above would look something like this:

"SELECT tblClassesAttended.ClassID FROM tblClassesAttended WHERE blClassesAttended.IndividualID=" & Me.Parent!IndividualID

but when I type such statement in the row source of the control it does not work. What is the correct way of refering to the parent form when typing the SQL in the row source?
BTW. I cannot use the main form's name
 
solution

I found a solution, the row source of the control should have:
SELECT tblClassesAttended.ClassID FROM tblClassesAttended WHERE tblClassesAttended.IndividualID=Parent!IndividualID;
 
Another question: What if I want to use a custom function for the row source? e.g.:
SELECT tblClassesAttended.ClassID FROM tblClassesAttended WHERE tblClassesAttended.IndividualID=ValueFromFunction();

Would the best solution be a VBA that presets row source properties for my controls on LoadForm?
 
Since SQL is separate from VBA, you can't use the Me. object. You need to refer to the control by its fully qualified formal name:

SELECT tblClassesAttended.ClassID FROM tblClassesAttended WHERE blClassesAttended.IndividualID= Forms!mainform!IndividualID;
 

Users who are viewing this thread

Back
Top Bottom