Access VBA – Change the Name of a Field in an Existing Table

I’ve just been importing some records from Excel to Access using VBA.

By default the names of the fields of the imported records are “F1″, “F2″, “F3″ etc.

To make things a little clearer I wanted to rename these imported fields to more meaningful names.

Here’s how to do it:

CurrentDb().TableDefs(TableName).Fields("OldName").Name = "NewName"

where:
TableName is the name of the table in which we want to change the names
“OldName” is the old name of the field
“NewName” is the new name we want to use for this field

1 Response to “Access VBA – Change the Name of a Field in an Existing Table”


  1. 1 JP October 10, 2008 at 7:36 pm

    When importing a spreadsheet with a header row to an Access database, you can specify that the first row of data is the headers. The command ‘DoCmd.TransferSpreadsheet’ has an option ‘HasFieldNames’ which, when set to True, tells VBA that the first row of data is the header.

    Thx,
    JP


Leave a Reply




Blog Stats

  • 29,945 hits

Counter

ClustrMap