Réponse n° 1 -------- le 21/04/2015 : 21:07 par 3Stone
Administrateur
|
Bonjour,
En général, lorsque je dois copié un base, j'en profite pour la compacter... Alors, en utilisant DAO (cocher la référence DAO) : Code :DBEngine.CompactDatabase strBase, strDest
Ou alors, on peut utiliser la fonction suivant :
Code :Function CopyFile(ByVal source$, ByVal Destination$) As Long Dim Index1 As Integer, NumBlocks As Integer Dim FileLength As Long, LeftOver As Long, AmountCopied As Long Dim SourceFile As Integer, DestFile As Integer Dim FileData As String Dim RetVal As Variant Const BlockSize = 32768 On Error GoTo Err_CopyFile ' Remove the destination file. DestFile = FreeFile Open Destination For Output As DestFile Close DestFile ' Open the source file to read from. SourceFile = FreeFile Open source For Binary Access Read Shared As FreeFile ' Open the destination file to write to. DestFile = FreeFile Open Destination For Binary As DestFile ' Get the length of the source file. FileLength = LOF(SourceFile) ' Calculate the number of blocks in the file and left over. NumBlocks = FileLength \ BlockSize LeftOver = FileLength Mod BlockSize ' Create a buffer for the leftover amount. FileData = String$(LeftOver, 32) ' Read and write the leftover amount. Get SourceFile, , FileData Put DestFile, , FileData ' Create a buffer for a block to be read. FileData = String$(BlockSize, 32) ' Read and write the remaining blocks of data. For Index1 = 1 To NumBlocks ' Read and write one block of data. Get SourceFile, , FileData Put DestFile, , FileData Next Index1 Close SourceFile, DestFile CopyFile = AmountCopied Bye_CopyFile: Exit Function Err_CopyFile: CopyFile = -1 * Err Resume Bye_CopyFile End Function
et faire : Code :CopyFile "C:/le/chemin/complet/labase.mdb", "D:/LaBase.mdb"
Cordialement Pierre (3Stone) |