Bon ce morceau de code viens d'un prog plus complexe, mais en gros ca devrait le faire, il recopie une table d'un .mdb a un autre
Set TdPatch = Patch.TableDefs(RsAction("Nom"))
Set TdBase = Base.CreateTableDef(TdPatch.Name, TdPatch.Attributes, TdPatch.SourceTableName, TdPatch.Connect)
If (Err.Number <> 0) Then
If (Err.Number <> 3012) Then
Print #numfich, "Impossible de créer la table " & TdPatch.Name & vbCrLf & "Arret du patch"
OKtrans = False
Else
Err.Clear
Base.TableDefs.Delete TdPatch.Name
Set TdBase = Base.CreateTableDef(TdPatch.Name, TdPatch.Attributes, TdPatch.SourceTableName, TdPatch.Connect)
If (Err.Number <> 0) Then
Print #numfich, "La table " & TdPatch.Name & " existe déja, et on ne peut la remplacer"
OKtrans = False
End If
End If
End If
For Each ChpsPatch In TdPatch.Fields
Set ChpsBase = TdBase.CreateField(ChpsPatch.Name, ChpsPatch.Type, ChpsPatch.Size)
If (Err.Number <> 0) Then
Print #numfich, "Impossible de créer le champs " & ChpsPatch.Name & " dans la table " & TdPatch.Name
OKtrans = False
End If
If (ChpsPatch.Type = dbText) Then
ChpsBase.AllowZeroLength = ChpsPatch.AllowZeroLength
End If
ChpsBase.Attributes = ChpsPatch.Attributes
ChpsBase.DefaultValue = ChpsPatch.DefaultValue
ChpsBase.Required = ChpsPatch.Required
'ChpsBase.ValidateOnSet = ChpsPatch.ValidateOnSet
'ChpsBase.ValidationRule = ChpsPatch.ValidationRule
'ChpsBase.ValidationText = ChpsPatch.ValidationText
TdBase.Fields.Append ChpsBase
Next ChpsPatch
For Each IndPatch In TdPatch.Indexes
Set IndBase = TdBase.CreateIndex(IndPatch.Name)
If (Err.Number <> 0) Then
Print #numfich, "Impossible de créer l'index " & IndPatch.Name & " dans la table " & TdPatch.Name
OKtrans = False
End If
IndBase.Clustered = IndPatch.Clustered
IndBase.IgnoreNulls = IndPatch.IgnoreNulls
IndBase.Primary = IndPatch.Primary
IndBase.Required = IndPatch.Required
IndBase.Unique = IndPatch.Unique
For Each ChpsPatch In IndPatch.Fields
Set ChpsBase = IndBase.CreateField(ChpsPatch.Name)
IndBase.Fields.Append ChpsBase
Next ChpsPatch
TdBase.Indexes.Append IndBase
Next IndPatch
Base.TableDefs.Append TdBase
A++
Crazyht :)