Search code examples
sqlms-accessddl

MS Access: setting table column Caption or Description in DDL?


Is it possible to set a table column's Caption or Description properties in MS Access using DDL? Ideally, we could include them in a CREATE TABLE statement.


Solution

  • Use DAO to set Caption and Description properties as Andrea suggested. Just be aware that both those properties are user-defined, not default properties ... meaning that they don't exist before you assign them a value.

    For example the following statement triggers error 3270, 'Property not found', because I have not assigned a Description for the id field:

    Debug.Print CurrentDb.TableDefs("tblFoo").Fields("id").Properties("Description")
    

    In order to assign a Description value for the field, I would first have to CreateProperty for Description then Append the new property to the field's Properties collection. Rather than write code to show you, I will suggest you use Allen Browne's SetPropertyDAO function. That function will handle the details for you. Be sure to grab the HasProperty function, too, because it is called by SetPropertyDAO. (The code for HasProperty is on the same web page, immediately below the SetPropertyDAO function code.)