Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADOX to get and set the description of a column in an Access database
DescriptionThis example shows how to use ADOX to get and set the description of a column in an Access database in Visual Basic 6.
KeywordsADOX, ADO, column description, Access
CategoriesDatabase
 
To get a column's description, the program opens the database connection and makes an ADOX catalog representing the database. It finds the table in the Tables collection, finds the column in the table's Columns collection, and looks for the Description property in the Column object's Properties collection. Note that this causees an error if the Description property is not present so the code protects itself with an On Erro statement.
 
Private Sub cmdGetDescription_Click()
Dim conn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column

    ' Open the connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & txtDatabase.Text
    conn.Open

    ' Make a catalog for the database.
    Set cat = New ADOX.Catalog
    Set cat.ActiveConnection = conn

    ' Get the table.
    Set tbl = cat.Tables(txtTableName.Text)

    ' Get the column.
    Set col = tbl.Columns(txtFieldName.Text)

    ' Get the Description property.
    On Error Resume Next
    txtDescription.Text = col.Properties("Description")
    If Err.Number <> 0 Then
        txtDescription.Text = ""
    End If

    conn.Close
End Sub
 
To set a description, the program performs the same steps except this time it sets the column's Description property.
 
Private Sub cmdSetDescription_Click()
Dim conn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column

    ' Open the connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & txtDatabase.Text
    conn.Open

    ' Make a catalog for the database.
    Set cat = New ADOX.Catalog
    Set cat.ActiveConnection = conn

    ' Get the table.
    Set tbl = cat.Tables(txtTableName.Text)

    ' Get the column.
    Set col = tbl.Columns(txtFieldName.Text)

    ' Set the Description property.
    col.Properties("Description") = txtDescription.Text
    txtDescription.Text = ""

    conn.Close
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated