Problem adding descriptions to fields in a new TableDef

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

How do I add a Description to a field when creating a new
field? in a TableDef object

Tx
 
This code will create a table description and field descriptions:

Dim db As DAO.Database
Dim prp As DAO.Property
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Dim i As Integer
Set db = CurrentDb()
i = 1

Set tbl = db.TableDefs(TableName)
Set prp = tbl.CreateProperty("description", dbText)
prp.Value = "Table to illustrate setting descriptions"
tbl.Properties.Append prp

For Each fld In tbl.Fields
Set prp = tbl.CreateProperty("description", dbText)
prp.Value = "Field " & i & " of the " & TableName & " table"
fld.Properties.Append prp
i = i + 1
Next

Now, this will only work for tables and fields which do not already have
descriptions. You will need to error trap for those that do have
description and instead fo using the CreateProperty method, you would use
the Properties method to set the value.

And of course, the table and field descriptions set here are just for
illustration.
 
Addendum to previous post:

On my website (see sig below) is a small sample database called DAO.mdb that
illustrates this. Look in the module called "TableAndFileDefinitions". The
first sub reads definitions, but the second writes them. The last sub is a
test wrapper to run the Write sub.
 
<blush>
Sorry. You'd think I could get all the information into one post!. This
code is ONLY in the DAO2k.mdb (that is the 2000 version) sample.
</blush>
 

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

Back
Top