Change field name in a table

jeffcullina

New member
Local time
Today, 06:42
Joined
Jul 11, 2001
Messages
7
How do I change a field name in a table? I have tried the following (and several derivations of it) with no luck:

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim field As DAO.field

Set db As CurrentDb
Set rst = db.OpenRecordset(TblName, dbOpenTable)
Set field = rst.Fields("OldName")
Set field.FieldName = "NewName"
rst.Update
rst.Close
db.Close

Thanks,
Jeff
 
You need to modify the TableDef in order to change the field name. Try this code fragment(Access 97):

Dim db As Database
Dim tdf As TableDef

Set db = CurrentDb()
Set tdf = db.TableDefs("tablename")
tdf.Fields("fieldname").Name = "newfieldname"
 

Users who are viewing this thread

Back
Top Bottom