"How can I set and modify the descriptions of objects using VBA?"
Function bolModTableProperty(strTableName As String, strProperty As String, strPropType, strDescription As String) As Boolean
'Author: Jose F Hernandez jose@networkservices.net
'Purpose: Modify the Description of linked tables.
Dim db As Database
Dim strDesc As String
Dim prp As Property
Set db = currentdb
On Error GoTo bolModTableProperty_Err 'In case the table does not have a Description property set
db.TableDefs(strTableName).Properties(strProperty).value = strDescription 'A null Val in strdescription will give an Error
bolModTableProperty = True
bolModTableProperty_Exit:
If Not db Is Nothing Then Set db = Nothing
If Not prp Is Nothing Then Set prp = Nothing
Exit Function
bolModTableProperty_Err:
bolModTableProperty = False
Select Case Err.Number
Case 3270 ' property NOT found
Set prp = db.TableDefs(strTableName).CreateProperty(strProperty, strPropType, strDescription)
db.TableDefs(strTableName).Properties.Append prp
db.TableDefs(strTableName).Properties.Refresh
Resume Next
Case Else
MsgBox Err.Description
End Select
Resume bolModTableProperty_Exit
End Function
Function strGetTableDesc(strTable As String) As String
On Error Resume Next 'In case the table does not have a Description property set
'Author: Jose F Hernandez jose@networkservices.net
'Purpose: Get the description for a linked table from the B/E DB.
'Some Info: I used the 'msysobjects' table to grab the path to the B/E db and also to grab the
'name of the foreign table name. Just in case a different name is used for the linked table name.
'
Dim strDesc As String
Dim db As Database
Dim strDb As String
Dim strForeignTblName As String
strDb = DLookup("Database", "msysobjects", "Name=" & Chr(34) & strTable & Chr(34)) 'Path to B/E DB
strForeignTblName = DLookup("ForeignName", "msysobjects", "Name=" & Chr(34) & strTable & Chr(34)) Name of table in External DB
If Len(strDb) = 0 Then 'Local table.
Set db = currentdb
strDesc = db.TableDefs(strTable).Properties("Description").value
Else
Set db = DBEngine.OpenDatabase(strDb) 'Linked Table
strDesc = db.TableDefs(strForeignTblName).Properties("Description").value 'Linked Tables
End If
strGetTableDesc = strDesc
If Not db Is Nothing Then Set db = Nothing
End Function
Sub test()
Dim strTemp As String
Dim strTable As String
strTable = "TableName"
DoCmd.Hourglass True
' Use this ONLY on linked tables.
strTemp = strGetTableDesc(strTable)
bolModTableProperty strTable, "Description", dbText, strTemp
DoCmd.Hourglass False
End Sub