1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Dim CnX As New ADODB.Connection 'pour la connection à la BD
Dim CheminNomDelabase As String 'ou se trouve la BD
Dim NomDeLaBD As String
Dim Schema As New ADODB.Recordset
Dim NomTable As String
Dim strCnn As String 'infos pour la connection à la BD
Dim MsG As String
NomDeLaBD = "Bd2007.accdb"
CheminNomDelabase = "C:\PersoFrancis\BD Access 20007\" & NomDeLaBD
strCnn = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
strCnn = strCnn & "Data Source=" & CheminNomDelabase & ";"
If CnX.State <> adStateClosed Then CnX.Close
Set CnX = Nothing
CnX.CursorLocation = adUseClient: CnX.Mode = adModeReadWrite
On Error Resume Next
CnX.Open strCnn
If Err.Number <> 0 Then
MsG = "Erreur N°" & Err.Number & vbCrLf _
& "Description:" & vbCrLf & Err.Description & vbCrLf _
& "Impossible d'ouvrire la BD " & CheminNomDelabase
MsgBox MsG, vbCritical, "Informations"
Exit Sub
Else
MsG = "Ouverture de la BDs Ok" & vbNewLine
End If
'recuperation de chaque nom des tables de la BDs
Set Schema = CnX.OpenSchema(adSchemaColumns)
While Not Schema.EOF
DoEvents
If Schema!TABLE_NAME <> "" And NomTable <> Schema!TABLE_NAME And InStr(1, Schema!TABLE_NAME, "MSys") = 0 Then
NomTable = Schema!TABLE_NAME
MsG = MsG & vbNewLine & NomTable
End If
Schema.MoveNext
Wend
Schema.Close
MsgBox MsG, vbInformation, "Informations"
CnX.Close |
Partager