tags:

views:

52

answers:

2

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.

A: 

Hi. 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.

Andrea Monelli
"Resorted to DAO?" WTF? I'd say "resorting to DDL" would be the real step down, as DAO is by far the best way to interact fully with Jet/ACE databases. DDL is what you use when you *can't* use DAO.
David-W-Fenton
Hi David, I'd agree with you if all the database panorama was Access. We tend to use DDL since it's much more generic: write once, run (almost) everywere (almost) unmodified :)
Andrea Monelli
But these properties are not generic SQL field properties, but specific to MS Access. Secondly, these properties have no meaning except within Access, so attempting to write generic DDL for that context doesn't make any sense to me.
David-W-Fenton
I agree that DAO is much more flexible, but in this case DDL was much easier. We were migrating table definitions from a distributed MySQL database to a local Access db and we wanted to put the MySql "comment" properties in the Description or Caption. Easiest to just dump the SQL, run some regex and then import it back to Access as DDL. Thanks for all the feedback!
I think the goal of cross-platform SQL is impossible when you're using properties specific to one database or another.
David-W-Fenton
+2  A: 

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.)

HansUp
Thank! Appreciate the confirmation -- and the extra info in how the properties work.