Help with Pop Up Form

  • Thread starter Thread starter Sandra
  • Start date Start date
S

Sandra

I have a db of donors where I have a tabbed form
consisting of 3 main tables:
Page 1 - Master record of the donor for address, etc.
Page 2 - Subform of Individual records related to master
record
Page 3 - Subform of Donations related to each individual
record

On the Donations form I have a list box for donation
types. If "In-Kind" is selected I have a pop-up form for
a table to contain a detailed description of the donated
items.

The In-Kind form pops up as expected but it does not
acquire the link from the PK in the Donations record, and
upon exit I get the error message:
'You cannot add or change a record because a related
record is required in table "Donations" '.
In relationships I have a one-to-one between Donations
and InKind tables with referential integrity so I presume
the relationship is OK. The list box is selected after
the Donation record has acquired it's unique PK and
several other fields have been filled in.

What am I missing here?

Thanks for any advice,
Sandra
 
Sandra said:
I have a db of donors where I have a tabbed form
consisting of 3 main tables:
Page 1 - Master record of the donor for address, etc.
Page 2 - Subform of Individual records related to master
record
Page 3 - Subform of Donations related to each individual
record

On the Donations form I have a list box for donation
types. If "In-Kind" is selected I have a pop-up form for
a table to contain a detailed description of the donated
items.

The In-Kind form pops up as expected but it does not
acquire the link from the PK in the Donations record, and
upon exit I get the error message:
'You cannot add or change a record because a related
record is required in table "Donations" '.
In relationships I have a one-to-one between Donations
and InKind tables with referential integrity so I presume
the relationship is OK. The list box is selected after
the Donation record has acquired it's unique PK and
several other fields have been filled in.

What am I missing here?

The only way Access *automatically* propagates a foreign key value to a child
record is by using an embedded subform within a parent form. If you are opening
a separate form as a popup then there is no mechanism to automatically link that
record to the parent record you opened the popup from. As far as Access is
concerned you are simply opening a separate form bound to a separate table and
then creating a record. The fact that you opened the popup from another form is
irrelevant as is the fact that the table for the popup has a relationship
defined to the table the calling form is bound to.

You, as the developer must either design the calling form to "push" the foreign
key value to the popup when opening it or design the popup form so it "pulls"
the foreign key value from the calling form.

Example of a "push":

DoCmd.OpenForm "MyPopUp"
Forms!MyPopUp!FKField = Me.ID

For a "pull", you can use code in the popup form's open event to retrieve values
from the calling form or you can set the default value for the foreign key field
so that it comes from the calling form. The latter assumes that the popup is
never used in circumstances where the parent form is not open.
 
Rick Brandt said:
The only way Access *automatically* propagates a foreign key value to a child
record is by using an embedded subform within a parent form. If you are opening
a separate form as a popup then there is no mechanism to automatically link that
record to the parent record you opened the popup from. As far as Access is
concerned you are simply opening a separate form bound to a separate table and
then creating a record. The fact that you opened the popup from another form is
irrelevant as is the fact that the table for the popup has a relationship
defined to the table the calling form is bound to.

You, as the developer must either design the calling form to "push" the foreign
key value to the popup when opening it or design the popup form so it "pulls"
the foreign key value from the calling form.

Example of a "push":

DoCmd.OpenForm "MyPopUp"
Forms!MyPopUp!FKField = Me.ID

For a "pull", you can use code in the popup form's open event to retrieve values
from the calling form or you can set the default value for the foreign key field
so that it comes from the calling form. The latter assumes that the popup is
never used in circumstances where the parent form is not open.

Looking again at the error you were getting I think the actual issue is that you
need to save the record on the calling form before opening the popup. I
recommend...

Me.Dirty = False
DoCmd.OpenForm...
 
Back
Top