Full Version: Popup Subform Linked to Subform
UtterAccess Forums > Microsoft® Access > Access Forms
ddine
I'm having trouble linking these 2 forms.
I have a main form with a subform on it, call it SubForm A.
On the main form there is a button that pops up another subform, call it Subform B.
Subform A's recordsource has a primary key and SubForm B's recordsource has that primary key as a foreign key.
What I need, is for subform B to
1) Only show records that correspond to the record of SubForm A
2) Be able to add new records
Any idea of how to do this?
fkegley
You should be able to modify the code that opens Subform B so that it uses the appropriate control of Subform A as a Filter. As to whether or not new records can be added, that would depend on the record source of Subform B.
oCmd.OpenForm "SubformB",,, "[FieldName] = " & Me.SubformA!SubformAControlName
I think I have the right number of ,s but I don't usually do this from memory, so I may not.
ddine
Thanks Frank for your help.
tried your solution and it does indeed filter SubForm B properly.
However, I still cannot add new records.
SubForm B's recordsource has its own autonumber primary key and uses SubForm A's recordsource as a foreign key.
The problem is that it is not inserting the foreign key when it adds new records.
Would using passing the foreign key into the OpenArgs property of the form and setting the foreign key control to be '= me.openargs' be a good idea?
fkegley
Yes, that would work.
Is far as being able to add new records, or edit existing ones, that might depend on the record source of SubformB, for instance, if you are using aggregate functions in its recordsource, then the recordsource will not be updatable.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.