Quelques petites astuces pratiques sur MS Access.
CurrentProject.Path
Sub GetTablesList() '-------------------------------------------------------------------------------- ' Retourne la liste des tables de la base MS Access en cours '-------------------------------------------------------------------------------- Dim oTable As Variant For Each oTable In CurrentDb.TableDefs ' Exlut les tabes systèmes If Left(oTable.Name, 4) <> "MSys" Then Debug.Print oTable.Name End If Next End Sub
Petite fonction pour avoir le détail des propriétés de chaque champ de chaque table de la base MS Access
Sub DocTables() Dim oTable As TableDef Dim oProperty As Property Dim oField As Field Dim iCount As Integer Dim oAttribute As Object Open CurrentProject.Path & "\" & Split(CurrentProject.Name, ".")(0) & "_DocTables.txt" For Output As #1 For Each oTable In CurrentDb.TableDefs If Left(oTable.Name, 4) <> "MSys" Then Print #1, String(80, "-") Print #1, oTable.Name Print #1, String(80, "-") ' Liste les propriétés ' For iCount = 0 To oTable.Properties.Count - 1 ' Print #1, "> " & oTable.Properties(iCount).Name & ";" & oTable.Properties(iCount).Value ' Next iCount ' Liste les champs Print #1, String(80, "-") Print #1, "Champs" Print #1, String(80, "-") For iCount = 0 To oTable.Fields.Count - 1 Print #1, oTable.Fields(iCount).Name & ";" & oTable.Fields(iCount).Attributes Print #1, String(80, "-") Print #1, "> Propriétés" Print #1, String(80, "-") For Each oAttribute In oTable.Fields(iCount).Properties On Error Resume Next Print #1, oAttribute.Name & ";" & oAttribute.Value On Error GoTo 0 Next oAttribute Next iCount End If Next oTable Close #1 End Sub
Décrit pour chaque table les champs comme suit:
Utilise la fonction FieldType pour avoir le type du champ en Français (à compléter)
Sub DocTablesAndField() '-------------------------------------------------------------------------------- ' But : Extraction des champs de chaque table non système dans un fichier texte '-------------------------------------------------------------------------------- Dim oTable As TableDef Dim iCount As Integer Dim sOut As String Dim sDescription As String ' Création du fichier de sortie Open CurrentProject.Path & "\" & Split(CurrentProject.Name, ".")(0) & "_DocTables.txt" For Output As #1 ' En-tête du fichier de sortie Print #1, "Table;Champs;Position;Description;Type;Taille" ' Boucle sur toutes les tables For Each oTable In CurrentDb.TableDefs ' Ne traite pas les tables systèmes If Left(oTable.Name, 4) <> "MSys" Then ' Boucle sur les champs For iCount = 0 To oTable.Fields.Count - 1 On Error Resume Next sDescription = oTable.Fields(iCount).Properties("Description").Value On Error GoTo 0 ' Table sOut = oTable.Fields(iCount).Properties("SourceTable").Value ' Champ sOut = sOut & ";" & oTable.Fields(iCount).Properties("SourceField").Value ' Position du champ sOut = sOut & ";" & oTable.Fields(iCount).Properties("OrdinalPosition").Value ' Description sOut = sOut & ";" & sDescription ' Type du champ sOut = sOut & ";" & FieldType(oTable.Fields(iCount).Properties("Type").Value) ' Taille du champ sOut = sOut & ";" & oTable.Fields(iCount).Properties("Size").Value Print #1, sOut Next iCount End If Next oTable ' Fermeture du fichier de sortie Close #1 MsgBox "Fin de traitement", vbInformation End Sub
Public Function FieldType(intType As Integer) As String Select Case intType Case 1 FieldType = "Oui/Non" Case 3 FieldType = "Entier" Case 4 FieldType = "Entier long" Case 8 FieldType = "Date/Heure" Case 10 FieldType = "Texte" Case Else FieldType = "<inconnu>" End Select End Function
Les spécifications d'import/export sont stockées dans la table système MSysIMEXSpecs (cf. cette page) .
La requête suivante permet donc de retrouver leurs noms :
SELECT SpecName FROM MSysIMEXSpecs ORDER BY SpecName ASC
Sub ExtractQueryDefs() '-------------------------------------------------------------------------------- ' Extrait toutes les requêtes de la base '-------------------------------------------------------------------------------- Open CurrentProject.Path & "\" & Split(CurrentProject.Name, ".")(0) & "_QueryDefs.txt" For Output As #1 For Each qdf In CurrentDb.QueryDefs Write #1, String(40, "-") Write #1, qdf.Name Write #1, qdf.SQL Next Close #1 End Sub
Sa ka fèt = Comment va ? (créole)
Merci de passer sur mon petit bout de web
Read, Take, Share... Enjoy
--
Fabio (20090317)