How to Pass a Primary Key from One Form to Another
Posted on 2007-10-03
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
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?