Sub test()
Dim Connexion As Object: Set Connexion = CreateObject("Adodb.connection")
With Connexion
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & ";Extended Properties=""Excel 12.0;HDR=YES;""" 'à la place de ThisWorkbook.FullName tu écris le chemin du fichier.xlsx dan Access!
t = ListeChampTable(Connexion, "Feuil1$")
Debug.Print ChampExist(Connexion, "Feuil1$", "A")
.Close
End With
End Sub
Function ListeChampTable(Connexion As Object, table As String)
Dim t() As String, i As Integer
With Connexion
With .OpenSchema(4, Array(Empty, Empty, table))
While Not .EOF
ReDim Preserve t(i)
t(i) = !COLUMN_NAME
i = i + 1
.MoveNext
Wend
ListeChampTable = t
End With
End With
End Function
Public Function ChampExist(Connexion As Object, table As String, Champ As String) As Boolean
With Connexion
With .OpenSchema(4, Array(Empty, Empty, table))
If Not .EOF Then
.Filter = "COLUMN_NAME ='" & Champ & "'"
ChampExist = Not .EOF
End If
End With
End With
End Function
Public ADOConnection As ADODB.Connection
Public ListeChamps() As String 'Représente le tableau des nom de champs
'..................................................................................................................................
Sub test()
If connexion Then
ListeChamps = ListeChampTable(ADOConnection, "TClient")
ComboBox.List = ListeChampTable(ADOConnection, "TClient")
End If
End Sub
'..................................................................................................................................
'@@@@@@@@@@@@@@@
Public Function connexion() As Boolean
'@@@@@@@@@@@@@@@
'ouverture de la base Clients.accdb
strfolder = ThisWorkbook.Path & "\"
Chemin = strfolder & "clients.accdb"
Set ADOConnection = New ADODB.Connection
ConnectString = "Provider=Microsoft.ace.oledb.12.0;Data source=" & Chemin & ";persist security info = false"
ADOConnection.Open ConnectString
Set adorecordset = New ADODB.Recordset
End Function
'***********************************************************
'Permet de récupérer les noms de tous les champs d'une table!
Function ListeChampTable(connexion As Object, table As String)
Dim t() As String, i As Integer
With connexion
With .OpenSchema(4, Array(Empty, Empty, table)) 'ouvre le RcordSet des champs de la table!
While Not .EOF
ReDim Preserve t(i)
t(i) = !COLUMN_NAME
i = i + 1
.MoveNext
Wend
ListeChampTable = t
End With
End With
End Function
'*************************************************************