Tom,
You want to replace values in data_dictionary? With first field in each table?
Code:
Public Sub DocumentTables()
'Requires function FieldType
Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strSQL_Drop As String
Dim strSQL_Create As String
Dim strSQL_Delete As String
Dim BuildNew As Boolean
'rebuild data_dictionary OR delete records and refill may/22
' BuildNew True OR BuildNew False
10 BuildNew = True 'False
'==
Dim idxLoop As Index
20 On Error Resume Next
30 DoCmd.Close acTable, "data_dictionary" 'it may/may not be open
'===
'SQL to Delete existing copy of this table
40 strSQL_Drop = "DROP TABLE data_dictionary;"
'SQL to Create the data_dictionary table
50 strSQL_Create = "CREATE TABLE data_dictionary" & _
"(EntryID AUTOINCREMENT PRIMARY KEY,table_name varchar(250),table_description varchar(255)," & _
"field_name varchar(250),field_description varchar(255)," & _
"ordinal_position NUMBER, data_type varchar(18)," & _
"length varchar(5), default varchar(30), Reqd bit);"
60 Set db = CurrentDb()
70 If BuildNew Then
80 Debug.Print "-Building new data_dictionary"
90 Debug.Print strSQL_Drop
100 db.Execute strSQL_Drop, dbFailOnError
110 DoEvents
120 Debug.Print strSQL_Create
130 db.Execute strSQL_Create, dbFailOnError
140 DoEvents
150 Else
160 Debug.Print "-Empty and refill data_dictionary" & vbCrLf _
& strSQL_Delete
db.Execute strSQL_Delete, dbFailOnError
170 End If
180 Set Rs = db.OpenRecordset("data_dictionary")
190 With Rs
200 For Each tdf In db.TableDefs
210 If Left(tdf.name, 4) <> "Msys" _
And Left(tdf.name, 5) <> "Data_" _
And Left(tdf.name, 1) <> "~" Then
220 Debug.Print tdf.name & " " & .Fields(0).name
230 For Each fld In tdf.Fields
240 .AddNew
250 !table_name = tdf.name
260 !table_description = tdf.Properties("description")
270 !Field_name = fld.name
280 !field_description = fld.Properties("description")
290 !ordinal_position = fld.OrdinalPosition
300 !data_type = FieldType(fld.Type)
310 !Length = fld.Size
320 !Default = fld.DefaultValue
330 !Reqd = fld.Required
340 .Update
350 Exit For '<<<<<<<<<<<<<<<<<<<<<<<<<'Jump out after first field
360 Next
370 End If
380 Next
390 End With
400 MsgBox "Tables have been documented", vbInformation, "TABLES DOCUMENTED"
410 Rs.Close
420 db.Close
430 Application.RefreshDatabaseWindow
Exit_Error_DocumentTables:
440 Set tdf = Nothing
450 Set Rs = Nothing
460 Set db = Nothing
470 Exit Sub
Error_DocumentTables:
480 Select Case Err.Number
Case 3376, 3211
490 Resume Next 'Ignore error if table not found
500 Case 3270 'Property Not Found
510 Resume Next
520 Case Else
530 MsgBox Err.Number & ": " & Err.Description
540 Resume Exit_Error_DocumentTables
550 End Select
End Sub