Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Posts
    85

    Unanswered: Alter DAO statement

    Trying to make the below statement be able to change multiple field names

    (change's a Field name)
    Sub RenameField(strTableName As String, _
    strFieldFrom As String, _
    strFieldTo As String)

    Dim dbs As DAO.Database
    Dim tDef As DAO.TableDef


    Dim fDef As DAO.Field

    Set dbs = CurrentDb()
    Set tDef = dbs.TableDefs(strTableName)
    Set fDef = tDef.Fields(strFieldFrom)

    fDef.Name = strFieldTo

    Set fDef = Nothing
    Set tDef = Nothing
    Set dbs = Nothing

    'Then just call it like: RenameField "tblRenCol","Jeff","Jeffrey"

    End Sub

    Am I on the right track to change multiple field names

    Sub RenameField(strTableName As String, _
    strFieldFrom As String, _
    strFieldTo As String)

    Dim dbs As DAO.Database
    Dim tDef As DAO.TableDef
    Dim fDef As DAO.Field

    Set dbs = CurrentDb()
    Set tDef = dbs.TableDefs(strTableName)
    Set fDef = tDef.Fields(strFieldFrom1,strFieldFrom2,strFieldFr om3)

    fDef.Name = (strFieldTo1,strFieldTo2,strFieldTo,strFieldTo3)

    Set fDef = Nothing
    Set tDef = Nothing
    Set dbs = Nothing

    End Sub


    Thank's Tim

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    I think you are barking up the wrong tree

    what I would is use the crosstab which turn feild data into feild names

    them do a make table to make it a table them run a report over that

    DoCmd.SetWarnings False ' turn off the warnings
    DoCmd.OpenQuery "mk-QUERY" 'WHICH WOULD BE CALLING THE CROSSTAB QUERY
    DoCmd.SetWarnings True
    DoCmd.OpenReport "REPORT1", acViewNormal 'report1 is pointing to the new created table
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Tim

    One question - why do you need to do this? Needing code to change column names in tables is a red light that things Might Be Very Wrong.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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