Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / February 2005

Tip: Looking for answers? Try searching our database.

Changing Linked Tables through VBA code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 16 Feb 2005 21:23 GMT
Hello,

Is there a way ot chane Linked Tables through VBA code
rather than having to go the Linked Table Manager ?

Any help would be greatly appreciated.

Thank you,
Jeff
Sean - 16 Feb 2005 22:44 GMT
Here is a sample from in invoicing database I wrote that does just what you are asking.

I keep each month's invoices in a .MDB data file located in the "p:\invoices\" folder, each containing one month's information.  The front end database has a linked table called "tInvoiceDetail".  Depending on which month the user wishes to work with, I relink that table to the appropriate .MDB using this procedure.

I use Access 2000.  This function is depended on having the "Microsoft ADO Ext. 2.x for DLL and Security" (MSADOX.DLL) reference.

Sub RelinkTable(strFilename As String)
   
   Dim cat As ADOX.Catalog
   Dim tbl As ADOX.Table
   
   Set cat = New ADOX.Catalog
   Set cat.ActiveConnection = CurrentProject.Connection
   If cat.Tables("tInvoice Detail").Properties("JET OLEDB:Link Datasource") <> ("p:\invoices\" & strFilename) Then
       cat.Tables.Delete ("tInvoiceDetail")

       Set tbl = New ADOX.Table
       tbl.Name = "tInvoiceDetail"
       tbl.ParentCatalog = cat
       tbl.Properties("Jet OLEDB:Create Link") = True
       tbl.Properties("Jet OLEDB:Link Datasource") = "p:\invoices\" & strFilename
       tbl.Properties("Jet OLEDB:Remote Table Name") = "tInvoiceDetail"
       cat.Tables.Append tbl
       Set tbl = Nothing
   End If
   Set cat = Nothing

End Sub
Douglas J. Steele - 16 Feb 2005 23:26 GMT
In addition to Sean's suggestion, check
http://www.mvps.org/access/tables/tbl0009.htm at "The Access Web"

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hello,
>
[quoted text clipped - 5 lines]
> Thank you,
> Jeff
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.