Results 1 to 4 of 4

Thread: how do I populate a combo box

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Tylertown Mississippi
    Posts
    4

    Exclamation

    I have a combo box that pulls data from a database table and works fine.
    My table looks like this:

    field1 field2 field3
    37 0.397 0.399 0.402
    37 0.392 0.396 0.408
    37 0.397 0.412 0.403
    37 0.397 0.476 0.403
    38 0.398 0.452 0.403
    38 0.398 0.409 0.403
    38 0.398 0.402 0.404
    38 0.398 0.401 0.404

    The problem is, I only want the combo box to display one instance of "field1". For example, I want 37 to be displayed only once, instead of twice, and 38 once, and so on...

    THANX for any help on this!!!!


  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Sorry I do not have more information, but you might look at using the MSHFlexGrid Control. It allows you to connect to a database table and display the information the way you describe.

    You will need to add the Microsoft Flexgrid Control to your project.


  3. #3
    Guest

    Lightbulb

    Why dont you add a distict word to you selection sql statement.

    select distict colom1 from table...
    where ...

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    I needed to do the same thing in an app I was working on recently and this is how I tackled it, the most important piece of this code is making sure sort the fields so they appear in order...

    Code:
    Dim sSQL as String 
    Dim rst as Recordset
    Dim PrevItem
    
    ' Make sure items are displayed in order
    sSQL = "SELECT field1 FROM Table ORDER BY field1 ASC;"
    
    Set rst = DB.OpenRecordset(sSQL)
    
    If not rst.RecordCount = 0 then 
    
      rst.MoveFirst
    
      While Not rst.EOF
        
        ' Only add to combo box if the current item is different from the previous item
        If Not rst!field1 = PrevItem then 
    
           Combo1.AddItem rst!field1
    
           PrevItem = rst!field1
    
        End if
    
        rst.MoveNext
    
      Wend
    
    End if
    
    rst.Close
    set rst = Nothing
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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