Retrieve the column names of a table and display them as a list on a form

I would like to create a search engine on my access DB, first thing i wanna to do is to read the column names from a table into a combo box list on a form (so that user can choose which attribute they would like to choose)

How could I achieve that?

Who is Participating?
thorkylConnect With a Mentor Commented:
If you are not linked to a SQL database dont worry about Query1

then open the module basGetInfo
place the curssor in the function tkbMakeModelACCESS

Hit the F5 key

Then look in the table DATA_MODEL
It will have a list of all of your tables with the fields.
   < this is a denormalized view >
then you can export the table and use it to build you select boxes.

jadedataMS Access Systems CreatorCommented:
Hey rickypk!

Put this in the debug window and press return (modify the tablename)

  for x = 0 to dbengine(0)(0).tabledefs("tablename").fields.count-1:debug.print dbengine(0)(0).tabledefs("tablename").fields(x).name: next x

It will list the fields for your table.  Copy them into a text document.

Here is a sample database that will give you the details of all linked tables in a database.

I use this for creating data element dictionaries but is will giv you a list of all fields in all tables.

To use it
Open it and then link all of your tables in your database to it.

Change Query1 's connection properties <sql Server only>

Run tkbMakeModelACCESS for access databases
Run tkbMakeModelSQLSERVER for SQL Server databases
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

rickypkAuthor Commented:
Hi Jack,

Thanks for your advice, but I wanna the column names to be displayed in a list which is contained in a form... instead of creating a text doc.

rickypkAuthor Commented:
Hi thorkyl

I m trying on your DB, but how could I change the connection properties and where should I run those commands (tkbModelAccess..etc). I m new to Access and I dun have a clue....

jadedataMS Access Systems CreatorCommented:
A combobox/listbox can be used to pull a field list from a single table or query.  You could set the rowsourcetype and rowsource to do this.  Short of that you need to "tablize" the field names in your tables to a reference table stored in the front end.  I usually find this is accomplished better by using the loop code provided earlier to read the table at runtime.  It assures that as design changes are made that these changes are encompassed in the list when the user gets there.
rickypkAuthor Commented:
Hey Jack,

So is there any ways that after I create the txt doc, I could turn its value to a list in which the user can choose from a list box?

If so, how? I need to create a interface with a list, so I have to use a list...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.