Microsoft KB Archive/127028

= How to Bind Data Controls Across Multiple Forms in VB 4.0 =

Article ID: 127028

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q127028



SUMMARY
The information in this article shows you how to bind two Data Controls on separate forms and have the bound controls updated to scroll through the same recordset.



MORE INFORMATION
With Microsoft Visual Basic version 4.0, you can now assign or set the RecordSet property of a Data Control to any other recordset -- including an existing Dynaset, Snapshot, or Table object. In addition, you can update the bound fields of the Data Control to reflect changes in the recordset. This allows all bound fields on all open forms to scroll through the same recordset.

Step by Step Example
 In Visual Basic, start a new project (Alt, F, N). Form1 is created by default. Add a data control (Data1) and two text boxes (text1 and text2) to Form1.  Using the following table as a guide, set the following properties of the controls on Form1:   Control     Property        Value --  Data1       DatabaseName    BIBLIO.MDB Data1      RecordSource    Titles Text1      DataSource      Data1 Text1      DataField       Title Text2      DataSource      Data1 Text2      DataField       Year Published   Add the following code to the Load event of Form1. Sub Form1_Load Data1.Refresh ' Data control must be refreshed before showing form2. Form2.Show    ' Load second form that refers to data control on                     ' this form. End Sub  Add a second form to the project (ALT, I, F). Form2 is created by default. Add a data control (Data1) and two text boxes (Text1 and Text2) to Form2.  Using the following table as a guide, set the following properties of the controls on Form2:   Control     Property        Value --  Text1       DataSource      Data1 Text2      DataSource      Data1   Add the following code to the Form_Load event of Form2. Sub Form_Load Text1.DataField = "Subject"  ' Assign the bound field values. Text2.DataField = "Comments" Set Data1.Recordset = Form1.Data1.Recordset ' This is the key. End Sub </li> Press the F5 key to run the program. The two forms should display on the screen. When you click either Data Control to scroll through the recordset, the bound fields on both forms will scroll at the same time.</li></ol>

Additional query words: 4.00 vb4win vb4all

Keywords: KB127028

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.