Rename table field

jamescullis

Registered User.
Local time
Tomorrow, 06:07
Joined
Jun 2, 2014
Messages
38
Hi all,

I want to rename a table field in VBA after import but I don't know the field name, I only know it's the 4th field in the import xlsx file that changes daily.

Any help please?
 
How are you importing data if the field name changes?
 
This is untested but I think it would be something like.

Code:
Dim db As DAO.Database
    Dim tdf As DAO.tableDef
    Dim rs As DAO.Recordset
    Dim fld As DAO.Field
        
    Set db = CurrentDb
    set fld = db.tabledefs("TableName").fields(3) 'position
    fld.name = "NewName"

You can refer to a fields by its name or ordinal position (0 to n).
 

Users who are viewing this thread

Back
Top Bottom