creating a Data Dictionary

jashgtp

Registered User.
Local time
Today, 14:56
Joined
Mar 13, 2009
Messages
16
I found this code and would like to use it to create a data dictionary however
I cannot seem to get it to work.
I put it into my code builder but then no table gets created
Little help? Thanks.





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!
= tdf.NAME
rstDatadict![Field] = "----------------------------"
rstDatadict![Display] = "----------------------------"
rstDatadict![Type] = ""
rstDatadict.Update
rstDatadict.AddNew
rstDatadict!
= "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!
= 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
 
slightly modified version here

put it in a module,
if it doesnt run, make sure DAO is selected in your references

first you need to create a table called

Code:
MyTable with fields
table text255
field text255
display text255
type text255
lookupsql memo
description memo
size number

then put your cursor at the start of main, and click run


Code:
Option Compare Database
Option Explicit

Sub main()
GenerateDataDictionary ("MyTable")
End Sub

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
Dim FieldDataType As String
Dim dbs As Database

On Error GoTo fail
Set rstDatadict = CurrentDb.OpenRecordset(aDataDictionaryTable)
Set dbs = CurrentDb
Set colTdf = dbs.TableDefs
'Go hrough the database and get a tablename

For Each tdf In dbs.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

MsgBox ("Table Generated")
exithere:

    Exit Function
    
fail:
    Call MsgBox("Error: " & Err & "  Desc: " & Err.Description)
    Resume exithere
End Function
 
there is an error with the mytable with feilds

It displays red and gives an error compile error : expected expression


thanks

sorry i am very new to this and can't seem to fix it
 
to be honest, if you are new to this, and cannot fix it, then its hard to see what you would be using a data dictionary for (particularly the fornat in which this one is generated)

but

a) the table needs to have the fields correctly designed, as I set out
b) you need to be using DAO, not ADO
 
in a code module, tools, references, make sure DAO appears above ADO
 
wow there are a lot of references...do i need to check the box for the DAO ones and the ADO but just have the DAO ones first?

Thanks

Josh
 

Users who are viewing this thread

Back
Top Bottom