with a linked table is there a way so the link name does not include library

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dgpnich

    with a linked table is there a way so the link name does not include library

    I am using msaccess with db2 but this seems to apply to any odbc linked table. I do not want the libary to be included in the link name
    example MISCMFIL_NAMMSP where MISCMFIL is the libray and NAMMSP is the actual table.
    When I link the table by default it returns MISCMFIL_NAMMSP
    I can manually rename the link but with the number of tables and links I need to process I would prefer that the library not be included at the creation of the link so I could forgo this step
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32663

    #2
    The step cannot be foregone, but you can run a procedure in your code to process through all your tables (TableDefs) and rename them to a version of the name which excludes the text "MISCMFIL_" .

    I know where you're coming from as I did something very similar myself on one of my databases.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32663

      #3
      You could use code similar to the following :
      Code:
      Public Sub RenameTables()
          Dim strLeft As String
          Dim tblThis As DAO.TableDef
      
          strLeft = "MISCMFIL_"
          For Each tblThis In CurrentDb.TableDefs
              With tblThis
                  If Left(.Name, Len(strLeft)) = strLeft Then
                  	Debug.Print "From " & .Name,
                      Call DoCmd.Rename(NewName:=Mid(.Name, Len(strLeft) + 1), _
                                        ObjectType:=acTable, _
                                        OldName:=.Name)
                      Debug.Print " to " & .Name
                  End If
              End With
          Next tblThis
      End Sub
      Lines #9 & #13 are optional, but give a log of all the tables that have been renamed. You will find the results in the Immediate Pane (See Debugging in VBA).

      Comment

      Working...