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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| Private Sub Commande5_Click()
Dim x As Integer, y As Integer, strSQL As String
Dim wrkDefaultSource As Workspace
Dim wrkDefaultDest As Workspace
Dim dbsSource As Database
Dim dbsDest As Database
Dim tdfloop As TableDef
Dim TableSource As String, TableDest As String, BoolTrouve As Boolean, BoolData As Boolean
Dim laTableSource As TableDef, laTableDest As TableDef
Dim fldSource As Field, fldDest As Field, leChamp As Field, BoolTrouveFld As Boolean
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsSource = wrkDefault.OpenDatabase(Source)
Set dbsDest = wrkDefault.OpenDatabase(Destination)
BoolTrouve = False
BoolData = False
'On Error Resume Next
With dbsSource
For x = 0 To .TableDefs.Count - 1
TableSource = .TableDefs(x).Name
TableDest = .TableDefs(x).Name
'''Cherche la table dans la bd destination
With dbsDest
For Each tdfloop In .TableDefs
If tdfloop.Name = TableSource Then
BoolTrouve = True
Exit For
Else
BoolTrouve = False
End If
Next tdfloop
If BoolTrouve = False Then
'''Table inexistante => Import
BoolData = IIf(dbsSource.TableDefs(x).Properties("Description") = "Avec data", True, False)
If BoolData = False Then
DoCmd.TransferDatabase acImport, "Microsoft Access", Source, acTable, TableSource, TableSource & "Temp", True
Else
DoCmd.TransferDatabase acImport, "Microsoft Access", Source, acTable, TableSource, TableSource & "Temp", False
End If
DoCmd.CopyObject Destination, TableSource, acTable, TableSource & "Temp"
Call SupprimerTable(TableSource & "Temp")
Else
'''Table existante => Vérifie leur structure
For Each fldSource In dbsSource.TableDefs(x).Fields
For Each fldDest In tdfloop.Fields
If fldDest.Name = fldSource.Name Then
BoolTrouveFld = True
Exit For
Else
BoolTrouveFld = False
End If
Next fldDest
If BoolTrouveFld = True Then
'''Vérifie propriétés et les modifie si besoin
If fldDest.Type <> fldSource.Type Or fldDest.size <> fldSource.size Then
Call ChangeFields(Destination, TableDest, fldDest.Name, fldSource.Type, fldSource.size, fldSource.Attributes)
End If
Else
'''Crée champ
Set laTableDest = dbsDest.TableDefs(TableDest)
Set leChamp = laTableDest.CreateField(fldSource.Name)
leChamp.Type = fldSource.Type
leChamp.size = fldSource.size
leChamp.Attributes = fldSource.Attributes
laTableDest.Fields.Append leChamp
End If
BoolTrouveFld = False
Next fldSource
End If
BoolTrouve = False
BoolData = False
End With
TblSuite:
Next x
End With
Set laTableSource = Nothing
Set laTableDest = Nothing
Set leChamp = Nothing
Set dbsource = Nothing
Set dbsDest = Nothing
Set tdfloop = Nothing
Set wrkDefault = Nothing
'''Crée les relations à l'identique entre Source et destination
Call CréeRelSauvegarde(Source, Destination)
End Sub |
Partager