|
|
Title | Use ADOData controls to and a DataGrid control to display master/detail data |
Description | |
Keywords | master/detail, master, detail, ADOData control, DataGrid |
Categories | Database, Controls |
|
|
When the form loads, connect the detail ADO Data control (ADODC) to the database but not to a table. Connect the master ADODC to the database and the master table.
|
|
Private Sub Form_Load()
' Prepare the detail data control's database name.
datDetail.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\info.mdb;Persist Security " & _
"Info=False"
' Prepare the master data control.
datMaster.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\info.mdb;Persist Security " & _
"Info=False"
datMaster.RecordSource = "Master"
datMaster.Refresh
Set grdMaster.DataSource = datMaster
End Sub
|
|
When the master ADODC moves, create a SELECT statement to fetch the detail data and refresh the detail ADODC.
|
|
' We have selected a new master record. Select
' the corresponding details records.
Private Sub datMaster_MoveComplete(ByVal adReason As _
ADODB.EventReasonEnum, ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, ByVal pRecordset As _
ADODB.Recordset)
Dim select_statement As String
select_statement = _
"SELECT * FROM Detail WHERE StudentId = " & _
datMaster.Recordset.Fields("StudentId")
datDetail.RecordSource = select_statement
datDetail.Refresh
End Sub
|
|
|
|
|
|