Solved

How to Link a table from external Database?

Posted on 2001-08-15
5
300 Views
Last Modified: 2008-02-01
I am doing a project where I need to create a link to user selected database (external database) from my current database on a particular table. I know how to do it in DAO. But I don't know how to do it using ADO. Quick response will help a lot

thanks in advance
0
Comment
Question by:revathi
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
harsh008_k earned 200 total points
ID: 6391595
Sub CreateLinkedAccessTable(strDBLinkFrom As String, _
         strDBLinkTo As String, _
         strLinkTbl As String, _
         strLinkTblAs As String)

   Dim catDB As ADOX.Catalog
   Dim tblLink As ADOX.Table

   Set catDB = New ADOX.Catalog
   ' Open a Catalog on the database in which to create the link.
   catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strDBLinkFrom

   Set tblLink = New ADOX.Table
   With tblLink
      ' Name the new Table and set its ParentCatalog property to the
      ' open Catalog to allow access to the Properties collection.
      .Name = strLinkTblAs
      Set .ParentCatalog = catDB

      ' Set the properties to create the link.
      .Properties("Jet OLEDB:Create Link") = True
      .Properties("Jet OLEDB:Link Datasource") = strDBLinkTo
      .Properties("Jet OLEDB:Remote Table Name") = strLinkTbl
   End With

   ' Append the table to the Tables collection.
   catDB.Tables.Append tblLink

   Set catDB = Nothing
End Sub

0
 
LVL 1

Expert Comment

by:harsh008_k
ID: 6391599
Creating a Linked External Table
Even though ADO and ADOX distinguish between tables that are linked by using Jet I-ISAM drivers and tables linked from ODBC data sources, the method you use to create any linked external table is the same. To create a linked external table by using ADOX and the Microsoft Jet 4.0 OLE DB Provider, you must use the provider-specific Jet OLEDB:Link Provider String property to specify a Microsoft Jet connection string that tells how to connect to the external table. For I-ISAM tables, the connection string specifies the I-ISAM type and the path to the external data source. For ODBC tables, the connection string specifies the ODBC connection string that is necessary to connect to the data source. You then use the provider-specfic Jet OLEDB:Remote Table Name property to specify the name of the source table, which varies for the type of data you are linking to. For example, for an Excel worksheet, the source table can refer to an entire worksheet, a named range, or an unnamed range, whereas for Microsoft Exchange or Outlook, the source table refers to a folder in the mail storage. Just as when you create a linked Access table, you must also set the Jet OLEDB:Create Link property to True. The following code sample can be used to create a linked table for any I-ISAM or ODBC data source.

Sub CreateLinkedExternalTable(strTargetDB As String, _
         strProviderString As String, _
         strSourceTbl As String, _
         strLinkTblName As String)

   Dim catDB As ADOX.Catalog
   Dim tblLink As ADOX.Table

   Set catDB = New ADOX.Catalog
   ' Open a Catalog on the database in which to create the link.
   catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=" & strTargetDB

   Set tblLink = New ADOX.Table
   With tblLink
      ' Name the new Table and set its ParentCatalog property to the
      ' open Catalog to allow access to the Properties collection.
      .Name = strLinkTblAs
      Set .ParentCatalog = catDB

      ' Set the properties to create the link.
      .Properties("Jet OLEDB:Create Link") = True
      .Properties("Jet OLEDB:Link Provider String") = strProviderString
      .Properties("Jet OLEDB:Remote Table Name") = strLinkTbl
   End With

   ' Append the table to the Tables collection.
   catDB.Tables.Append tblLink

   Set catDB = Nothing
End Sub

0
 

Expert Comment

by:cpearl_s
ID: 6391646
hai,
More tips,
If u are trouble in giving connection string ,as above x-perts said,
just follow this.
Place a adodc control and in the properties set the driver and connect to oracle database. After test connection succeded , just copy that connection string and Use


0
 

Expert Comment

by:cpearl_s
ID: 6391647
hai,
More tips,
If u are trouble in giving connection string ,as above x-perts said,
just follow this.
Place a adodc control and in the properties set the driver and connect to oracle database. After test connection succeded , just copy that connection string and Use


regards
cpearl


0
 

Author Comment

by:revathi
ID: 6403564
Thank you for your timely help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now