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

Advertisements

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Blog Stats

  • 222,709 hits

Counter

ClustrMap


%d bloggers like this: