-
1
- #1
I have an Access2000 database developed using ADO and I'm trying to compact the database using code. The database has been split and it's the Back end which I'm trying to compact on exit. So far every piece of code I've used has resulted in: <font color=red>You currently have the database open</font>.(Longer error message but you get the idea).<br><br>No forms remain open and as far as I know, there is nothing using the back end database.<br><br>I've succeeded in this using a DAO database in Access97, but sadly the same code won't work in this instance, even with the relevant references.<br><br>Here is the code that I have used
it fails during compact)<br><font color=blue>Function CompactDB()<br><br>Dim jetengine As JRO.jetengine<br>Dim fs As Object<br>Dim strSourceConnect As String<br>Dim strDestConnect As String<br>Dim strSourceDB As String<br>Dim strDestDB As String<br><br>'Build connection strings for SourceConnection and<br>'DestConnection arguments.<br>strSourceDB = "'W:\Sep_Reps\SEPData.mdb'"<br>strDestDB = "'W:\Sep_Reps\SEPOld.mdb'"<br><br>strSourceConnect = "Data Source=" & strSourceDB<br>strDestConnect = "Data Source=" & strDestDB & ";" & _<br> "Jet OLEDB:Encrypt Database=False"<br><br>Set jetengine = New JRO.jetengine<br>Set fs = CreateObject("Scripting.FileSystemObject"
<br><br>'Compact the database specified by the strSourceDB<br>'to the name and path specified by strDestDB<br>If fs.FileExists("W:\Sep_Reps\SEPOld.mdb"
Then<br> fs.DeleteFile ("W:\Sep_Reps\SEPOld.mdb"
<br>End If<br>jetengine.CompactDatabase strSourceConnect, strDestConnect<br><br>fs.copyfile "W:\Sep_Reps\SEPOld.mdb", "W:\Sep_Reps\SEPData.mdb", True<br><br>Set jetengine = Nothing<br>Set fs = Nothing<br><br>End Function<br></font><br><br>Any help would be greatly appreciated.