iterates the AllTables collection looking for a table whose name includes the substring "Backup". : AllTables « Access « VBA / Excel / Access / Word






iterates the AllTables collection looking for a table whose name includes the substring "Backup".

 
Public Sub RestoreFromBackup()
   Dim tbl As Variant
   Dim intPos As Integer
   Dim strNewName As String
   
   For Each tbl In CurrentData.AllTables
      intPos = InStr(1, tbl.Name, " Backup")
      If intPos > 0 Then
         strNewName = Left(tbl.Name, intPos - 1)
         If MsgBox("Replace " & strNewName & " with " & tbl.Name _
                   & "?", vbYesNoCancel Or vbQuestion, _
                   "Rename Table") = vbYes Then
            DoCmd.SetWarnings False
            DoCmd.Rename strNewName, acTable, tbl.Name
            DoCmd.SetWarnings True
         End If
      End If
   Next

End Sub

 








Related examples in the same category

1.Delete backup tables
2.iterates the AllTables collection, opens each nonsystem table, prints its structure, and then closes the open table.
3.iterates the AllTables collection to determine if a table is open. If it is, it prompts the user to close it.