Results 1 to 9 of 9
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Query Table Properties


    I would like to query the basic table properties of all the tables in my database,
    Table Name Date Created Date Modified Description

    I need to do some side by side comparisons between to versions of my application and this would help me zone in on which tables need to be modified. I know this in buried in some of the hidden tables, but I haven't worked with those before. Can I borrow someones query? It would be much appreciated.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Google: Access VBA table properties TableDefs

    Review: http://msdn.microsoft.com/en-us/library/ff195790.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The following code will work in A2000, don't have A2010 to test it:

    Code:
    Public Sub GetTableINfo()
       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
    
       Set db = CurrentDb
    
       On Error Resume Next
    
       db.TableDefs.Refresh
       Debug.Print "Name, Created , Updated"
       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)
             Desc = db.TableDefs(i).Properties(14)
             
             Debug.Print TblName & " / " & C_Date & " / " & U_Date & " / " & Desc
    
          End If
       Next i
       Set db = Nothing
       MsgBox "done"
    End Sub

  4. #4
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    This code gives me a lot of useful information including all the field names. These are falling under description. As is this gets me what I need, but I would also like to get the text description that is found in the table properties form. For future reference, could you point me at a list of table properties and their associated numbers?

    Sorry, one more item. I am pasting this data into Excel to parse out. The last column with the field names is also full of question marks and an unprintable character, a tiny box with a "?" in it. I am trying to do a find and replace to get rid of them, but I'm not having any luck. Any suggestions?
    Last edited by Paul H; 03-20-2012 at 08:00 AM. Reason: Content

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Are you referring to the text description for each field of table? Review http://allenbrowne.com/func-06.html

    This code will list the 21 table properties by index and name:
    Code:
    Sub ListTableProps()
    Dim db As DAO.Database
    Dim tdf As TableDef
    Dim i As Integer
    Set db = CurrentDb
    Set tdf = db.TableDefs("tablename")
    For i = 0 To 20
        Debug.Print i & " : " & tdf.Properties(i).Name
    Next
    End Sub
    Google: access excel export has box with question mark
    Review http://www.mrexcel.com/forum/showthread.php?t=321197
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    I actually found this elsewhere, combining the clean(trim(cell ref)) did most of the work. I still was left with a lot of question marks and some inconsistent parsing. Seems like this should be simpler. I also tried loading the output into an Access table, but for some reason the text fields would not populate.

    I adapted Ssanfu's code like this.

    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
       Set db 
    CurrentDb
       
       
        SQL 
    "Select * from a_tblTables"
       
    Set myRS CurrentDb.OpenRecordset(SQL)
       
    On Error Resume Next
       
       With myRS
           db
    .TableDefs.Refresh
           Debug
    .Print "Name, Created , Updated, Desc"
           
           
    For 0 To db.TableDefs.Count 1
              Desc 
    ""
              
    If Left(db.TableDefs(i).Name4) <> "Msys" Then
                 TblName 
    Len(db.TableDefs(i).Properties(0))
                 
    C_Date db.TableDefs(i).Properties(2)
                 
    U_Date db.TableDefs(i).Properties(3)
                 
    Desc Trim(db.TableDefs(i).Properties(14))
                 
                 
    Debug.Print TblName " , " C_Date " , " U_Date " , " Desc
              End 
    If
              .
    AddNew
                
    !Table TblName
                
    !Created C_Date
                
    !Updated U_Date
                
    !Description = !Desc
              
    .Update
        
           Next i
               
        End With 
    Here's the result from my table.

    tblName Created Updated Fields

    3/20/2012 12:46:32 PM 3/20/2012 12:57:55 PM

    9/29/2011 8:58:09 AM 9/29/2011 8:58:16 AM

    9/29/2011 8:58:09 AM 9/29/2011 8:58:16 AM
    9/29/2011 8:58:09 AM 9/29/2011 8:58:16 AM
    9/29/2011 8:58:09 AM 9/29/2011 8:58:16 AM


    This has moved past the practical stage, at least for the moment. If I could get this to work simply it would be something I would use, but as it stands, I can't spend much more time figuring this out. It will nag at me though, so if you have any other suggestions I'll look them over.

    I appreciate both your and Ssanfu's help with this.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
              .AddNew
                !Table = TblName
                !Created = C_Date
                !Updated = U_Date
                !Description = !Desc
              .Update
    Why do you have the bang (!) in front of the variable Desc?? It shouldn't be there....

  8. #8
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Thumbs up Wizhook

    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.

  9. #9
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Glad you were able to get the data you wanted....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-15-2012, 04:04 PM
  2. Form Properties
    By Desstro in forum Access
    Replies: 3
    Last Post: 04-10-2011, 05:54 PM
  3. Nz() for properties instead of values
    By eww in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:50 AM
  4. Displaying Query Properties in a Form
    By Bjar in forum Programming
    Replies: 1
    Last Post: 07-16-2008, 07:51 AM
  5. One table multiple fields identical properties.
    By swampdonkey in forum Queries
    Replies: 2
    Last Post: 09-29-2006, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums