Bonjour,
Des évènements inattendus m'ont tenu éloigné de mon ordinateur pendant plusieurs semaines et je me retrouve devant le même problème :
Le problème semble venir de VB.NET. En effet, j'ai créé un projet en VB6
Premières lignes du fichier VBP :
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\G{4AC9E1DA-5BAD-4AC7-86E3-24F4CDCECA28}#c.0#0#C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\ACEDAO.DLL#Microsoft Office 14.0 Access database engine Object Library
Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\Windows\SysWOW64\scrrun.dll#Microsoft Scripting Runtime
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
Form=Form1.frm
...................................
Code de la Form1 :
Dim objet_fso As New FileSystemObject
Dim f As File
Dim strSourcePath As String
Dim strDestPath As String
Private Sub btnChoisir_Click()
Label1 = ""
Label2 = ""
Label3 = ""
Label4 = ""
If Option1 Then
CommonDialog1.Filter = "Base ACCESS 2010 (*.accdb)|*.accdb"
ElseIf Option2 Then
CommonDialog1.Filter = "Base ACCESS 97 (*.mdb)|*.mdb"
End If
CommonDialog1.ShowOpen
strSourcePath = CommonDialog1.FileName
Label1.Caption = strSourcePath
Set f = objet_fso.GetFile(strSourcePath)
Label3.Caption = Format(f.Size / 1024, "### ### Ko")
btnCompacter.Enabled = Len(strSourcePath) <> 0
End Sub
Private Sub btnCompacter_Click()
If Option1 Then
strDestPath = Replace(strSourcePath, ".accdb", "_compacted.accdb")
ElseIf Option2 Then
strDestPath = Replace(strSourcePath, ".mdb", "_compacted.mdb")
End If
If objet_fso.FileExists(strDestPath) Then
Dim Effacer As VbMsgBoxResult
Effacer = MsgBox("Le fichier compacté " & s & " existe déjà. Voulez-vous le remplacer ?", vbYesNo + vbDefaultButton2)
If Effacer = vbNo Then Exit Sub
Kill strDestPath
End If
Label2.Caption = strDestPath
DBEngine.CompactDatabase strSourcePath, strDestPath
Set f = objet_fso.GetFile(strDestPath)
Label4.Caption = Format(f.Size / 1024, "### ### Ko")
MsgBox ("Compactage terminé avec succès")
End Sub
Private Sub Form_Load()
Set objet_fso = CreateObject("Scripting.FileSystemObject")
End Sub
Ce code fonctionne parfaitement et compacte toutes les bases ACCESS sans avoir intégré la référence à DAO
AccessVersion Build Version ProjVer
MDB 07.53 5903 3.0 Standard Jet DB
ACCDB 08.50 6620 4.0 Standard Jet DB
ACCDB 08.50 266 4.0 140 Standard Jet DB
ACCDB 09.50 12.0 140 Standard ACE DB
J'ai tenté de créer un projet similaire en VB.NET :
Références du fichier VBPROJ :
........................................
COMReference Include="Microsoft.Office.Interop.Access.Dao">
<Guid>{4AC9E1DA-5BAD-4AC7-86E3-24F4CDCECA28}</Guid> (identique à celle de VB6 : Reference=*\G{4AC9E1DA-5BAD-4AC7-86E3-24F4CDCECA28})
<VersionMajor>12</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
........................................
Code de la Form :
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.IO
Imports DAO
Public Class Form1
Dim infoReader As System.IO.FileInfo
Dim strSourcePath As String = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
OpenFileDialog1.Filter = "Base ACCESS 2010 (*.accdb)|*.accdb" ' activer pour access 2010
'OpenFileDialog1.Filter = "Base ACCESS 97 (*.mdb)|*.mdb" ' activer pour access 97
OpenFileDialog1.ShowDialog()
Label1.Text = OpenFileDialog1.FileName
strSourcePath = Label1.Text
infoReader = My.Computer.FileSystem.GetFileInfo(strSourcePath)
Dim SizeBefore As Double = infoReader.Length
Label4.Text = Format(SizeBefore / 1024, "### ### Ko")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim DBE As New DBEngine
Dim strDestPath As String = Replace(Label1.Text, ".accdb", "_new.accdb") ' activer pour access 2010
'Dim strDestPath As String = Replace(Label1.Text, ".mdb", "_new.mdb") ' activer pour access 97
infoReader = My.Computer.FileSystem.GetFileInfo(strDestPath)
If infoReader.Exists Then Kill(strDestPath)
DBE.CompactDatabase(strSourcePath, strDestPath)
infoReader = My.Computer.FileSystem.GetFileInfo(strDestPath)
Dim SizeAfter As Double = infoReader.Length
Label5.Text = Format(SizeAfter / 1024, "### ### Ko")
MsgBox("Compactage terminé")
End Sub
End Class
Ce code fonctionne et compacte les bases ACCESS après avoir intégré la référence à DAO
AccessVersion Build Version ProjVer
MDB 07.53 5903 3.0 Standard Jet DB
ACCDB 08.50 6620 4.0 Standard Jet DB
ACCDB 08.50 266 4.0 140 Standard Jet DB
Mais il renvoie une erreur pour les bases ACCESS
ACCDB 09.50 12.0 140 Standard ACE DB
Je suis donc toujours à la recherche d'une solution pour les bases ACCESS 2016
Merci d'avance
--