We help IT Professionals succeed at work.

how to change a table column name on access with an alter query

hi

i have a table that the name is "table1" and there is a field with the name "field2" and i want to change it to the name "field1" how can i make it, something  like this:

ALTER TABLe table1
ALTER COLUMN field2 field1

thanks alot
Comment
Watch Question

Do you need to change it from SQL? Access has a "Design mode" to design a table manually, where you can edit the name of the columns and any other things.

As I know, the only way to rename a table column on Access by SQL is to drop the column and add the column (but if you do so, you will have to copy the data first to another table and load back after your DROP+ADD operation is complete).
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
You can't. But you can use VBA:
 Dim  db  As  DAO.Database 
     Dim  tdd  As  DAO.TableDef 
     Set  db = CurrentDb() 
     Set  td = db.TableDefs(YourTableName) 
     td.Fields(CurrentFieldName).Name = NewFieldName 

Open in new window

Of course, the table has to be closed to allow this.

/gustav

Author

Commented:
thanks alot
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
You are welcome!

/gustav