Show Field Names in Combo Box

seany

Registered User.
Local time
Today, 03:10
Joined
Sep 1, 2003
Messages
53
Hi,

How do you display the names of field for a table in a combo box. I know how to do it in mySQL "DESCRIBE employee_data", is there a SQL command in access to do this?

thanks

Sean
 
Set the column heads property for the combo to Yes.
 
Sorry I Meant as shown, so that you can pick the title of a field

ID
Name
Address
 
I don't understand. Maybe this isn't supported in Acces, or maybe I'm just thick!
 
The Fields Collection

Take a lookin in the help system (while in the modules) so you get VBA help. There is a section with the title above. Here is part of it...
The Fields Collection
The Fields collection is one of ADO's intrinsic collections. A collection is an ordered set of items that can be referred to as a unit. For more information about ADO collections, see The ADO Object Model in Chapter 1.

The Fields collection contains a Field object for every field (column) in the Recordset. Like all ADO collections, it has Count and Item properties, as well as Append and Refresh methods. It also has CancelUpdate, Delete, Resync, and Update methods, which are not available to other ADO collections.

Examining the Fields Collection
Consider the Fields collection of the sample Recordset introduced in this chapter. The sample Recordset was derived from the SQL statement

SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID = 7
Thus, you should find that the Recordset Fields collection contains three fields.

'BeginWalkFields
Dim objFields As ADODB.Fields

objRs.Open strSQL, strConnStr, adOpenForwardOnly, adLockReadOnly, adCmdText

Set objFields = objRs.Fields

For intLoop = 0 To (objFields.Count - 1)
Debug.Print objFields.Item(intLoop).Name
Next
'EndWalkFields
This code simply determines the number of Field objects in the Fields collection using the Count property and loops through the collection, returning the value of the Name property for each Field object. You can use many more Field properties to get information about a field. For more information about querying a Field, see The Field Object.
 
The Fields Collection

Take a lookin in the help system (while in the modules) so you get VBA help. There is a section with the title above. Here is part of it...
The Fields Collection
The Fields collection is one of ADO's intrinsic collections. A collection is an ordered set of items that can be referred to as a unit. For more information about ADO collections, see The ADO Object Model in Chapter 1.

The Fields collection contains a Field object for every field (column) in the Recordset. Like all ADO collections, it has Count and Item properties, as well as Append and Refresh methods. It also has CancelUpdate, Delete, Resync, and Update methods, which are not available to other ADO collections.

Examining the Fields Collection
Consider the Fields collection of the sample Recordset introduced in this chapter. The sample Recordset was derived from the SQL statement

SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID = 7
Thus, you should find that the Recordset Fields collection contains three fields.

'BeginWalkFields
Dim objFields As ADODB.Fields

objRs.Open strSQL, strConnStr, adOpenForwardOnly, adLockReadOnly, adCmdText

Set objFields = objRs.Fields

For intLoop = 0 To (objFields.Count - 1)
Debug.Print objFields.Item(intLoop).Name
Next
'EndWalkFields
This code simply determines the number of Field objects in the Fields collection using the Count property and loops through the collection, returning the value of the Name property for each Field object. You can use many more Field properties to get information about a field. For more information about querying a Field, see The Field Object.
 
Thanks, Heres my final code

Private Sub Form_Open(Cancel As Integer)
Dim SQL As String
Dim rs As DAO.Recordset
Dim intLoop As Integer
Dim list As String

SQL = "Select * FROM Tbl_Adoption"

Set rs = CurrentDb.OpenRecordset(SQL)

For intLoop = 0 To (rs.Fields.Count - 1)
list = list & rs.Fields.Item(intLoop).Name & ";"
Next

rs.Close

Me.Field_Name.RowSource = list
End Sub
 

Users who are viewing this thread

Back
Top Bottom