|
How to generate Data Dictionary in Access |
|
MS Access is a very helpful tool for the database modelling. Although you can find a lot of wizards to help you with the database architecture, one important feature is missing. It is a Data Dictionary.
Here we would like to help you to produce an automated data dictionary for your MDB Database. We will use a VBA Script that imports the table names, fields and their types and comments into a separated table. Then you can easily export the data from the table into your Excel spreadsheet and send it to a printer. Public Function GenerateDataDictionary(aDataDictionaryTable As String) '*** Usage: GenerateDataDictionary("MyDataDictionaryTable") '*** Extracts the information about the tables for the data dictionary and inserts it to a table '***-- aDataDictionaryTable - Data dictionary table
Dim tdf As TableDef, fldCur As Field, colTdf As TableDefs Dim rstDatadict As Recordset Dim i As Integer, j As Integer, k As Integer Set rstDatadict = CurrentDb.OpenRecordset(aDataDictionaryTable) Set colTdf = CurrentDb.TableDefs 'Go hrough the database and get a tablename For Each tdf In CurrentDb.TableDefs 'Do what you want with the table names here. rstDatadict.AddNew rstDatadict.Update rstDatadict.AddNew rstDatadict![Table] = tdf.NAME rstDatadict![Field] = "----------------------------" rstDatadict![Display] = "----------------------------" rstDatadict![Type] = "" rstDatadict.Update rstDatadict.AddNew rstDatadict![Table] = "Table Description:" For j = 0 To tdf.Properties.Count - 1 If tdf.Properties(j).NAME = "Description" Then rstDatadict![Field] = tdf.Properties(j).Value End If Next j rstDatadict.Update rstDatadict.AddNew rstDatadict.Update
For i = 0 To tdf.Fields.Count - 1 Set fldCur = tdf.Fields(i) rstDatadict.AddNew rstDatadict![Table] = tdf.NAME rstDatadict![Field] = fldCur.NAME rstDatadict![Size] = fldCur.Size Select Case fldCur.Type Case 1 FieldDataType = "Yes/No" Case 4 FieldDataType = "Number" Case 8 FieldDataType = "Date" Case 10 FieldDataType = "String" Case 11 FieldDataType = "OLE Object" Case 12 FieldDataType = "Memo" Case Else ' Other values. FieldDataType = fldCur.Type End Select rstDatadict![Type] = FieldDataType For j = 0 To tdf.Fields(i).Properties.Count - 1 If fldCur.Properties(j).NAME = "Description" Then rstDatadict![DESCRIPTION] = fldCur.Properties(j).Value End If If fldCur.Properties(j).NAME = "Caption" Then rstDatadict![Display] = fldCur.Properties(j).Value End If If fldCur.Properties(j).NAME = "Rowsource" Then rstDatadict![LookupSQL] = fldCur.Properties(j).Value End If Next j rstDatadict.Update Next i Debug.Print " " & tdf.NAME Next tdf End Function |