Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleUse Data controls to display master/detail data
Keywordsmaster/detail, master, detail, data control
CategoriesDatabase, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated