Can one access the table design's description field through vba?

J

Jesper F

Tables' design view have a description field.
Text here is displayed in the status bar.
Can the value of this field be accessed with code? I can't
seem to find it.
 
J

Jeff Conrad

Public Function funcListDescription()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As Field

Set db = CurrentDb
Set tdf = db.TableDefs("YourTableNameHere")
For Each fld In tdf.Fields
Debug.Print fld.Properties("Description")
Next fld

db.Close
Set db = Nothing

End Function
 
D

Douglas J. Steele

Just a word of caution.

The Description property doesn't exist until you actually assign a
description. If you try to access the description property for a table that
doesn't have a description, it'll raise an error (3270: Property Not Found)

You need to handle this error.
 
J

Jeff Conrad

Ahhh quite right Doug.
I should have included some error handling for Jesper.
Thanks for the catch.

Jesper, try this instead:

Public Function funcListDescription()
On Error GoTo ErrorPoint

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As Field

Set db = CurrentDb
Set tdf = db.TableDefs("YourTableNameHere")
For Each fld In tdf.Fields
Debug.Print fld.Properties("Description")
Next fld

ExitPoint:
db.Close
Set db = Nothing
Exit Function

ErrorPoint:
If Err.Number = 3270 Then
Resume Next
Else
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
End If
Resume ExitPoint

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top