View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Retreiving list of table & field names from Access into Excel using VBA

Try code like the following. Set a reference to DAO 3.6 and run
the following code:

Sub AAA()
Dim DB As DAO.Database
Dim Tbl As DAO.TableDef
Dim Rng As Range
Dim Fld As DAO.Field
Set Rng = Range("A1")
Set DB = DAO.OpenDatabase("H:\Test\Test.mdb")'<<< CHANGE

For Each Tbl In DB.TableDefs
If Tbl.Attributes = 0 Then
Rng.Value = Tbl.Name
Set Rng = Rng(2, 2)
For Each Fld In Tbl.Fields
Rng.Value = Fld.Name
Set Rng = Rng(2, 1)
Next Fld
Set Rng = Rng(1, 0)

End If
Next Tbl
DB.Close
End Sub

"shivboy"
wrote in message
...

I am using VBA in MS Excel to create tables in MS Access and
set
relationships between the tables as I have large amounts of
related
data. Now in order to do that, I need to know how to list the
names of
the tables and fields in the tables in the database. This would
help me
to choose tables and further choose fields in those tables to
set
relationships between them. How do I do that? Please help.

Peace,

Shivboy


--
shivboy
------------------------------------------------------------------------
shivboy's Profile:
http://www.excelforum.com/member.php...o&userid=35137
View this thread:
http://www.excelforum.com/showthread...hreadid=551602