Search code examples
databasems-accessms-access-2007ms-access-2010

Passing Query Parameter to Sub-Form


I've read many other questions which are similar in nature but mine needs something a little bit different and I am struggling.

(This solution is great but I need something extra on top of it: Passing Query Parameter to Sub-Report)

I have 2 tables: Events and Comments. My main form is bound to Events which contains a subform that is based off a query that has a parameter (eID = the event ID). Basically, the subform shows all the comments (like a log) for a specific Event.

I tried to use the masterlink/childlink...and I get this error

You must add field cEvent to your record source if you wish to use this link.

(FYI : Comments.cEvent = Events.eID)

PROBLEM: It seems like it wants me to include the cEvents so the subform can rendor all the comments for all the Events organized by tabs... but I just want the comments for this particular Event and that's it.


Solution

  • Seems like you've got it mixed up.

    Your master query should look like this:

    PARAMETERS [Enter Event] Long; 
    SELECT *
    FROM Events 
    WHERE eId=[Enter Event];
    

    then the child query could be:

    SELECT Comments.cEvent, Comments.CDate, Comments.cComment 
    FROM Comments;
    

    The Master/Child setting will take care of the filtering of the subform.