Results 1 to 3 of 3

Thread: Is it possible to add a list of fields from a database to a combo box?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Is it possible to add a list of fields from a database to a combo box?

    Hi guys,


    I have a database (Microsoft access database)

    Is there a way to show all the fields in the table 'leads' in a combo box on form load?

    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Re: Is it possible to add a list of fields from a database to a combo box?

    Please find out link below, Hopefully find what you looking for. Thank you.
    http://www.planet-source-code.com/vb...72933&lngWId=1

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Is it possible to add a list of fields from a database to a combo box?

    Since I don't have your database I will just give you and example using the Northwinds DB. Make sure to set an ADO reference.
    Code:
    Private Sub Form_Load()
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim i As Integer
    
        Set cn = New ADODB.Connection
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;"
        cn.Open
        
        Set rs = New ADODB.Recordset
        With rs
            .ActiveConnection = cn
            .Source = "Select top 1 * from customers"
            .Open
        End With
        
        For i = 0 To rs.Fields.Count - 1
            Combo1.AddItem rs.Fields(i).Name
        Next i
        
        rs.Close
        Set rs = Nothing
        
        cn.Close
        Set cn = Nothing
    End Sub

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