I have many databases with Front-End (Forms, reports, modules) and Back-End (Tables) design. All tables in the Front-End are linked to the Back-End. What I've tried to do is use this code to "Compact and Repair" the Back-End database, but receive the following error message: "You attempted to open a database that is already opened exclusively by user 'Admin' on machine 'xxxxxx'. Try again when the database is available."
Any ideas on how to correct the code to allow me to compact the active "Back-End" database from a command button on the "Front-End" database?
****************************************************
Function CompactBackend()
Dim je As New JRO.JetEngine
Dim mNewPath As String
Dim mPath As String
Dim strPath As String
strPath = Forms![MainMenu]![Database Location]
'Change the database name to point to your database.
'Give a new name to the destination database, mNewPath preferably "OLDNAME_New.mdb"
'The mNewPath should not necessarily exist, but should becreated after the first
'sucessfull compact
mNewPath = strPath & "\Testq_New.mdb" 'New as a result of compact
mPath = strPath & "\Server Config Files Tables.mdb" 'Original Database
If Len(Dir(mNewPath)) Then ' Test to see if the database exist from
MsgBox " Hello new database from Compact exist! Deleting it"
Kill mNewPath
End If
If Len(Dir(mPath)) Then ' Test to see if the database exist from
MsgBox "You have the original database"
End If
MsgBox "Compacting database"
je.CompactDatabase SourceConnection:="Data Source= " & mPath, _
DestConnection:="Data Source= " & mNewPath & ";" & _
"Jet OLEDB:Encrypt Database=True"
MsgBox "Done Compacting database"
If Len(Dir(mPath)) Then ' Test to see if the database exist from
MsgBox "I am deleting the original database and copy the new to it"
Kill mPath
End If
If Len(Dir(mNewPath)) Then ' Test to see if the database exist from
MsgBox "New from Compact Say Hello"
End If
MsgBox "Copying file from new to original"
FileCopy mNewPath, mPath
End Function
Any ideas on how to correct the code to allow me to compact the active "Back-End" database from a command button on the "Front-End" database?
****************************************************
Function CompactBackend()
Dim je As New JRO.JetEngine
Dim mNewPath As String
Dim mPath As String
Dim strPath As String
strPath = Forms![MainMenu]![Database Location]
'Change the database name to point to your database.
'Give a new name to the destination database, mNewPath preferably "OLDNAME_New.mdb"
'The mNewPath should not necessarily exist, but should becreated after the first
'sucessfull compact
mNewPath = strPath & "\Testq_New.mdb" 'New as a result of compact
mPath = strPath & "\Server Config Files Tables.mdb" 'Original Database
If Len(Dir(mNewPath)) Then ' Test to see if the database exist from
MsgBox " Hello new database from Compact exist! Deleting it"
Kill mNewPath
End If
If Len(Dir(mPath)) Then ' Test to see if the database exist from
MsgBox "You have the original database"
End If
MsgBox "Compacting database"
je.CompactDatabase SourceConnection:="Data Source= " & mPath, _
DestConnection:="Data Source= " & mNewPath & ";" & _
"Jet OLEDB:Encrypt Database=True"
MsgBox "Done Compacting database"
If Len(Dir(mPath)) Then ' Test to see if the database exist from
MsgBox "I am deleting the original database and copy the new to it"
Kill mPath
End If
If Len(Dir(mNewPath)) Then ' Test to see if the database exist from
MsgBox "New from Compact Say Hello"
End If
MsgBox "Copying file from new to original"
FileCopy mNewPath, mPath
End Function