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
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
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