linking subform to mainform field

G

Guest

I have a main form that has a field called LastName. I also have a subform
that also has a field called LastName. I placed that field in the subform to
be able to correlate the subform to the mainform BUT what I want is that each
time I open the form to a specific LastName in the main form that the subform
field called LastName will auto populate with the same value in the mainform
field called LastName. How do I do this? I have done this a long time ago
but can not remember how I did this. I recall I did this completely using
the Build option in properties of the field and did not use VBA ( I am not
versed in VBA and would prefer to not do this in VBA). Can anyone assist?
 
G

Guest

Hi, Pearl.

A subform is linked to a main form by the LinkMasterFields and
LinkChildFields properties of the subform, which are the matching fields in
the main and subform's record sources, respectively. Since a main
form/subform is used to display a one-to-many-relationship (one main form
record with many subform detail records), this field is normally the primary
key of the main form record source and a corresponding foreign key in the
subform. For example:

Customer: ABC Corporation
Address: 1234 Lincoln Hwy.
etc...more main form fields

Orders:
Order # Order Date OrderStatus
--------------------------------------------------
1234 1/1/05 Closed
1356 2/3/05 30 Days Past Due
....more Order records

Notice the linking field (CustomerNumber) need not be *displayed* in either
form, but it must be a field in each of the forms' record sources.

I'm kind of surprised you'd be linking by a last name, which normally would
never be used as a primary key. I also don't understand why you would want
to display the name on the subform also; it doesn't add any new information.

Hope that helps. If you need any further discussion on the last topic,
please provide more detail about the generic purpose of your application and
its tables.

Sprinks
 
J

John Vinson

I have a main form that has a field called LastName. I also have a subform
that also has a field called LastName. I placed that field in the subform to
be able to correlate the subform to the mainform BUT what I want is that each
time I open the form to a specific LastName in the main form that the subform
field called LastName will auto populate with the same value in the mainform
field called LastName. How do I do this? I have done this a long time ago
but can not remember how I did this. I recall I did this completely using
the Build option in properties of the field and did not use VBA ( I am not
versed in VBA and would prefer to not do this in VBA). Can anyone assist?

I see Sprinks has provided you with the answer (thanks!) but let me
just amplify on one point he made.

Names ARE NOT UNIQUE.

If you have eleven different people all named Smith in your database,
and seven named Brown, which person's data do you want to see on the
subform?

Or do you tell the second Smith "I'm sorry, we can't do business with
you, there's already someone named Smith in our database?"

Use a unique PersonID instead; and as Sprinks says, there's probably
no good reason to display the same name on both the form and the
subform.

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