Coupling two DataGrid controls

Q: I want to couple two DataGrid controls so that a changed selection in one will show corresponding records in the other one

A: Try the following

Put two Jet data controls (Data1 and Data2) and two DataGrid controls (DBGrid1 and DBGrid2) on a form and set the properties shown below. The Biblio.mdb database is used as an example

If you use RDO or ADO you can use the corresponding data controls, but the properties will be slightly different


Object Property Value
Data1 DatabaseName C:\....\Biblio.mdb
  RecordSource Authors
  Visible False
Data2 DatabaseName C:\....\Biblio.mdb
RecordSource Blank
Visible False
DBGrid1 DataSource Data1
DBGrid2 DataSource Data2

Insert the following code

Private Sub DBGrid1_Click()
  Data2.RecordSource = "SELECT Titles.Title," & _
    " Titles.[Year Published], Titles.ISBN, Titles.Description FROM" & _
    " Titles INNER JOIN [Title Author] ON Titles.ISBN = [Title Author].ISBN" & _
    " WHERE [Title Author].Au_ID = " & Data1.Recordset("au_id")
End Sub

Also take a look at the Hierarchical Flex Grid control, perhaps that control corresponds to your wishes as well.