!table_description = tdf.Properties("description")
!field_description = fld.Properties("description")
'Set the field properties.
'AutoNumber
140 With !ContractorID
150 Set .ParentCatalog = cat
160 .Properties("Autoincrement") = True 'AutoNumber.
170 .Properties("Description") = "Automatically " & _
"generated unique identifier for this record."
180 End With
'---------------------------------------------------------------------------------------
' Procedure : testdb
' Author : Jack
' Created : 12/8/2009
' Purpose : Test opening second A2003 database.
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: N/A
'------------------------------------------------------------------------------
'
Sub testdb()
Dim dbsCurrent As DAO.Database
Dim dbsSecond As DAO.Database
Dim tbl As DAO.TableDef
10 On Error GoTo testdb_Error
20 Set dbsCurrent = CurrentDb
30 Set dbsSecond = DBEngine.Workspaces(0).OpenDatabase("c:\users\mellon\downloads\EquipInventoryOrLocation.mdb")
40 Debug.Print dbsCurrent.name
50 Debug.Print dbsSecond.name
60 For Each tbl In dbsSecond.TableDefs
70 Debug.Print " " & tbl.name
80 Next
90 Debug.Print Now()
100 On Error GoTo 0
110 Exit Sub
testdb_Error:
120 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure testdb of Module Module5"
End Sub
Dim DataDB As DAO.Database
Dim CurrDB As DAO.Database
Dim tbl As DAO.TableDef
Dim xx As DAO.Field
Dim rs As DAO.Recordset
Dim i As Long
Dim strSQL As String
Dim strAlterTableQRY As String
Set DataDB = OpenDatabase(strDataMDBFile, False, False, "MS Access; PWD=" & pbDataMDBFilePass & " ")
Set CurrDB = CurrentDb()
For Each tbl In DataDB.TableDefs
Debug.Print tbl.Name
For Each xx In tbl.Fields
For i = 1 To 30
Debug.Print "PropertyID " & i & " - " & xx.Properties(i).Name
Next i
Next
Next
PropertyID 1 - Attributes
PropertyID 2 - CollatingOrder
PropertyID 3 - Type
PropertyID 4 - Name
PropertyID 5 - OrdinalPosition
PropertyID 6 - Size
PropertyID 7 - SourceField
PropertyID 8 - SourceTable
PropertyID 9 - ValidateOnSet
PropertyID 10 - DataUpdatable
PropertyID 11 - ForeignName
PropertyID 12 - DefaultValue
PropertyID 13 - ValidationRule
PropertyID 14 - ValidationText
PropertyID 15 - Required
PropertyID 16 - AllowZeroLength
PropertyID 17 - AppendOnly
PropertyID 18 - Expression
PropertyID 19 - FieldSize
PropertyID 20 - OriginalValue
PropertyID 21 - VisibleValue
PropertyID 22 - ColumnWidth
PropertyID 23 - ColumnOrder
PropertyID 24 - ColumnHidden
PropertyID 25 - DecimalPlaces
PropertyID 26 - DisplayControl
PropertyID 27 - GUID
Sub smig()
Dim datadb As DAO.Database
Set datadb = CurrentDb
On Error Resume Next '<<<need this in case property is NULL
For Each tbl In datadb.TableDefs
Debug.Print "Table :" & tbl.name
For Each xx In tbl.Fields
For i = 1 To 30
Debug.Print vbTab & "Field PropertyID " & i & " - " & xx.Properties(i).name
Next i
Next
Next
End Sub
Sub smig()
Dim datadb As DAO.Database
Set datadb = CurrentDb
On Error Resume Next
For Each tbl In datadb.TableDefs
If Not (tbl.name Like "~*" Or tbl.name Like "MSys*") Then
Debug.Print "Table :" & tbl.name & vbCrLf & IIf(GetTableDescr(tbl.name) & vbNullString = "", "", " -- " & GetTableDescr(tbl.name))
For Each xx In tbl.Fields
Debug.Print vbTab & vbTab & "Field " & xx.name & " - " & xx.Properties("Description").Value
Next xx
End If
Next
End Sub
Public Function GetTableDescr(stTableName As String) As String
On Error Resume Next
GetTableDescr = CurrentDb.TableDefs(stTableName).Properties("Description").Value
End Function
Still stuck
Can't find Descriotion as a field property.
I used this code:
Here are the properties I got (Code stoped at 28):Code:Dim DataDB As DAO.Database Dim CurrDB As DAO.Database Dim tbl As DAO.TableDef Dim xx As DAO.Field Dim rs As DAO.Recordset Dim i As Long Dim strSQL As String Dim strAlterTableQRY As String Set DataDB = OpenDatabase(strDataMDBFile, False, False, "MS Access; PWD=" & pbDataMDBFilePass & " ") Set CurrDB = CurrentDb() For Each tbl In DataDB.TableDefs Debug.Print tbl.Name For Each xx In tbl.Fields For i = 1 To 30 Debug.Print "PropertyID " & i & " - " & xx.Properties(i).Name Next i Next Next
Code:PropertyID 1 - Attributes PropertyID 2 - CollatingOrder PropertyID 3 - Type PropertyID 4 - Name PropertyID 5 - OrdinalPosition PropertyID 6 - Size PropertyID 7 - SourceField PropertyID 8 - SourceTable PropertyID 9 - ValidateOnSet PropertyID 10 - DataUpdatable PropertyID 11 - ForeignName PropertyID 12 - DefaultValue PropertyID 13 - ValidationRule PropertyID 14 - ValidationText PropertyID 15 - Required PropertyID 16 - AllowZeroLength PropertyID 17 - AppendOnly PropertyID 18 - Expression PropertyID 19 - FieldSize PropertyID 20 - OriginalValue PropertyID 21 - VisibleValue PropertyID 22 - ColumnWidth PropertyID 23 - ColumnOrder PropertyID 24 - ColumnHidden PropertyID 25 - DecimalPlaces PropertyID 26 - DisplayControl PropertyID 27 - GUID
'---------------------------------------------------------------------------------------
' Procedure : assignTableDescription
' Author : mellon
' Date : 24/10/2015
' Purpose : Assign a description to a table
'
' If a description already exists, overwrite it
'---------------------------------------------------------------------------------------
'
Function assignTableDescription(tableName As String, TableDesc As String)
Dim db As DAO.Database
Dim MyDesc As String
10 On Error GoTo assignDescription_Error
20 Set db = CurrentDb
30 db.TableDefs(tableName).Properties("description") = TableDesc
assignDescription_Error:
40 'MsgBox "error number is " & Err.number 'for debugging
50 If Err.number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
60 Set prpNew = db.TableDefs(tableName).CreateProperty("Description", dbText, TableDesc)
70 db.TableDefs(tableName).Properties.Append prpNew
80 ElseIf Err.number = 0 Then
Exit Function
Else
90 MsgBox "Error " & Err.number & " in line " & Erl & " (" & Err.Description & ") in procedure assignDescription of Module DataDictionary"
100 End If
End Function
'---------------------------------------------------------------------------------------
' Procedure : smig2
' Author : mellon
' Date : 24/10/2015
' Purpose : sample code to call assignTableDescription to add a description to a table
'
' Calls: assignTableDescription
'---------------------------------------------------------------------------------------
'
Sub smig2()
'note can not add a description if one exists!!!
Dim desc As String, resp
Dim tblName As String
10 On Error GoTo smig2_Error
20 tblName = "animalcapture" 'put a table name here
80 ' desc = "AAAAAA WWWW --S A M P L E - D E S C R I P T I O N-- PPPP WWW" 'description here
desc = "Sample table to mock up different Capture dates for animals to assist a poster"
90 Call assignTableDescription(tblName, desc)
100 Debug.Print tblName & vbCrLf & vbTab & CurrentDb.TableDefs(tblName).Properties("Description")
110 On Error GoTo 0
120 Exit Sub
smig2_Error:
130 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure smig2 of Module DataDictionary"
End Sub
' --- Order the Ordered ones (PositionAfter)
strSQL = "SELECT * FROM [NewVersion_Tables_Columns] " & _
"WHERE [dbVersion] > " & LatestDataMDBVersion(strDataMDBFile) & " " & _
"AND Trim([ColumnName] & '') <> '' " & _
"AND Trim([ColumnPositionAfter] & '') <> '' " & _
"ORDER BY [TableName], [ColumnAddOrder]"
Set rs = CurrDB.OpenRecordset(strSQL)
With rs
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
Set DataDB = OpenDatabase(strDataMDBFile, False, False, "MS Access; PWD=" & pbDataMDBFilePass & " ") ' db need to be set after each column so they can be ordered correctly
strTableName = .Fields("TableName")
strColumnName = .Fields("ColumnName")
' --- Set Position
strPrevPositionAfter & " - " & .Fields("ColumnPositionAfter")
If strPrevTableName = strTableName And strPrevPositionAfter = .Fields("ColumnPositionAfter") Then
x = x + 1
Else
x = 1
End If
For i = 0 To DataDB.TableDefs(strTableName).Fields.Count - 1
If DataDB.TableDefs(strTableName).Fields(i).Name = .Fields("ColumnPositionAfter") Then
DataDB.TableDefs(strTableName).Fields(strColumnName).OrdinalPosition = i + x
Debug.Print DataDB.TableDefs(strTableName).Fields(strColumnName).Name & ", POS:" & DataDB.TableDefs(strTableName).Fields(strColumnName).OrdinalPosition & ", X=" & x
End If
Next i
strPrevTableName = strTableName
strPrevPositionAfter = .Fields("ColumnPositionAfter")
DataDB.Close
Set DataDB = Nothing
.MoveNext
Loop
.Close
Set rs = Nothing
End If
End With
OvedPasswordHintID, POS:[B]4[/B], X=1
OvedPasswordHintAnswer, POS:[B]5[/B], X=2
Test1, POS:[B]6[/B], X=3
Test2, POS:[B]7[/B], X=4