PC Review


Reply
Thread Tools Rate Thread

Cycle through tables in another DB from code

 
 
=?Utf-8?B?Y2hlcm1hbg==?=
Guest
Posts: n/a
 
      25th Apr 2007
I want to reference the table names in one Access DB from another Access DB
via code. Any suggestions on how to do this?

Thanks in advance!
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFyZ2FyZXRCYXJ0bGV5?=
Guest
Posts: n/a
 
      26th Apr 2007
> I want to reference the table names in one Access DB from another Access DB
> via code. Any suggestions on how to do this?


This will list out all the tables in a database:


Option Compare Database
Option Explicit

Sub ListFieldsinRemoteDB()
Dim db As Database
Dim tdefs As TableDefs, tdef As TableDef
Set db = DBEngine.OpenDatabase("C:\BC\BSS\Moore\DOP Data.mdb")
For Each tdef In db.TableDefs
Debug.Print tdef.Name
Next tdef
db.Close
Set db = Nothing
End Sub

You can, of course, use a variable for the name of the remote database.

This will list out all the tables, including the system tables. You can add
some logic to exclude the system tables, if you choose.


 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      26th Apr 2007
cherman wrote:

>I want to reference the table names in one Access DB from another Access DB
>via code. Any suggestions on how to do this?



You can open the other db using OpenDatabase then reference
a table through the TableDefs collection.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      26th Apr 2007
Here's another solution, using a simple query to read the tables in another
database:

SELECT MSysObjects.[Name]
FROM MSysObjects IN 'C:\MyFolder\MyFile.mdb'
WHERE (MSysObjects.[Type] = 1)
AND NOT ((MSysObjects.[Name] Like "~*")
OR (MSysObjects.[Name] Like "MSys*"))
ORDER BY MSysObjects.[Name];

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"cherman" <(E-Mail Removed)> wrote in message
news:F0347D03-AC5B-4AE8-80A7-(E-Mail Removed)...
>I want to reference the table names in one Access DB from another Access DB
> via code. Any suggestions on how to do this?
>
> Thanks in advance!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to print to PDF & cycle until EOF Antney Microsoft Access VBA Modules 3 10th Jul 2008 08:40 AM
Cycle through db tables =?Utf-8?B?U2hhbmU=?= Microsoft Access VBA Modules 2 23rd Mar 2006 06:53 PM
Cycle Through two Tables Dominic Microsoft Access Queries 5 8th Mar 2004 11:48 PM
Getting VBA code to cycle thru all records Lee-Anne Microsoft Access VBA Modules 3 27th Sep 2003 07:16 PM
Re: Getting VBA code to cycle thru all records Tim Ferguson Microsoft Access VBA Modules 2 26th Sep 2003 06:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:19 AM.