MRX
MRX

Reputation:

How to insert a column description into an Access table?

How can I insert a description for a column in an Access table using SQL?

I do:

CREATE TABLE TAB_A (COLUMN1 TEXT(30), COLUMN2 REAL, PRIMARY KEY (COLUMN1)

but how can I insert a description for each column?

Upvotes: 2

Views: 4002

Answers (2)

Tomalak
Tomalak

Reputation: 338228

You can't do it in SQL.

KB210314: ACC2000: How to Use ADO or DAO to Retrieve a Field's Description

I reckon that it can be set the same way that it can be retrieved:

Function SetFieldDesc_ADO(ByVal MyTableName As String, ByVal MyFieldName As String, ByVal Description As String)

   Dim MyDB As New ADOX.Catalog
   Dim MyTable As ADOX.Table
   Dim MyField As ADOX.Column

   On Error GoTo Err_SetFieldDescription

   MyDB.ActiveConnection = CurrentProject.Connection
   Set MyTable = MyDB.Tables(MyTableName)
   MyTable.Columns(MyFieldName).Properties("Description").Value = Description

   Set MyDB = Nothing

Bye_SetFieldDescription:
   Exit Function

Err_SetFieldDescription:
   MsgBox Err.Description, vbExclamation
   Resume Bye_SetFieldDescription
End Function

Upvotes: 1

Mitch Wheat
Mitch Wheat

Reputation: 300559

Dim col As ADOX.Column = New ADOX.Column
With col
  .Name = name
  .Type = type
  .DefinedSize = size
  .ParentCatalog = cat
  .Properties("Description").Value = description
End With

Upvotes: 0

Related Questions