Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005

    Unanswered: change fieldnames in the table using VB


    In Visual Basic language,

    there are codes for createDef (generate the new table), right.

    Can we update the fieldnames in the table?

    I have one table with 3 fieldnames:
    Name1, Name2, Name3

    I want to write VB to edit the fieldnames in the table as following:

    Can VB edit it except generating the table?
    I went through the forum, but I cannot get ideas, and related problems.


  2. #2
    Join Date
    Feb 2004

    Chg FieldName

    Following should work on Jet DB's, just replace names in the test function and call f_RenameFieldNameOK for each field you want to change. Enjoy!!

    Function test_f_RenameFieldName()
    If f_RenameFieldNameOK("TableName", "OldFieldName", "NewFieldName") Then MsgBox "Rename worked!"
    End Function

    Function f_RenameFieldNameOK(pTbl, pWas, pIs) As Boolean
    Dim tdf As TableDef, fld As Field, db As Database

    On Error GoTo errmsg
    Set db = CurrentDb
    Set tdf = db.TableDefs(pTbl)
    Set fld = tdf.Fields(pWas)
    fld.Name = pIs

    f_RenameFieldNameOK = True
    Exit Function

    MsgBox err & ", " & err.Description

    End Function

Posting Permissions

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