I am simply trying to write a function which changes the column name of a table in MS Access/VBA.
Here is the code:
Private Sub Change_Col_Name(Table As String, OldColName As String, NewColName As String)
Dim tblDef As TableDef
Dim fldDef As Field
Set tblDef = CurrentDb.TableDefs(Table)
For Each fldDef In tblDef.Fields
If fldDef.Name = OldColName Then
fldDef.Name = NewColName
Exit For
End If
Next fldDef
tblDef.RefreshLink
CurrentDb.TableDefs.Refresh
End Sub
I get an error 3420 for the line
For Each fldDef In tblDef.Fields
I’m not sure what I’m doing wrong.
Thanks in advance.