I finally got a copy of vb last week and was introduced to DAO and ADO just after. Since, I have been trying to link two datacombo boxes. Finally I figured out how. I thought It should be in a thread here somewhere, and since I couldn't find a simple example, I thought I should post here, what I have conjured up. Although I can't figure out how to set the .text property to a current record. Please Suggest changes, and hopefully we can produce a final result worthy of the FAQs.
____________________________________________________________
Dim NWDB, rs1, rs2, SQL As String
Private Sub DataCombo1_Click(Area As Integer)
Call UpdateDataCombo2
End Sub
Private Sub Form_Load()
Dim rs1 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
rs1.Open "Select CompanyName, SupplierID from Suppliers", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", adOpenStatic, adLockOptimistic
With DataCombo1
Set .RowSource = rs1
.ListField = "CompanyName"
.BoundColumn = "SupplierID"
'.Text = "1" 'I dont understand yet how to set
'the text property to match the data.
.Text = DataCombo1.BoundColumn 'So I inserted the
'Field Name, which
'populates
'datacombo2 with
'select *
End With
Call UpdateDataCombo2
End Sub
Sub UpdateDataCombo2()
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
rs2.Open "Select ProductName, SupplierID from Products where SupplierID = " & DataCombo1.BoundText, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", adOpenStatic, adLockOptimistic, adCmdText
With DataCombo2
Set .RowSource = rs2
.ListField = "ProductName"
.Text = DataCombo2.BoundColumn
End With
End Sub
____________________________________________________________
Dim NWDB, rs1, rs2, SQL As String
Private Sub DataCombo1_Click(Area As Integer)
Call UpdateDataCombo2
End Sub
Private Sub Form_Load()
Dim rs1 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
rs1.Open "Select CompanyName, SupplierID from Suppliers", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", adOpenStatic, adLockOptimistic
With DataCombo1
Set .RowSource = rs1
.ListField = "CompanyName"
.BoundColumn = "SupplierID"
'.Text = "1" 'I dont understand yet how to set
'the text property to match the data.
.Text = DataCombo1.BoundColumn 'So I inserted the
'Field Name, which
'populates
'datacombo2 with
'select *
End With
Call UpdateDataCombo2
End Sub
Sub UpdateDataCombo2()
Dim rs2 As ADODB.Recordset
Set rs2 = New ADODB.Recordset
rs2.Open "Select ProductName, SupplierID from Products where SupplierID = " & DataCombo1.BoundText, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", adOpenStatic, adLockOptimistic, adCmdText
With DataCombo2
Set .RowSource = rs2
.ListField = "ProductName"
.Text = DataCombo2.BoundColumn
End With
End Sub