I am a professional Access developer and am working with another colleage on large Access project. Te ease communications and code sharing we have developed as system where each developer has an mdb to deposit new code into for the other person to import into their copy of the application. I have developed a form-driven function to import objects from the other persons repository, and that part works find. What I have not been able to do is delete the objects from the remote repository after import. I get the message "Microsoft Access can't save design changes or save to a new database object because another user has the file open. To save your design changes or to save to a new object, you must have exclusive access to the file."
I know I have exclusive access to the file, so that is not the issue. Somehow I cannot get Access to recognize exclusive access even though I am wrapping both the copy and delete operations in Application objects. Anyone have any ideas?
Code is below.
Private Sub cmdImportSelectedObjects_Click()
Dim varOBJ As Variant
Dim Exp As String
Exp = ExportDestination
Dim Parts(1) As String
Dim oType As AcObjectType
Dim MType As Long
Dim itExists As Boolean
Dim strCopied() As String
Dim strSQL As String
Dim LongX As Long
Dim Prompt As Integer
Dim varx As Variant
Dim TOID As Variant
Dim HaveRecord As Boolean
Dim objAccCopy As New Access.Application
Dim objAccDelete As New Access.Application
Const tblTO = "tblTurnedOverDoc"
On Error GoTo ErrTrap
objAccCopy.OpenCurrentDatabase AltReportSource, True
For Each varx In Me!lstExport.ItemsSelected
ResumeLoop:
Parts(0) = Me!lstExport.Column(0, varx)
Parts(1) = Me!lstExport.Column(1, varx)
Typer Parts(0), oType, MType
'Unload object if it is loaded
If ObjectExists(Parts(1), oType) Then
If IsObjectLoaded(Parts(1), oType) Then
DoCmd.Close oType, Parts(1)
End If
'Check if backup exists
If ObjectExists("Old" & Parts(1), oType) Then
DoCmd.DeleteObject oType, "old" & Parts(1)
End If
DoCmd.Rename "Old" & Parts(1), oType, Parts(1)
End If
DoCmd.TransferDatabase acImport, "Microsoft Access", AltReportSource, oType, Parts(1), Parts(1)
Next
'Cannot seem to get exclusive access to remote database to delete files
objAccCopy.CloseCurrentDatabase
Set objAccCopy = Nothing
objAccDelete.OpenCurrentDatabase AltReportSource, True
For Each varx In Me!lstExport.ItemsSelected
Parts(0) = Me!lstExport.Column(0, varx)
Parts(1) = Me!lstExport.Column(1, varx)
Typer Parts(0), oType, MType
objAccDelete.DoCmd.DeleteObject oType, Parts(1)
arrPush strCopied, Parts(1)
Next
objAccDelete.Quit
Set objAccDelete = Nothing
MsgBox "Successfully copied " & Join(strCopied, Comma) & " from " & AltReportSource, vbOKOnly, "Copy Successful"
Me!lstExport.Visible = False
Me!cmdExport.Enabled = False
Me!lstExport.Visible = False
Me!Procedure.Enabled = True
Me!cmdSave.Enabled = True
ClearFields
ExitMe:
Exit Sub
ErrTrap:
Prompt = MsgBox("Error copying " & Parts(1) & " to " & ExportDestination & ". What do you want try the next item?", vbYesNoCancel)
If Prompt = vbYes Then
i = i + 1
Resume ResumeLoop
Else
Resume ExitMe
End If
End Sub