Results 1 to 2 of 2

Thread: Changing the name of a table

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 1999
    Location
    Caracas, Miranda, Venezuela
    Posts
    69

    Post

    How Can I change de Name of a Access Table from VB?

    Thanks
    Rafael


    ------------------


  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Code:
    Public Sub RenameTable(sOldName As String, sNewName As String)
    
        Dim nCtr As Integer
        Dim bFound As Boolean
       
        On Error GoTo ErrorRoutine
    
        'strip off owner if necessary
        If InStr(sNewName, ".") <> 0 Then
            sNewName = Mid(sNewName, InStr(sNewName, ".") + 1, Len(sNewName))
        End If
        
        'Search to see if table exists
        For nCtr = 0 To gdbTargetDB.TableDefs.Count - 1
            If UCase(gdbTargetDB.TableDefs(nCtr).Name) = UCase(sOldName) Then
                gdbTargetDB.TableDefs(nCtr).Name = sNewName
                bFound = True
                Exit For
            End If
        Next
        
        If Not bFound Then
            gsErrText = "Table name not found"
            Err.Raise 10010
            Exit Sub
        End If
        
    ErrorRoutine:
    
        If Err.Number <> 0 Then
            'Put your error code here
        End If
    
    
    End Sub

    ------------------
    Marty

Posting Permissions

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



Click Here to Expand Forum to Full Width