Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    100

    Unanswered: Renaming a field using script

    How can I go about renaming a field in a table (as opposed to in a query) using VBA script?

    I have tried so many different ideas but seem to be coming up empty.

    Thanks!

  2. #2
    Join Date
    Oct 2003
    Posts
    706
    You can edit the object, but ... "if you feel like you need to rename a field dynamically, you are probably going about things the wrong way."
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Perhaps using Alter Table you can Add a new Field (the name you want), then copy the content of your old column in that new column using the UPDATE..... SET statement.

    Then drop the old Column using dbs.Execute "ALTER TABLE yourTableName DROP COLUMN oldColumnName;"

    As logic it should function.

  4. #4
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147
    You can edit the table using code, but like sundialsvcs said maybe doing something else wrong..

    However, its a very simple line of code...

    CurrentDb.TableDefs("Your_Table_Here").Fields("old _name").Name = "new_name"

    You can replace old_name with either the name of the field you want to replace, or an integer, relating to that field.

    Regards

    Ken

  5. #5
    Join Date
    Jan 2004
    Posts
    100
    Originally posted by Ken_Hart
    You can edit the table using code, but like sundialsvcs said maybe doing something else wrong..

    However, its a very simple line of code...

    CurrentDb.TableDefs("Your_Table_Here").Fields("old _name").Name = "new_name"

    You can replace old_name with either the name of the field you want to replace, or an integer, relating to that field.

    Regards

    Ken
    I have no doubt I am going about things the wrong way! Unfortunately, I know of no other way.

    As an FYI, here is what I'm doing.....

    I have a report that refers to 12 monthly fields of current information. As each month passes, the oldest month is moved to another table holding old information. I then add a new month for new information. As the form refers to the 12 specific field names found in the table of current information, I am essentially copying each column of data over one column as a month passes. This way the form can always refer to the same fields and I am essentialy, by changing the name of the fields, moving each field's data into the next month's data.

    If there are better ways to do this, I'm all ears.

    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •