1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Sub Importer_Tables()
Dim Db As DAO.Database
Dim rst As DAO.Recordset
Dim tbd As DAO.TableDef
Dim cOldName As String
On Error GoTo Importer_Tables_Error
Set Db = CurrentDb
DoCmd.SetWarnings (False)
'importer les tables à partir de la procédure enregistrée «
importation2 »
DoCmd.RunSavedImportExport ("importation2")
For Each tbd In Db.TableDefs
If Right(tbd.Name, 1) = "1" And Left(tbd.Name, 6) = "dbaa85" Then
'Si le nom de la table se termine par '1' et commence par
'dbaa85"
cOldName = Left(tbd.Name, Len(tbd.Name) - 1)
'cOldName : nom de la table moins le "1" final
If (DCount("*", "MSysObjects", "Name='" & cOldName & "'") > 0)
Then
'Si cOldName existe, on supprime ses enregistrements
Db.Execute "delete * from " & cOldName & ""
'et on rajoute les ENREGISTREMENTS de la table en cours (qui
se termine par 1)
Db.Execute "INSERT INTO " & cOldName & " SELECT * FROM " &
tbd.Name
'Supprimer les TABLES nouvellement importées (qui se
terminent par 1 : exemple dbaa85_ind1 )
Db.Execute "drop table " & tbd.Name
End If
End If
Next
rst.Close
Db.Close
Set rst = Nothing
Set Db = Nothing
DoCmd.SetWarnings (True)
MsgBox "Mise à jour des tables terminée !" & vbCrLf & vbCrLf & "La base
va être fermée automatiquement pour compactage..."
'Pour fermer la base de données
'DoCmd.Quit
' Application.Quit acQuitSaveAll
Application.CloseCurrentDatabase
On Error GoTo 0
Exit Sub
Importer_Tables_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
Importer_Tables of Module Import_Tables"
End Sub |
Partager