Option Explicit
Type TypeFeild
Name As String
Value As Integer
End Type
Type Champ
AutoNumber As Boolean
DEFAULT As String
Description As String
Name As String
Position As Integer
Size As String
Type As TypeFeild
End Type
Sub Test()
Dim Cn As Object, Tchamps() As Champ 'Liste des champs et leurs valeur!
Set Cn = CreateObject("Adodb.Connection") 'Access
With Cn
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Myrep\MyBDD.accdb;"
Tchamps() = ListeChampTable(Cn, "MyTable")
Range("A1").CopyFromRecordset .Execute("[MyTable]")
.Close
End With
End Sub
Function ListeChampTable(Connexion As Object, table As String) As Champ()
Dim t() As Champ, i As Integer, G As Object, Tp As Collection
Set Tp = ConsType
With Connexion
With .OpenSchema(4, Array(Empty, Empty, table))
While Not .EOF
ReDim Preserve t(i)
t(i).Name = !COLUMN_NAME
t(i).Position = !ORDINAL_POSITION
t(i).Type.Name = Tp("k" & !DATA_TYPE)
t(i).Type.Value = !DATA_TYPE
t(i).Size = IIf("" & !CHARACTER_MAXIMUM_LENGTH = "", "NULL", !CHARACTER_MAXIMUM_LENGTH)
t(i).DEFAULT = IIf("" & !COLUMN_DEFAULT = "", "NULL", !COLUMN_DEFAULT)
t(i).Description = IIf("" & !Description = "", "NULL", !Description)
Debug.Print !COLUMN_FLAGS
t(i).AutoNumber = !COLUMN_FLAGS.Value = 90 And t(i).Type.Value = 3
i = i + 1
.MoveNext
Wend
ListeChampTable = t
End With
End With
End Function
Function ConsType() As Collection
Set ConsType = New Collection
ConsType.Add "adSmallInt", "k" & 2
ConsType.Add "adInteger", "k" & 3
ConsType.Add "adSingle", "k" & 4
ConsType.Add "adDouble", "k" & 5
ConsType.Add "adCurrency", "k" & 6
ConsType.Add "adDate", "k" & 7
ConsType.Add "adIDispatch", "k" & 9
ConsType.Add "adBoolean", "k" & 11
ConsType.Add "adVariant", "k" & 12
ConsType.Add "adDecimal", "k" & 14
ConsType.Add "adUnsignedTinyInt", "k" & 17
ConsType.Add "dBigInt", "k" & 20
ConsType.Add "adGUID", "k" & 72
ConsType.Add "adBinary", "k" & 128
ConsType.Add "adChar", "k" & 129
ConsType.Add "adWChar", "k" & 130
ConsType.Add "adNumeric", "k" & 131
ConsType.Add "adDBTimeStamp", "k" & 135
ConsType.Add "adVarChar", "k" & 200
ConsType.Add "adLongVarChar", "k" & 201
ConsType.Add "adVarWChar", "k" & 202
ConsType.Add "adLongVarWChar", "k" & 203
ConsType.Add "adVarBinary", "k" & 204
ConsType.Add "adLongVarBinary", "k" & 205
End Function