How to Pass a Primary Key from One Form to Another

Hi,

I am working on a contact management database written in VB.NET using VS2005. I'm trying to figure out how to pass a primary key parameter from one form to another. I have three tables I'm working with - Opportunity, Contact and jct_OpportunityContact, where jct_OpportunityContact is a junction (or linking) table to represent a many-to-many relationship between opportunities and contacts.

I have a form that displays data from an opportunity table (parent) with a grid view that displays data from the jct_OpportunityContact table and Contact table. The grid view will be read-only and a contact will be added by clicking a button which opens a separate form to show the available options. When the user makes the selection on the secondary form, it will populate the grid view on the primary form.

The junction table contains three columns
OpportunityID
ContactID
ContactRole

When the user clicks the button to add a contact, I want to pass the primary key of the opportunity record from the primary form (either an existing record that is being updated or a new record). This primary key will populate the OpportunityID in the junction table and the user will then be able to create the relationship by selecting a contact and contact role on the secondary form. When the user makes the selection and closes the form, the grid view on the primary form will be populated with this relationship. This behavior can be seen in the "Account" form in Outlook BCM 2007.

Can someone explain how I can get the primary key from the opportunity form to use in the secondary form?

Many thanks!!
LVL 1
jandrews404Asked:
Who is Participating?
 
surajgupthaCommented:
I assumed that your primary key is a composite primary key containing three values. If your primary key is just one value, only one property will be needed.
0
 
surajgupthaCommented:
Have three properties in the secondary form. Before doing a SecondaryForm.Show() set these three properties. Use them when the form loads.
0
 
surajgupthaCommented:
Or have a constructor to the form that sets these three values
0
 
jandrews404Author Commented:
Im confused regarding the three properties. What would they be?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.