I have the following code that compacts and repairs an access table from vb.

Public Sub MaintainDataFile(MDBfilename)
'init
Dim vJet As New JRO.JetEngine
Dim vBak As String
Dim vBackup As String
Dim vSource As String

'if bak exists, kill it
vBak = Left(MDBfilename, InStr(MDBfilename, ".")) & "bak"
If CBool(Len(Dir(vBak))) Then Kill vBak

'compact/repair & backup
vSource = "Data Source=" & MDBfilename
vBackup = "Data Source=" & vBak

vJet.CompactDatabase vSource, vBackup
Kill MDBfilename
Name vBak As MDBfilename
End Sub

When I try this code from within the Access program, I get the error message that says the database has been placed in a state by user 'Admin' that prevents it from being opened or locked.

Is there a way to use code to compact and repair an access database from within that Access program?

Thanks