Resumen Adjuntar tabla de dBase con ADO   (2 mensajes )

Mensaje enviado por jfo@tragsatec.es

Te mando algo que he encontrado por ahi, supongo que modificando un poco te podra valer


Crear una tabla vinculada

Sub ADOCreateAttachedJetTable()
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
'Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;"
'Set the name and target catalog for the table
tbl.Name = "Authors"
Set tbl.ParentCatalog = cat
'Set the properties to create the link
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Datasource") = "C:\pubs.mdb"
tbl.Properties("Jet OLEDB:Link Provider String") = ";pwd=password"
tbl.Properties("Jet OLEDB:Remote Table Name") = "authors"
'Append the table to the collection
cat.Tables.Append tbl
Set cat = Nothing
End Sub

**********************************************
Crear una tabla vinculada (ODBC)

Sub ADOCreateAttachedODBCTable()
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
'Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\nwind.mdb;"
'Set the name and target catalog for the table
tbl.Name = "Titles"
Set tbl.ParentCatalog = cat
'Set the properties to create the link
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = _
"ODBC;DSN=alyssa1;UID=sa;PWD=;"
tbl.Properties("Jet OLEDB:Remote Table Name") = "titles"
' Append the table to the collection
cat.Tables.Append tbl
Set cat = Nothing
End Sub

Un saludo

Mensaje enviado por "Juan Onorio Palavicini Hernández" <onorio_palavicini@hotmail.com>

Gracias por tu consejo, ya he encontrado la solución buscando en la ayuda en línea de Microsoft, ahi se las envío a todos por si a alguien le hace falta (está bestial):

ACC2000: How to Create and Refresh Linked dBASE Tables with ADOX

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Access 2000

--------------------------------------------------------------------------------
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).



SUMMARY
With ActiveX Data Objects code, you can programmatically link to dBASE tables and also refresh them. This article contains sample Visual Basic for Applications functions that demonstrate how to do this.



MORE INFORMATION

In Windows Explorer, create two new folders in the root directory of Drive C. Name one folder MyDbaseFiles and the other folder MyDbaseFiles2.

Close Windows Explorer, and then start Microsoft Access.

Open the sample database Northwind.mdb.

Click the Customers table, and then click Export on the File menu.

In the Export Table 'Customers' to dialog box, browse to the C:\MyDbaseFiles folder.

Set the Save as type box to dBASE IV (*.dbf).

Make sure the file name is Customers, and then click Save.

Close Northwind.mdb, and then create a new Access database, and name it DB1.mdb.

On the Insert menu, click Module. A new module appears.

On the Tools menu, click References.

Make sure the following two references are selected:

Microsoft ADO Ext. for DDL and Security. (Version 2.1 or higher)
Microsoft ActiveX Data Objects Library. (Version 2.1 or higher)

Type or paste the following code into the new module:

Function LinkdBaseFile(strPath As String, _
  strLinkPro As String, strRemTab As String)

Dim conn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table

' Open the catalog using the current Access database.
cat.ActiveConnection = CurrentProject.Connection

' Create the new table.
tbl.Name = "LinkedBase"
Set tbl.ParentCatalog = cat

' Set the properties to create the link.
tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Datasource") = strPath
tbl.Properties("Jet OLEDB:Link Provider String") = strLinkPro
tbl.Properties("Jet OLEDB:Remote Table Name") = strRemTab

' Append the table to the tables collection of the catalog.
cat.Tables.Append tbl

' Clean up.
Set cat = Nothing

End Function


Function RefreshLinkedDBase(strPath As String)

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table

' Open the catalog.
cat.ActiveConnection = CurrentProject.Connection

'Cycle through all tables.
For Each tbl In cat.Tables
' Check to make sure each table is a linked table.
    If tbl.Type = "LINK" Then
        'Set the path apporpriately
        tbl.Properties("Jet OLEDB:Link Datasource") = strPath
    End If
Next
End Function

Type the following line in the Immediate window, and then press ENTER:


?LinkdBaseFile("c:\MyDbaseFiles\","Dbase IV","Customer")
In the Database window, click Tables, and on the View menu click Refresh.
Note that there is a new linked dBASE table.

In Windows Explorer, browse to the C:\MyDbaseFiles\ folder.

Click the file CUSTOMER.DBF, and on the Edit menu, click Cut.

Browse to the C:\MyDbaseFiles2 folder and paste the file there.

Return to the DB1.mdb database and try opening the dBASE table. Note that you receive an error. The link must be updated.

Return to the Visual Basic for Applications module that you created earlier.

Type the following line in the Immediate window, and then press ENTER:

?RefreshLinkedDBase("C:\MyDbaseFiles2\")
Return to the Database window and try to open the dBASE table. Note that it opens without an error. The link is updated.

Additional query words: directory directories


Saludos.
Juan Onorio Palavicini Hernández
Correo electrónico: onorio_palavicini@hotmail.com
ICQ #: 62653440
http://orbita.starmedia.com/~el_zorro_willis/



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com