Option Compare Database   'Use database order for string comparisons
Option Explicit
Dim db As Database
'
' To convert your tables:
'   1. Open the immediate Window using the View menu
'   2. Type ?ConvertAllTables() and press Enter
'

Function ConvertAllTables ()
On Error GoTo ConvertAllTables_Err
    Dim i As Integer
    Dim tdSrc As TableDef
    Dim iTmp As Integer
    
    DoCmd Hourglass True

    Set db = CurrentDB()

    For i = 0 To db.Tabledefs.Count - 1
        Set tdSrc = db.Tabledefs(i)
        If (tdSrc.Attributes And DB_SYSTEMOBJECT) = 0 Then
            iTmp = RemoveDDLBit(tdSrc)
        End If
    Next i

ConvertAllTables_Exit:
    db.Close
    DoCmd Hourglass False
    Exit Function
ConvertAllTables_Err:
    MsgBox Error$
    Resume ConvertAllTables_Exit
End Function

Function fBadFieldProp (stPropName) As Integer
    Select Case stPropName
        Case "ColumnWidth", "ColumnOrder", "ColumnHidden"
            fBadFieldProp = True
    End Select

End Function

Function fBadTableProp (stPropName) As Integer
    Select Case stPropName
        Case "RowHeight", "DatasheetFontName", "DatasheetFontHeight", "DatasheetFontWeight", "DatasheetFontItalic", "DatasheetFontUnderline", "TabularCharSet", "TabularFamily", "ShowGrid", "FrozenColumns"
            fBadTableProp = True
    End Select
    
End Function

Function PrintProps (stName As String, fTable As Integer, fField As Integer)
On Error Resume Next
    Dim db As Database
    Dim td As TableDef
    Dim i As Integer, j As Integer

    Set db = CurrentDB()
    Set td = db.Tabledefs(stName)

    If fTable Then
        Debug.Print "Table props:"
        For i = 0 To td.Properties.Count - 1
            Debug.Print "     " & td.Properties(i).Name & "=" & td.Properties(i).Value
        Next i
    End If

    If fField Then
        For j = 0 To td.Fields.Count - 1
            Debug.Print "Field props(" & td.Fields(j).Name & "):"
            For i = 0 To td.Properties.Count - 1
                Debug.Print "     " & td.Fields(j).Properties(i).Name & "=" & td.Fields(j).Properties(i).Value
            Next i
        Next j
    End If

    db.Close

End Function

Function RemoveDDLBit (tdSrc As TableDef)
On Error GoTo RemoveDDLBit_Err
    
    Dim fdSrc As Field
    Dim propSrc As Property
    Dim fInTrans As Integer

    Dim vName As Variant
    Dim vType As Variant
    Dim vValue As Variant

    Dim iProp As Integer
    Dim iFld As Integer
    
    BeginTrans
        fInTrans = True

        ' Table properties
        For iProp = tdSrc.Properties.Count - 1 To 0 Step -1
            Set propSrc = tdSrc.Properties(iProp)

            If fBadTableProp(propSrc.Name) Then
                vName = propSrc.Name
                vType = propSrc.Type
                vValue = propSrc.Value
                
                tdSrc.Properties.Delete propSrc.Name

                Set propSrc = tdSrc.CreateProperty(vName, vType, vValue)
                tdSrc.Properties.Append propSrc
            End If
            
        Next iProp
        

        ' Field properties

        For iFld = 0 To tdSrc.Fields.Count - 1
            
            Set fdSrc = tdSrc.Fields(iFld)
            For iProp = fdSrc.Properties.Count - 1 To 0 Step -1
                Set propSrc = fdSrc.Properties(iProp)
                If fBadFieldProp(propSrc.Name) Then
                    vName = propSrc.Name
                    vType = propSrc.Type
                    vValue = propSrc.Value
                    
                    fdSrc.Properties.Delete propSrc.Name

                    Set propSrc = fdSrc.CreateProperty(vName, vType, vValue)
                    fdSrc.Properties.Append propSrc
                End If
                
            Next iProp
    
        Next iFld
    CommitTrans
    fInTrans = False

RemoveDDLBit_Exit:
    Exit Function
RemoveDDLBit_Err:
    If fInTrans Then
        Rollback
        fInTrans = False
    End If
    MsgBox Error$
    Resume RemoveDDLBit_Exit
End Function

