Results 1 to 2 of 2

Thread: filter data into combo box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 1999
    Posts
    22

    Post

    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

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Hi Eddie. Here is some code I whipped up for you. This uses the CUSTOMERS table in the NORTHWIND mdb:
    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width