Solved

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

Posted on 2003-11-03
7
3,959 Views
Last Modified: 2012-06-21
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?

Thanks
0
Comment
Question by:rickypk
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9671159
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.

regards
Jack
0
 
LVL 2

Expert Comment

by:thorkyl
ID: 9671259
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.

ftp://ftp.inspectra.net/pub/outgoing/Database_Table_Structure.zip

To use it
Open it and then link all of your tables in your database to it.
   < MAKE A BACKUP FIRST >

Change Query1 's connection properties <sql Server only>

Run tkbMakeModelACCESS for access databases
Run tkbMakeModelSQLSERVER for SQL Server databases
0
 

Author Comment

by:rickypk
ID: 9671391
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.

Ricks
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rickypk
ID: 9671421
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 VB.....so I dun have a clue....

Thanks
Ricks
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9671440
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.
0
 

Author Comment

by:rickypk
ID: 9671503
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...

Thanks
Ricks
0
 
LVL 2

Accepted Solution

by:
thorkyl earned 50 total points
ID: 9671617
Ok
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.

0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now