Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to Pass a Primary Key from One Form to Another

Posted on 2007-10-03
Medium Priority
Last Modified: 2010-03-19

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?

Many thanks!!
Question by:jandrews404
  • 3
LVL 21

Expert Comment

ID: 20008774
Have three properties in the secondary form. Before doing a SecondaryForm.Show() set these three properties. Use them when the form loads.
LVL 21

Expert Comment

ID: 20008776
Or have a constructor to the form that sets these three values

Author Comment

ID: 20009130
Im confused regarding the three properties. What would they be?
LVL 21

Accepted Solution

surajguptha earned 1500 total points
ID: 20009228
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.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question