cmcritchie
09-24-2001, 02:22 AM
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.
cmcritchie
09-24-2001, 03:12 AM
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).]
Pat Hartman
09-24-2001, 05:11 PM
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.
cmcritchie
09-25-2001, 12:10 AM
Thanks Pat - I obviously need a trip to the opticians!!