Title | Use Data controls to display master/detail data |
Keywords | master/detail, master, detail, data control |
Categories | Database, Controls |
|
|
When the forms loads, connect a master Data control to the database's master table. Connect the detail Data control to the database but don't connect it to a table yet.
|
|
Private Sub Form_Load()
' Prepare the detail data control's database name.
datDetail.DatabaseName = App.Path & "/info.mdb"
' Prepare the master data control.
datMaster.DatabaseName = App.Path & "/info.mdb"
datMaster.RecordSource = "Master"
datMaster.Refresh
End Sub
|
|
In the master Data control's Reposition event handler, set the detail Data control's SELECT statement to get the detail data.
|
|
' We have selected a new master record. Select
' the corresponding details records.
Private Sub datMaster_Reposition()
Dim select_statement As String
select_statement = _
"SELECT * FROM Detail WHERE StudentId = " & _
datMaster.Recordset.Fields("StudentId")
datDetail.RecordSource = select_statement
datDetail.Refresh
End Sub
|
|
|
|