Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem renaming column with SQL 1

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
NL
I am trying to use the following:

MySQL = "ALTER TABLE MyTable RENAME COLUMN MyColumn to MyNewColumn;"
DoCmd.RunSQL MySQL

This yields:
Run time error '3293': Syntax error in ALTER TABLE statement

What is wrong here; MyTable and MyColumn are valid names.

 
Access doesn't support this alter table statement. It has to be done using VB.

Dodge20
 
Something like

Dim db As Database
Set db = CurrentDb
' Rename the field
db.TableDefs("[" & TblName & "]").Fields("CurrentFieldName").Name = NewFieldName


Dodge20
 
It (renaming Fields in a data base) is also generally avoided. Other objects may (usually DO reference tables/fields through the name properties. Changing an object name would normally require corresponding changes in all other objects which reference the object, including secondary and teritary references.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks Dodge20 and MichaelRed,

dbf.TableDefs("MyTable").Fields("MyColumn").Name = "MyNewColumn" worked fine.

I am aware that changing column names is in principle not a great idea. I must change the content of my index field, so will batchwise (i) add a new field, (ii) fill this with the newly calculated index, (iii) delete the old index and (iv) rename the new field to the old index field name.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top