Change Field Names In Table w/Macro

D

DBarker

Is there a way to take an existing table and run a macro
that will change the names of the fields? Or do I have to
do this by programming a module. The field names will be
consistent all the time. What I am doing is pulling data
from a live database and then manipulating it to show the
fields that I want and not the naming conventions of the
live database since they are not easily understood.

Thanks,
Debbie
 
S

Steve Schapel

Debbie,

No, sorry, this is not possible, either with a macro or with a VBA
procedure. The only way you can achieve this purpose is to add new
fields to the table, with the names you want, run an update query to set
the value of the new fields to the value of the existing fields, and
then delete the existing fields. To do these steps with a macro, you
would use RunSQL macro actions to run ALTER TABLE statements, and an
OpenQuery action to run the Update.

But to be honest, I am wondering what the problem is with the existing
fields. Since you are unlikely to see the tables in the course of
normal usage of the database, does it really matter what the field names
are?
 
D

Douglas J. Steele

Actually, that's not correct, Steve. You can change the name of a field
without any problems.
CurrentDb().TableDefs("MyTable").Fields("MyOldFieldName").Name =
"MyNewFieldName" will work.

You're probably thinking of trying to change the field type.
 
S

Steve Schapel

<blush> Thanks, Doug. Yes, I was getting confused with a field type change.

Sorry, Debbie, I gave you incorrect advice!
 

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

Top