-
Data1 and Data2 Controls both have the same Databasename
there are two tables in the database
one table named categories has
CategoryNames and CategoryID fields
the other table named Products has
ProductNames and CategoryID fields
Data1.RecordSource is set to Categories
Data2.RecordSource is not set
DBCombo1.Rowsource = Data1
DBCombo1.Listfield = CategoryNames
DBList1.Rowsource = Data2
DBList1.Listfield = ProductNames
====================================================
Programatically I want to set the Data2.RecordSource
when I choose an item in the BDcombo to populate the
DBlist
====================================================
Now if the DBCombo1.Listfield = CategoryID the code
is simple as follows:
Private Sub DBCombo1_Change()
Data2.RecordSource = "SELECT DISTINCTROW _
Products.ProductName FROM Products WHERE _
(Products.CategoryID = " & DBCombo1.Text & ");"
Data2.Refresh
End Sub
====================================================
But what is the code since
DBCombo1.Listfield = CategoryNames ?
-
I am not sure that I understand your question. But I will give you an answer so at least your thread pops to the top.
Data2.RecordSource = "SELECT DISTINCTROW _
Products.ProductName FROM Products, categories WHERE _
(Products.CategoryID = categories.CategoryID ) AND _ categories.ProductNames = DBCombo1.Text );"
I JOIN the two tables over CategoryID. You cold also put the CategoryID as a part of the sting in the combobox and exctract it from the DBCombo1.Text.
-
thanks I have it working now