Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Lier des tables par VBA

4 réponses
Avatar
Maël REBOUX
Bonjour,

Je cherche, dans la base Access en cours, à aller lier des tables qui sont
dans une autre base Access.
En cherchant dans les archives, j'ai trouvé le programme suivant :

Je force les chemins pour l'exemple.
--
Public Sub CreateLinkedAccessTable()

Dim strDBLinkFrom As String
Dim strDBLinkTo As String
Dim strLinkTbl As String
Dim strLinkTblAs As String

Dim Defaut As String

Defaut = "D:\temp\mabd\"

strDBLinkFrom = Defaut & "BDsource.mdb"
strDBLinkTo = Defaut & "BDcible.mdb"
strLinkTbl = "civilite"
strLinkTblAs = "TableLiee"



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
-----

Mais ça ne marche pas : j'ai le message suivant :
"Jet n'a pas pu trouvé l'objet "TableSource"..."

Pourtant, je suis certain de mes variables.

Où est le pb ? N'y a-t'il pas un autre moyen de lier une table par du code ?

Merci d'avance pour les réponses.

4 réponses

Avatar
keops
va voir dans menu outils-< utilitaires des bases de donnees->gestionnaires
de tables liees ou fractionner une base

@+
"Maël REBOUX jaudy-guindy-bizien.org>" <xmael.rebouxx<> a écrit dans le
message de news:
Bonjour,

Je cherche, dans la base Access en cours, à aller lier des tables qui sont
dans une autre base Access.
En cherchant dans les archives, j'ai trouvé le programme suivant :

Je force les chemins pour l'exemple.
--
Public Sub CreateLinkedAccessTable()

Dim strDBLinkFrom As String
Dim strDBLinkTo As String
Dim strLinkTbl As String
Dim strLinkTblAs As String

Dim Defaut As String

Defaut = "D:tempmabd"

strDBLinkFrom = Defaut & "BDsource.mdb"
strDBLinkTo = Defaut & "BDcible.mdb"
strLinkTbl = "civilite"
strLinkTblAs = "TableLiee"



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
-----

Mais ça ne marche pas : j'ai le message suivant :
"Jet n'a pas pu trouvé l'objet "TableSource"..."

Pourtant, je suis certain de mes variables.

Où est le pb ? N'y a-t'il pas un autre moyen de lier une table par du code
?

Merci d'avance pour les réponses.








Avatar
Luis
Bonjour,
Sur ce lien, il y a 'Tables Attachées' c'est sûrement ce
que tu cherches si ta base a été fractionnée.
http://users.skynet.be/accesshome/tables.htm#Links

Luis
-----Message d'origine-----
Bonjour,

Je cherche, dans la base Access en cours, à aller lier
des tables qui sont

dans une autre base Access.
En cherchant dans les archives, j'ai trouvé le programme
suivant :


Je force les chemins pour l'exemple.
--
Public Sub CreateLinkedAccessTable()

Dim strDBLinkFrom As String
Dim strDBLinkTo As String
Dim strLinkTbl As String
Dim strLinkTblAs As String

Dim Defaut As String

Defaut = "D:tempmabd"

strDBLinkFrom = Defaut & "BDsource.mdb"
strDBLinkTo = Defaut & "BDcible.mdb"
strLinkTbl = "civilite"
strLinkTblAs = "TableLiee"



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
-----

Mais ça ne marche pas : j'ai le message suivant :
"Jet n'a pas pu trouvé l'objet "TableSource"..."

Pourtant, je suis certain de mes variables.

Où est le pb ? N'y a-t'il pas un autre moyen de lier une
table par du code ?


Merci d'avance pour les réponses.






.



Avatar
Maël REBOUX
Je viens de tester ces fonctions. Elles marchent bien mais ne
correspondent pas exactement à ce que je souhaite faire.

Certaines des infos dont j'ai besoin sont stockées dans une autre base
que la base courante. J'affiche, par exemple une liste de noms qui est
stockée dans la base distante. En source de la listbox, je met donc une
requête SQL. Mon pb est que une des tables sources de cette requête est dans
cette table distante...

Je souhaiterai donc avoir une procédure VBA qui attache les tables liées
souhaitées au démarrage et une autre qui les détache à la fermeture de la
base.

Comment y parvenir ?
Avatar
Maël REBOUX
J'ai trouvé ce code plus simple ici :
http://support.microsoft.com/default.aspx?scid=kb;fr;468694

Mais j'ai toujours l'erreur 3423 : "Impossible d'utiliser ODBC pour
importer de, exporter vers ou attacher une table de base de données externe
Microsoft Jet à votre base de données."

Faut-il comprendre qu'il y a une limitation du serveur ODBC de mon
Windows 200 Pro ?