Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compacting a back end DB using JRO. 1

Status
Not open for further replies.

Phooey

Programmer
Feb 14, 2000
111
GB
I have an Access2000 database developed using ADO and I'm trying to compact the database using code.&nbsp;&nbsp;The database has been split and it's the Back end which I'm trying to compact on exit.&nbsp;&nbsp;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 = &quot;'W:\Sep_Reps\SEPData.mdb'&quot;<br>strDestDB = &quot;'W:\Sep_Reps\SEPOld.mdb'&quot;<br><br>strSourceConnect = &quot;Data Source=&quot; & strSourceDB<br>strDestConnect = &quot;Data Source=&quot; & strDestDB & &quot;;&quot; & _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;Jet OLEDB:Encrypt Database=False&quot;<br><br>Set jetengine = New JRO.jetengine<br>Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br><br>'Compact the database specified by the strSourceDB<br>'to the name and path specified by strDestDB<br>If fs.FileExists(&quot;W:\Sep_Reps\SEPOld.mdb&quot;) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;fs.DeleteFile (&quot;W:\Sep_Reps\SEPOld.mdb&quot;)<br>End If<br>jetengine.CompactDatabase strSourceConnect, strDestConnect<br><br>fs.copyfile &quot;W:\Sep_Reps\SEPOld.mdb&quot;, &quot;W:\Sep_Reps\SEPData.mdb&quot;, True<br><br>Set jetengine = Nothing<br>Set fs = Nothing<br><br>End Function<br></font><br><br>Any help would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top