>The combo box with the department number info is an ado bound to the department table.
>
>The listbox with subdept info is an ado bound to the subdepartment table.
>
>I have been trying to link them together, but I can't even get the darn tables to open in design mode. The instuctions I have say that I can open the data view, select my data link, expand that all the way so that I can see all the table names, then right click on the table icon of my choice. I will then supposedly see 'design' and from there I can go on to set up relations between my tables. But there is no selection for design when I right click on my table icon.
Here is a little hand to start you up.
Open a new standard EXE.
Add a reference to "Microsoft ActiveX Data Objects Library".
To the form, add a ComboBox and a ListBox control.
Add this code (change the path to the database):
Option Explicit
Private mcnDB As ADODB.Connection
Private Sub Combo1_Click()
Dim rstTemp As ADODB.Recordset
List1.Clear
Set rstTemp = New ADODB.Recordset
With rstTemp
.Open "SELECT ProductName FROM Products WHERE SupplierID = " & Combo1.ItemData(Combo1.ListIndex) & " ORDER BY ProductName", mcnDB
Do Until .EOF
List1.AddItem !ProductName
.MoveNext
Loop
.Close
End With
Set rstTemp = Nothing
End Sub
Private Sub Form_Load()
Dim rstTemp As ADODB.Recordset
Set mcnDB = New ADODB.Connection
With mcnDB
'Change the path on the following line
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb"
.Open
End With
Set rstTemp = New ADODB.Recordset
With rstTemp
.Open "SELECT SupplierID, CompanyName FROM Suppliers ORDER BY CompanyName", mcnDB
Do Until .EOF
Combo1.AddItem !CompanyName
Combo1.ItemData(Combo1.NewIndex) = !SupplierId
.MoveNext
Loop
.Close
End With
Set rstTemp = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
mcnDB.Close
Set mcnDB = Nothing
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com