Of course you are correct. I made a few changes including this new function I found here. The full function appears at the end and uses "Wizhook", something I never heard of till a few minutes ago.
GetColumnNames(strObjectName As String, Optional ShowDetails As Boolean = False) As String
This produces none of the problems that show up when using
Desc = db.TableDefs(i).Properties(14)
Code:
Public Function GetTableINfo2()
Dim db As Database
Dim i As Integer
Dim TblName As String
Dim C_Date As Date
Dim U_Date As Date
Dim Desc As String
Dim myRS As Recordset
Dim SQL As String
Dim Fields As String
Set db = CurrentDb
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete FROM a_tblTables"
DoCmd.SetWarnings True
SQL = "Select * from a_tblTables"
Set myRS = db.OpenRecordset(SQL)
On Error Resume Next
With myRS
db.TableDefs.Refresh
Debug.Print "Name, Created , Updated, Fields"
For i = 0 To db.TableDefs.Count - 1
Desc = ""
If Left(db.TableDefs(i).Name, 4) <> "Msys" Then
TblName = db.TableDefs(i).Properties(0)
C_Date = db.TableDefs(i).Properties(2)
U_Date = db.TableDefs(i).Properties(3)
Fields = GetColumnNames(db.TableDefs(i).Properties(0))
Debug.Print TblName & " , " & C_Date & " , " & U_Date & " , " & Fields
End If
.AddNew
!TblName = TblName
!Created = C_Date
!Updated = U_Date
!Fields = Fields
.Update
Next i
End With
Set db = Nothing
End Function
Code:
Function GetColumnNames(strObjectName As String, Optional ShowDetails As Boolean = False) As String 'Returns the names of all columns in the specified table or query
'If ShowDetails = False, the return value is like so:
' ID;Column1;Column2;
'If ShowDetails = True, the return value is like so:
' ID;4;4;Column1;10;100;Column2;4;4;
' In this case,the columns represent the following data:
' Column name ; DAO datatype constant:
' (dbLong = 4, dbText = 10, etc) ; Max bytes per column
With WizHook
WizHook.Key = 51488399 'This is an internal Wizhook key.
'It only needs to be given once per
'user session, but most Wizhook
'functions won't work without it.
If ShowDetails Then
GetColumnNames = .GetInfoForColumns(strObjectName) 'where strObjectName is the table name passed to the function
Else
GetColumnNames = .GetColumns(strObjectName) 'where strObjectName is the table name passed to the function
End If
End With
'MsgBox GetColumnNames
End Function
I'm happy with the finished product which I can quickly drop into Excel and parse out using Text to Columns.
It's been an interesting discussion.