View Full Version : How to change a database field description through code


yeuker
05-25-2007, 10:54 AM
Hi Everyone,

I am writing a small patch for an exisiting db that is deployed on quite a few machines. It basically just runs some alter statements to add and remove columns and alter a few others. The problem is that I need to also alter the column description (that you can see if you are editing the table in design view). How do I do that through code? Thanks so much gurus.

Yeuker

pbaldy
05-25-2007, 11:12 AM
You can use a DAO TableDef to view/edit the description.

yeuker
05-25-2007, 11:24 AM
Could you please post some example code? I am using ado. Can I do it through Ado? Thanks again,

Cory

pbaldy
05-25-2007, 11:29 AM
Don't know about ADO, just know that it can be done with DAO.

yeuker
05-25-2007, 11:37 AM
Could you please post some code for me?

Thanks again,

Cory

pbaldy
05-25-2007, 11:42 AM
Dim db As DAO.Database
Dim tdf As DAO.TableDef

Set db = CurrentDb()
Set tdf = db.TableDefs("TableName")

tdf.Fields("FieldName").Properties("Description") = "New description here"

Set tdf = Nothing
Set db = Nothing

yeuker
05-25-2007, 12:18 PM
Sweet man. I'll give it a try in a bit. Cheers,

Yeuker.

gemma-the-husky
05-25-2007, 12:27 PM
if you're working in a linked backend database you will find that some properties cannot be changed. in that case you need to open the linked database directly - dbengine.workspaces(0) etc, but i'm not sure of the exact sysntax ,and only then will you be able to change everything - add fields etc.

yeuker
05-26-2007, 10:35 AM
Here is the code in case anyone else is looking for it. Thanks all.

-Yeuker

Option Compare Database

Option Explicit

Const dbPath = "C:\\...\\...\\yourfile.mdb"

Function Rename()

Dim wsp As Workspace
Dim db As Database
Dim tdf As TableDef


Set wsp = DBEngine.Workspaces(0)
Set db = wsp.OpenDatabase(dbPath)

Set tdf = db.TableDefs("tablename")
tdf.Fields("fieldname").Properties("Description") = "New description here"

Set tdf = Nothing
Set db = Nothing

db.Close
Set db = Nothing
Set wsp = Nothing
End Function