Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2006
    Posts
    5

    Unanswered: Renaming Columns heading in Access table

    Please ,anyone knows if there is a way to rename Columns heading in Access's table using vba. I am able to read the Columns content but When I try to rename the Column heading using .Edit and .Update I get error.
    Thanks in advance for your help.

  2. #2
    Join Date
    Mar 2005
    Posts
    22
    you can use the alter command in a sub to change the column name

    ALTER TABLE table [ * ]
    RENAME [ COLUMN ] column TO newcolumn

    Create a sub in your code that will alter the table, for example:

    Private Sub cmdAlterPersons_Click()
    DoCmd.RunSQL "ALTER TABLE Persons RENAME COLUMN FullName to Last Name"
    End Sub

    This would work and it is quick and easy. You could pass a reference in the sub if you want to change the name dynamically. for example:

    Private Sub cmdAlterPersons_Click(byval NewName as string)
    DoCmd.RunSQL "ALTER TABLE Persons RENAME COLUMN FullName to " & NewName
    End Sub


    Also you will want you can turn off the warning so they don't see the pop up to advise that the table is being altered.

    Private Sub cmdAlterPersons_Click(byval NewName as string)

    DoCmd.SetWarnings False

    DoCmd.RunSQL "ALTER TABLE Persons RENAME COLUMN FullName to " & NewName

    DoCmd.SetWarnings true
    End Sub

    I sure this helps

Posting Permissions

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