Sub Create_tblTableFields()
Dim db As DAO.Database
Dim tblLoop As DAO.TableDef
Dim fldLoop As DAO.Field
Dim TD1 As DAO.TableDef
Dim QD1 As DAO.QueryDef
Dim TempSet1 As DAO.Recordset
Dim strDatabase As String
Dim ThisDB As Database
'strDatabase = "C:\hartman\LinkDB2.mdb"
strDatabase = Forms!frmPrintDoc!txtDBName
Set ThisDB = CurrentDb()
If strDatabase = "" Then
Set db = CurrentDb()
Else
Set db = DBEngine.Workspaces(0).OpenDatabase(strDatabase)
End If
db.Containers.Refresh
Set QD1 = ThisDB.QueryDefs!QdeltblTableFields
QD1.Execute
Set TD1 = ThisDB.TableDefs!tblTableFields
Set TempSet1 = TD1.OpenRecordset
' Loop through TableDefs collection.
For Each tblLoop In db.TableDefs
' Enumerate Fields collection of each
' TableDef object.
For Each fldLoop In tblLoop.Fields
If Left(tblLoop.Name, 4) = "MSys" Or Left(tblLoop.Name, 1) = "z" Or Left(tblLoop.Name, 1) = "~" Then
Else
TempSet1.AddNew
If Left(tblLoop.Name, 7) = "MOBDEV_" Then
TempSet1!TableName = Mid(tblLoop.Name, 8)
Else
If Left(tblLoop.Name, 4) = "dbo_" Then
TempSet1!TableName = Mid(tblLoop.Name, 5)
Else
TempSet1!TableName = tblLoop.Name
End If
End If
'Debug.Print tblLoop.Name & "-" & fldLoop.Name
TempSet1!FieldName = fldLoop.Name
TempSet1!OrdinalPosition = fldLoop.OrdinalPosition
TempSet1!AllowZeroLength = fldLoop.AllowZeroLength
TempSet1!DefaultValue = fldLoop.DefaultValue
TempSet1!Size = fldLoop.Size
TempSet1!Required = fldLoop.Required
TempSet1!Type = fldLoop.Type
TempSet1!ValidationRule = fldLoop.ValidationRule
TempSet1!Attributes = fldLoop.Attributes
On Error Resume Next ' the following property is only available when it is not null
TempSet1!DESCRIPTION = fldLoop.Properties("Description")
TempSet1!FieldType = GetType(fldLoop.Type)
If fldLoop.Attributes And dbAutoIncrField Then 'performs bitwise operation
TempSet1!AutoNum = True
TempSet1!Required = True
Else
TempSet1!AutoNum = False
End If
TempSet1.Update
End If
Next fldLoop
Next tblLoop
db.Close
End Sub
Private Function GetType(lType As Long) As String
'* Returns description of lType
Select Case lType
Case dbBigInt: GetType = "BigInt" '16
Case dbBinary: GetType = "Binary" '9
Case dbBoolean: GetType = "Boolean" '1
Case dbByte: GetType = "Byte" '2
Case dbChar: GetType = "Char" '18
Case dbCurrency: GetType = "Currency" '5
Case dbDate: GetType = "Date" '8
Case dbDecimal: GetType = "Decimal" '20
Case dbDouble: GetType = "Double" '7
Case dbFloat: GetType = "Float" '21
Case dbGUID: GetType = "GUID" '15
Case dbInteger: GetType = "Integer" '3
Case dbLong: GetType = "Long" '4
Case dbLongBinary: GetType = "LongBinary" '11
Case dbMemo: GetType = "Memo" '12
Case dbNumeric: GetType = "Numeric" '19
Case dbSingle: GetType = "Single" '6
Case dbText: GetType = "Text" '10
Case dbTime: GetType = "Time" '22
Case dbTimeStamp: GetType = "TimeStamp" '23
Case dbVarBinary: GetType = "VarBinary" '17
Case Else: GetType = "Undefined - " & lType
End Select
End Function