I have like 20 datasets, each with 28 fields without the first row having fieldnames. So MS Access assigned 'Field1', 'Field2'.... 'Field28' as fieldnames for each column. I'd like to know if it is possible to run a query to rename them? I couldn't find any information online and I tried manually entering the names but it is taking too long.
Asked
Active
Viewed 2,848 times
0
-
You can use `ALTER` statements to change the field names. – VVN Mar 02 '16 at 04:59
-
What do you want to rename them to? – Chendur Mar 02 '16 at 04:59
1 Answers
2
Access SQL does not support changing the name of an existing field.
You could create a SELECT
query and alias the field name:
SELECT Field1 AS FieldA FROM YourTable;
Then you would use the query instead of the table whenever you want to display the aliased name.
Or you could use a "make table" query to create a new table with the new field name:
SELECT Field1 AS FieldA INTO NewTable FROM YourTable;
Or you could execute an ALTER TABLE
statement to add the new field, then an UPDATE
to populate the new field with the old field data, and finally DROP
the old field. But that seems like too much work.
Instead of SQL, consider using VBA to rename the field:
CurrentDb.TableDefs("YourTable").Fields("Field1").Name = "FieldA"

HansUp
- 95,961
- 11
- 77
- 135