N. Saad N. Saad - 1 year ago 150
Vb.net Question

modify the Description property of an Access table from .NET

I am trying to modify field and table properties for an MS Access database from within a VB.Net project.

So far I have successfully done the following:
1- Retrieve Schema
2- Retrieve Table Descriptions
3- Modify Field Description within a table

I still haven't found a way to modify the Description of a table in the database. I am using ADODB and ADOX.

Below is how I am modifying the field description:

Dim MyDB As New ADOX.Catalog
Dim MyTable As ADOX.Table
Dim DB As New ADODB.Connection

DB.Open("Provider='Microsoft.ACE.OLEDB.12.0';Data Source= 'People.accdb';")
MyDB.ActiveConnection = DB

MyTable = MyDB.Tables("People")
MyTable.Columns("MyID").Properties("Description").Value = "Changed"

Answer Source

The Description property for an Access table is not available to ADOX. You will need to use ACE DAO, like this:

' required COM reference:
'     Microsoft Office 14.0 Access Database Engine Object Library
' Imports Microsoft.Office.Interop.Access.Dao
Dim dbe As New DBEngine
Dim db As Database = dbe.OpenDatabase("C:\Users\Public\myDatabase.accdb")
Dim tbd As TableDef = db.TableDefs("Donors")
Dim newDescription As String = "This is the new table description."
    tbd.Properties("Description").Value = newDescription
Catch ex As Runtime.InteropServices.COMException
    If ex.ErrorCode = -2146825018 Then
        ' Property not found.
        tbd.Properties.Append(tbd.CreateProperty("Description", DataTypeEnum.dbText, newDescription))
    End If
End Try