How to Synchronize Data on the Form with a dbCombo

Last reviewed: June 18, 1996
Article ID: Q143421
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SUMMARY

You can use the DBCombo control to link data from two data controls if the DataField property of the DBCombo control uses a field common to the RecordSource of the data controls. The FindFirst method allows you to synchronize the data between the two data controls when the DataField property of the DBCombo control is linked to a primary key.

MORE INFORMATION

The following code example allows you to synchronize data between two data controls when the DBCombo control is bound to a field common to both data controls. The field is a primary key.

Code Example

  1. Start 16-bit or 32-bit Visual Basic or if it is already running, click New Project on the File menu.

  2. Add the listed controls to the Form and set the indicated properties

          Control     Default Name   Property           Value
          -------------------------------------------------------------------
    
           Data        Data1          DatabaseName       Biblio.mdb
                                      RecordSource       Publishers
    
           Data        Data2          DatabaseName       Biblio.mdb
                                      RecordSource       Titles
    
           TextBox     Text1          DataSource         Data1
                                      DataField          PubID
    
           TextBox     Text2          DataSource         Data1
                                      DataField          Name
    
           TextBox     Text3          DataSource         Data1
                                      DataField          Company Name
    
           TextBox     Text4          DataSource         Data2
                                      DataField          Title
    
           DBCombo     DBCombo1       DataSource         Data2
                                      RowSource          Data1
                                      BoundColumn        PubID
                                      DataField          PubID
                                      ListField          PubID
                                      Style              2 - DropDown List
    
    
    

  3. Copy the following code to the Code window of the Form1 form to do the synchronization:

          Private Sub DBCombo1_Change()
    
             Data1.Recordset.FindFirst "PubID=" & DBCombo1.BoundText
          End Sub
    
          Private Sub Form_Load()
             Data1.Refresh
          End Sub
    
    

  4. On the Run menu, click Start or press the F5 key to start the program. Select a number from the ComboBox control and note that all the text boxes change. The ComboBox control and the first text box match showing the synchronization.


KBCategory: kbprg kbhowto
KBSubcategory: PrgCtrlsCus
Additional reference words: 4.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.