Populating Combo-box with Field Names

cmcritchie

New member
Local time
Today, 22:07
Joined
Sep 24, 2001
Messages
8
Hi, I have a combo box on a form and need to populate the combo box with all of the field names from a linked table, when the form is loaded. I am able to get each field name using the Fields.Name property of the TableDef but then can't add this string to the combo box. I thought I could use the AddItem method, but this is not accepted as a valid method for the combo box on the form.
Any ideas?

Thanks.
 
I've managed to get the field names loaded by adding the names to a string and using it as the row source. However, due to the 2048 character length limit this doesn't work for tables with large amounts of field names. Any ideas how I could get round this?

Thanks in advance.

My code is as follows:

Private Sub Form_Load()

Dim db As Database, td As TableDef
Dim strTemp As String, strList As String
Dim i As Integer

Set db = CurrentDb
Set td = db.TableDefs!Spec

For i = 1 To td.Fields.Count
strTemp = td.Fields(i - 1).Name
strList = strList & strTemp & ";"
Next

Me!Combo0.RowSource = strList

[This message has been edited by cmcritchie (edited 09-24-2001).]
 
Look at the options for RowSource Type in a combobox. You'll see there are three - Table/Query, Value List, and Field List. Select Field List and then in the RowSource, select the table or query that contains the fields you want to list.
 

Users who are viewing this thread

Back
Top Bottom