Populate field on linked form from main form

G

Guest

I have a number of linked forms using command buttons from a main client
details form. I would like the linked forms to record the client ID from the
main form. I can currently get the linked form to display the client ID, but
I cannot get the linked form to record the client ID into the underlying data
source.

Can anyone help?
 
G

Guest

Hi, Michelle.

I'm not sure what you mean by "linked". Are these subforms on the main
form? If so, then setting the LinkMasterFields and LinkChildFields to the
primary key of main form's recordsource and the foreign key corresponding to
it in the subform's recordsource will do it.

If, on the other hand, they're only linked in the sense that they're related
to a common business process, you will have to copy the value using code. If
you are opening a new form with a command button to add a new record, and
you'd like to copy a value from the prior form, this code in the Command
button OnClick procedure will do it.

DoCmd.OpenForm "YourForm", , , , acFormAdd
Forms!YourForm!ClientID = Me!ClientID
' Close Main Form (Optional)
Me.Close

Hope that helps.
Sprinks
 
G

Guest

Sprinks said:
Hi, Michelle.

I'm not sure what you mean by "linked". Are these subforms on the main
form? If so, then setting the LinkMasterFields and LinkChildFields to the
primary key of main form's recordsource and the foreign key corresponding to
it in the subform's recordsource will do it.

If, on the other hand, they're only linked in the sense that they're related
to a common business process, you will have to copy the value using code. If
you are opening a new form with a command button to add a new record, and
you'd like to copy a value from the prior form, this code in the Command
button OnClick procedure will do it.

DoCmd.OpenForm "YourForm", , , , acFormAdd
Forms!YourForm!ClientID = Me!ClientID
' Close Main Form (Optional)
Me.Close

Hope that helps.
Sprinks

Hi Michelle,

I am trying to do the same. I like to use linked forms at times, sometimes
from subforms. Did you get it to work. Like you, I can display the primary
key value on the linked form, as the foreign key, which is fine for viewing
existing records, but then I want to add a new record on the linked form,
saving the displayed value of the foreign key into the underlying table, but
I keep getting 0 in this field.

How did you go? did you get it working.
 

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