Revised question about Table Description

  • Thread starter Thread starter Gary Brown
  • Start date Start date
G

Gary Brown

Does anyone know how to change the Table Description using VBA?
I can do it manually by right-clicking on a table, selecting 'Properties'
and typing in a description but I'd like to do that via code.
I would like to add a description programatically for documentation purposes

Any help would be greatly appreciated.
 
Gary Brown said:
Does anyone know how to change the Table Description using VBA?
I can do it manually by right-clicking on a table, selecting 'Properties'
and typing in a description but I'd like to do that via code.
I would like to add a description programatically for documentation
purposes

Any help would be greatly appreciated.


Here's a simple routine, originally posted by Doug Steele, with some minor
changes I made:

'----- start of code -----
Sub SetTableDescription(TableName As String, Description As String)

' Code posted by Douglas J. Steele 11-July-2008
' Modified by Dirk Goldgar, 2-July-2009

On Error GoTo ErrHandler

Dim db As DAO.Database
Dim tdfTable As DAO.TableDef
Dim prpDesc As DAO.Property

Set db = CurrentDb
db.TableDefs(TableName).Properties("Description") = Description

ExitHere:
Set prpDesc = Nothing
Set tdfTable = Nothing
Set db = Nothing
Exit Sub

ErrHandler:
Select Case Err.Number
Case 3270 'Property Not Found
Set tdfTable = db.TableDefs(TableName)
Set prpDesc = tdfTable.CreateProperty( _
"Description", dbText, Description)
tdfTable.Properties.Append prpDesc
Case Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End Select
Resume ExitHere

End Sub
'----- end of code -----
 
Back
Top