HOWTO: Establish a One-to-Many Relation with a DBComboLast reviewed: December 12, 1997Article ID: Q170552 |
The information in this article applies to:
SUMMARYOften it is desirable to have a DBCombo pick-list to allow users to choose a single data item and have a set of records from a different but related table display. Most often this scenario is based on two tables with a one- to-many relationship. The DBCombo box lists records from the table on the "one" side of the relationship and other controls show the records from the table on the "many" side of the relationship.
MORE INFORMATIONA one-to-many relationship is based on a field that exists in both tables in the relationship. The field in the one side of the relationship is a unique field. The same field in the many side of the relationship can contain duplicate values. Two Data controls should be used to coordinate the two tables. The DBCombo box must present records from the one side table using a field that is easily interpreted by the user. Usually, the field presented to the user is different than the field used in the relationship. That being the case, after a selection is made in the DBCombo box the corresponding relationship field or join field must be retrieved. The relationship field from the current record selected in the DBCombo box can then be used to filter the data from the many side table in the second data control using an SQL "WHERE" clause in the RecordSource property of the data control.
Sample ProgramThis program uses the Biblio database's Titles and Publishers table to illustrate creating a one-to-many relation with a DBCombo box. There is a one-to-many relation between the Publishers and Titles tables in the Biblio database joined on the PubID field. The DBCombo box shows a list of possible Publishers' names and the DBGrid control displays the related records on the many side of the relationship, namely the Titles table:
REFERENCESFor more information about database relationships, search for the keywords "Relational Database Design" in the Microsoft Visual Basic 5.0 Books Online. Keywords : VB4WIN vb5all vb5howto Version : WINDOWS:4.0,5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |