how to programmatic add table description?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Access database window, we can right-click the table and select
properties. Then a new dialog box appears. We can check the table
creation/modified date/time, and we can type a description, or set the
attributes of the table to hidden, etc.

This is the way how we could add a description manually. Can we add the same
programmatically?
 
The description is stored in a property of the TableDef object named,
appropriately enough, Description. The "trick" is that the property doesn't
exist until you add a description. That means you need something like the
following untested air code:

Sub SetDescription(TableName As String, _
TableDescription As String)

On Error GoTo Err_SetDescription

Dim tdfCurr As DAO.TableDef
Dim prpDesc As DAO.Property

Set tdfCurr = CurrentDb().TableDefs(TableName)
tdfCurr.Properties("Description") = TableDescription

End_SetDescription:
Exit Sub

Err_Property:
' Error 3270 means that the property was not found.
If Err.Number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
Set prpDesc = tdfCurr.CreateProperty( _
"Description", dbText, TableDescription)
tdfCurr.Properties.Append prpNew
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & _
Err.Description & ")"
Resume End_SetDescription
End If
End Sub


Note that this is DAO code. If you're using Access 2000 or 2002, make sure
you've set a reference to the DAO library.
 
I revised the codes slightly (delete the properties before creating and
setting it) and it works for me.
 
Back
Top