Programmatically change column name

  • Thread starter Thread starter bill morgan
  • Start date Start date
B

bill morgan

Friends,

Anyone know of a way to change the name of a table column
(through a SQL Alter Table statement, etc.)
programmatically?

Thanks ...
 
I don't believe it can be done in SQL, short of creating a new column,
copying the data, and deleting the old one. It can be done in DAO ...

Public Sub RenameColumn()

CurrentDb.TableDefs("Categories").Fields("CategoryName").Name =
"CatName"

End Sub

.... or, if you really must, ADOX ...

Public Sub RenameColumnX()

Dim cat As ADOX.Catalog

Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
cat.Tables("Categories").Columns("CatName").Name = "CategoryName"

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Brendan,

Exactly what I was looking for. And you gave me two
solutions, rather than one! Thank you ...

bill
 
Back
Top