Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2013, 03:29 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linked Tables

I have a table, in what I call my "catalog" database, with a list of access databases that we have at our facility. Is there a way with VBA to loop throught this list and determine if each database has linked tables or passthrough queries and then store these "links" as paths in another table.

We have over 300 databases and they are interlinked. I am currently looking at each database and logging the links in my "catalog" database, but it is taking a long time.

Sims
 
Old August 23rd, 2013, 04:38 PM
gjgriffith's Avatar
Wrox Author
 
Join Date: Jul 2009
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Yes you can!

Hello Sims,

So, you can use the "DataSourceName" and "Connect" properties of the "TableDef" or "QueryDef" object to determine if it is a "Linked" table. Here is an example of some code for working with the TableDef object:

Code:
Public Sub CheckForLinkedTables()
On Error GoTo HandleErrors

    Dim db As DAO.Database
    Dim td As TableDef
    Dim tds As TableDefs
    
    Set db = CurrentDb
    Set tds = db.TableDefs

    ' Loop through each of the tables to check for links
    For Each td In tds

        ' Check the "SourceTableName" property to check if the table is linked
        If Nz(td.SourceTableName, "") <> "" Then
        
            ' Get the connection string for the table in strTemp
            Dim strTemp As String
            strTemp = Nz(td.Connect, "")
            
            ' This is a linked table - do work here

        Else

            ' This is NOT a linked table

        End If
    Next

ExitSub:
On Error Resume Next
    Set td = Nothing
    Set tds = Nothing
    Set db = Nothing
    Exit Sub

HandleErrors:
    MsgBox "An error was captured!" & vbNewLine & vbNewLine & "Message: " & _
            vbNewLine & Err.Description & vbNewLine & vbNewLine & "Number:" & _
            Err.Number, vbExclamation, "Error"
    Resume ExitSub
    
End Sub
So, the above code checks all of the tables in the current database to determine if they are "linked" tables or not (which is what the IF block is for in this code). The "SourceTableName" property of the "TableDef" object will have a value if the table is linked externally, otherwise it will be empty if it is a local table. And the "Connect" property stores the actual connection string to the location of the linked table. Does that all makes sense?

Anyway, I hope this is helpful, but if there is anything else I can do to help out, please just let me know!

Best Regards,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
 
Old August 23rd, 2013, 04:44 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do I do this from another database (I have a catalog database which has the paths to each database). I want to loop through the table and for each record, see if that database has a links or not, then put that information in a table on the catalog database.
 
Old August 23rd, 2013, 04:55 PM
gjgriffith's Avatar
Wrox Author
 
Join Date: Jul 2009
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Why not just open a different database, instead of using CurrentDB?

Hi Sims,

Thank you for the quick reply message to my previous reply. Why not just open a different database using the DAO.Database.Workspace object, instead of just using CurrentDB? Will that work for you?

There is a good MSDN article about how to accomplish this task at:
http://msdn.microsoft.com/en-us/libr.../ff835343.aspx
Does this article make sense?

I would provide a code sample here, but I don't have any samples for this scenario super handy just at the moment and I'm kind of in a hurry. But you should just be able to open up a different database using the Workspace object of the DAO.Database object. Does that all make sense?

And if you have any other questions, please just let me know!

Best,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
 
Old August 23rd, 2013, 04:59 PM
Registered User
 
Join Date: Aug 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can see how that Might work. Thanks
 
Old August 25th, 2013, 12:30 AM
gjgriffith's Avatar
Wrox Author
 
Join Date: Jul 2009
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default

Hi Sims,

Sounds great - if you have any other questions, please let me know!

Best Regards,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Tables edojan Access 1 July 20th, 2006 10:49 AM
Linked Tables ru1 Access 1 September 21st, 2005 07:24 AM
help with two linked tables query footohi Access 2 August 25th, 2005 10:25 AM
Linked Tables ricmar Access VBA 6 July 28th, 2004 05:08 PM
Access Linked Tables StephenDID Access ASP 6 October 6th, 2003 10:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.