Results 1 to 3 of 3

Thread: Field Description ---> VBA read/set ??

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    4

    Question Field Description ---> VBA read/set ??

    Is there any way to programatically read or set the field description in the database design view?

    Thanks,
    DW

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Field Description ---> VBA read/set ??

    We are talking about Access I assume.

    You can read the property Description like so...

    VB Code:
    1. 'Read:
    2. MsgBox Application.CurrentDb.TableDefs("Table1").Fields(0).Properties("Description").Value = "Testing description props of first field."
    3.  
    4. 'Write:
    5. Application.CurrentDb.TableDefs("Table1").Fields(0).Properties("Description").Value = "Testing field description property write"
    Last edited by RobDog888; May 22nd, 2006 at 11:14 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    4

    Re: Field Description ---> VBA read/set ??

    Yes, Access.

    I have a procedure that fills a table with a list of the tables, and fields in the table to produce a report that summarizes the database (see below). I am running into a <property not found> error for those fields where I haven't filled in a description.

    I can't seem to trap and skip the error using an If ... Then. I've tried testing if it is Null and also "". Any suggestions?


    VB Code:
    1. Dim db As Database
    2. Dim AllTableDefs As DAO.TableDefs
    3. Dim AllFields As DAO.Fields
    4. Dim rstTableList As DAO.Recordset
    5. Dim qdfTables As DAO.QueryDef
    6. Dim NumRecsTableList As Long
    7. Dim NumFields As Long
    8. Dim qdfDelete As DAO.QueryDef
    9.  
    10. Dim TCount As Long
    11. Dim strSQLDelete As String
    12.  
    13.  
    14. Set db = CurrentDb()
    15.  
    16. ' Set AllTableDefs to definitions of all tables in the database:
    17. Set AllTableDefs = db.TableDefs
    18. Set qdfTables = db.QueryDefs("qTableList")
    19. Set rstTableList = db.OpenRecordset("Tablelist", dbOpenDynaset)
    20. rstTableList.MoveLast
    21.  
    22. NumRecsTableList = rstTableList.RecordCount
    23.  
    24. 'reset the TableList
    25.  
    26. If NumRecsTableList > 0 Then
    27.     strSQLDelete = "DELETE * from [TableList]"
    28.        
    29.     Set qdfDelete = db.CreateQueryDef("", _
    30.             strSQLDelete)
    31.    
    32.     qdfDelete.Execute
    33. End If
    34.        
    35. ' Display names of all tables in database:
    36. For j = 0 To AllTableDefs.Count - 1
    37. If Left(AllTableDefs(j).Name, 1) <> "~" And Left(AllTableDefs(j).Name, 4) <> "MSys" And Left(AllTableDefs(j).Name, 1) <> "_" Then
    38. Set AllFields = AllTableDefs(j).Fields
    39.     For k = 0 To AllFields.Count - 1
    40.        
    41.     With rstTableList
    42.         .AddNew
    43.         !tablename = AllTableDefs(j).Name
    44.         !FieldName = AllFields(k).Name
    45.         If AllFields(k).Properties("Description").Value = "" Then
    46.         Else
    47.             Debug.Print AllFields(k).Properties("Description").Value
    48.             !Description = AllFields(k).Properties("Description").Value
    49.         End If
    50.         !TYPE = FieldType(AllFields(k).TYPE)
    51.         !length = AllFields(k).Size
    52.         !DefaultValue = AllFields(k).DefaultValue
    53.         !Position = AllFields(k).OrdinalPosition
    54.         .Update
    55.     End With
    56. Next
    57. End If
    58. Next
    59.  
    60.  
    61. End Sub

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width