Linking Records

G

Guest

I would like to place a control button in my form. I would like this button
to open another form and then link the new record in this child form to the
current record in the parent form. The child form is created from a
completely different table, however, it would be nice if the child could have
a field (or some sort of label visible to the user) that says "Hey everyone,
my mom's name is Form A, and I'm her kid. We can never be separated."

Any suggestions?

Nicole
 
J

jahoobob via AccessMonster.com

You will need a field that shows the relationship between the parent and the
child. This is best done by entering the children in a subform linked to the
parent in the parent table.

You should have a primary key for each parent in the parent table and a
foreign key for each child in the children table that has the same value for
each child of that parent. When you use a form based on the parent table
with a subform based on the children table they will be linked. You can use
the same form to view all the parents and their respective children as long
as it isn't a data entry form.

If you want to do as you ask, opening a separate form with the children, you
can have the button open the children form by passing the parent's primary
key value. You can do this either through a macro or through code. A macro
is easier for a beginner to understand but code the prefered method.

The code should be something like this:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "subfrmChildren"

stLinkCriteria = "[ChildsParentID]=" & Me![ParentID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

where subfrmChildren is the form you want to open via the button,
[ChildsParentID] is the foreign key of the children table, and [ParentID] is
the primary key of the Parent table.

Hope this helps and isn't too confusing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top