How to Programmatically Retrieve Field & Table Comments

  • Thread starter Thread starter Siegfried Heintze
  • Start date Start date
S

Siegfried Heintze

I found the example C++/MFC program DAOView that enumerates the fields in a
TableDef and print out all the properties of each field. I wrote my own
VB.NET program to import DAO and enumerate the fields in a tabledef and
display the attributes and properties of each field.

I have looked up the DAO.field in the documentation and I cannot figure out
how to retrieve the comments! The intellisence in VB.NET gives me no clues
either.

Can someone kindly tell me how to programmatically set and retrieve the
comments that the MSAccess GUI allows you to set and retrieve?

Thanks,
Siegfried
 
Siegfried said:
I found the example C++/MFC program DAOView that enumerates the fields in a
TableDef and print out all the properties of each field. I wrote my own
VB.NET program to import DAO and enumerate the fields in a tabledef and
display the attributes and properties of each field.

I have looked up the DAO.field in the documentation and I cannot figure out
how to retrieve the comments! The intellisence in VB.NET gives me no clues
either.

Can someone kindly tell me how to programmatically set and retrieve the
comments that the MSAccess GUI allows you to set and retrieve?


That's one of the Access (as a user of Jet) custom user
created properties. These custom properties do not exist if
you don't add a description in the UI.

The typical approach is to use error handling to catch the
non-existent case and set your comment string variable to
whatever you want. In VBA, the code would look like:

strComment = fld.Properties("Description")
If Err.Number = 3270 Then
strComment = "N/A"
End If

To set the property, you have to determine if it exists. If
it does, just set it, if not create it:

fld.Properties("Description") = strComment
If Err.Number = 3270 Then
Set prp = fld.CreateProperty("Description", dbText,
strComment)
fld.Properties.Append prp
tdf.fields.Refresh
End If
 
Back
Top