MS Access: setting table column Caption or Description in DDL?
Is it possible to set 开发者_如何学Ca table column's Caption or Description properties in MS Access using DDL? Ideally, we could include them in a CREATE TABLE statement.
Use DAO to set Caption and Description properties as Andrea suggested. Just be aware that both Caption and Description 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.)
Alas, it's not possibile to change or set some properties of a table or field by Access DDL. We had a similar problem, involving also relations between tables, and we resorted to DAO.
It' quite simple anyway, you'll be using objects such as DAO.Database
, DAO.TableDef
and DAO.Field
.
精彩评论