Retrieve table names and field names

J

John J.

In a mailing form I would like the user to be able to select one of
database's tables and after that he should be able to select one or more
fields of that table. In VBA how can I retrieve all database 's tablenames
and how can I retrieve the fieldnames of one the tables.

Thank you,
John
 
D

Douglas J. Steele

Using combo boxes would be your best bet. Let's assume you name them
cboTableList and cboFieldList.

To load cboTableList with the names of the tables, set its RowSourceType to
Table/Query, and the RowSource to:

SELECT Name FROM MSysObjects WHERE Type IN (1, 4, 6) And Name NOT LIKE
'MSys*' ORDER BY NAME

For the AfterUpdate event, put code like:

Private Sub cboTableList_AfterUpdate()

Me.cboFieldList.RowSourceType = "Field List"
Me.cboFieldList.RowSource = Me.cboTableList

End Sub
 
J

John J.

Thanks! Works great.

John

Douglas J. Steele said:
Using combo boxes would be your best bet. Let's assume you name them
cboTableList and cboFieldList.

To load cboTableList with the names of the tables, set its RowSourceType
to Table/Query, and the RowSource to:

SELECT Name FROM MSysObjects WHERE Type IN (1, 4, 6) And Name NOT LIKE
'MSys*' ORDER BY NAME

For the AfterUpdate event, put code like:

Private Sub cboTableList_AfterUpdate()

Me.cboFieldList.RowSourceType = "Field List"
Me.cboFieldList.RowSource = Me.cboTableList

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top