PDA

Click to See Complete Forum and Search --> : filter data into combo box


Playmaker
Dec 29th, 1999, 03:39 AM
Hi, I need help with something. I have a combo box connected to a table in my SQL database using ADODC. What I want is to display only certain data from that table into the combobox. The data is dependant on which client number is on the form. Is there a way to filter which data choices populate my combo box according the client number specified in a text box on my form?

Thanks.
Eddie

Clunietp
Dec 29th, 1999, 09:21 AM
Hi Eddie. Here is some code I whipped up for you. This uses the CUSTOMERS table in the NORTHWIND mdb:

Private Sub Combo1_DropDown()

'declare objects
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

'clear existing list
Combo1.Clear

'open recordset of data that we want to get, using the current customer id
rs.Open "Select * from Customers where CustomerID = '" & Me.Adodc1.Recordset.Fields(0).Value & "'", Me.Adodc1.Recordset.ActiveConnection

'populate dropdown box
Do Until rs.EOF = True
Combo1.AddItem rs.Fields("CompanyName").Value
rs.MoveNext
Loop

End Sub


Tom