Table fields

garyd1234

Board Regular
Joined
Apr 17, 2003
Messages
103
Hi,
Does anyone know how I can get a list of the fields in a table to go in a list box. I have been trying this but it doesn't work:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim cnt As Container
Dim doct As Document
Dim tbl As TableDef
Dim fld As Field
Dim fldrs As Field

Dim prop As Property


Set db = OpenDatabase("db1.mdb")

Set rs = db.OpenRecordset("Main")

Set fld = db.TableDefs(0).Fields(0)
Set fldrs = rs.Fields(0)
For Each prop In fld.Properties
Debug.Print prop.Name, prop.Type, prop.Value

Next

End Sub


I get a type mismatch error on the line:

Set fld = db.TableDefs(0).Fields(0)
I don't really understand the structure which I got from a help menu in Access. I am trying to list the names of tables in my database in a combo box. When the user selects one it lists the fields and types in another combo box. How do I do this? It is frustrating.

Thanks for any help.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
field list

If I understand your question correctly you can do so by setting the 'Row Source Type' option in the Listbox Properties to 'Field List', you can then select the table/query def you want to take the fields from in the 'Row Source' option in the next line of the properties box.

Hope this is what you need.
 
Upvote 0

Forum statistics

Threads
1,221,522
Messages
6,160,308
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top