relating tables - carrying over record ID to new form

G

Guest

I have two tables, one with the key "Building ID". The second table has the
key "Image ID" plus I also added the field Building ID to it in order to
relate the two tables in a one-to-many relationship.

My form for Table 1 has a button which opens the form for the second table.
I have the field "Building ID" on both forms. However, instead of the second
form displaying the Building ID which matches the first table, it shows a
zero. What is the best way to force the Building ID number of the second
table/form to match the Building ID number of the first form?

Thanks!
 
J

John Vinson

My form for Table 1 has a button which opens the form for the second table.
I have the field "Building ID" on both forms. However, instead of the second
form displaying the Building ID which matches the first table, it shows a
zero. What is the best way to force the Building ID number of the second
table/form to match the Building ID number of the first form?

IMO the *best* way is to make the second form a Subform of the first,
using BuildingID as the Master and Child Link Field.

When you *open* a second form, you're opening it from scratch, with no
automatic reference to the calling form. If you really want to use two
separate, independent forms, you'll need to put VBA code in the event
which opens the second form, setting its WhereCondition argument to

"[BuildingID] = " & Me![BuildingID]

and probably also passing BuildingID in the OpenArgs parameter, and
using VBA code in the second form's Open event to set the Default
Value property of the BuildingID to the passed value.

If that sounds complicated, it is; if the subform sounds easy... it is
too!

John W. Vinson[MVP]
 

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