How to Pass a Primary Key from One Form to Another

Posted on 2007-10-03
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
    LVL 21

    Expert Comment

    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

    Or have a constructor to the form that sets these three values
    LVL 1

    Author Comment

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

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    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…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now