Show Field Names in Combo Box (1 Viewer)

seany

Registered User.
Local time
Today, 19:44
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
 

neileg

AWF VIP
Local time
Today, 19:44
Joined
Dec 4, 2002
Messages
5,975
Set the column heads property for the combo to Yes.
 

seany

Registered User.
Local time
Today, 19:44
Joined
Sep 1, 2003
Messages
53
Sorry I Meant as shown, so that you can pick the title of a field

ID
Name
Address
 

neileg

AWF VIP
Local time
Today, 19:44
Joined
Dec 4, 2002
Messages
5,975
I don't understand. Maybe this isn't supported in Acces, or maybe I'm just thick!
 

colette

Registered User.
Local time
Today, 11:44
Joined
Sep 23, 2005
Messages
22
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.
 

colette

Registered User.
Local time
Today, 11:44
Joined
Sep 23, 2005
Messages
22
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.
 

seany

Registered User.
Local time
Today, 19:44
Joined
Sep 1, 2003
Messages
53
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

Top Bottom