To solve the error, test the existence of the object in the target database and delete it before using TransferDatabase, as in the following example: Create a copy of the sample database Northwind.mdb Northwind2.mdb as amended.
Open the sample database Northwind.mdb amended.
Create a module and type the following procedure:
Code:
Public Function TransferObject (Filename As String, _
objType As Integer, _
objName As String)
On Error GoTo TransferObject_Err
Sun accObj As New Access.Application
accObj.OpenCurrentDatabase Filename
accObj.DoCmd.DeleteObject objType, objName
accObj.CloseCurrentDatabase
Set accObj = Nothing
DoCmd.TransferDatabase acExport, _
"Microsoft Access", _
Filename, _
objType, objName, objName, False
MsgBox "Transferred Object:" & objName & _
'To database file "& Filename, _
vbInformation, "Test"
TransferObject_End:
Exit Function
TransferObject_Err:
MsgBox Err.Description, vbCritical, "Test"
Resume TransferObject_End
End Function
Save the module as TestXfer and close it.
To test this function, type the following line in the Debug window, and then press ENTER.
Note: Enter the name of the path and file complete Northwind2.mdb as the first parameter of the following function. ? TransferObject ( "Northwind2.mdb" acForm, "Orders")
? TransferObject ( "Northwind2.mdb" acForm, "Orders")
Note that when the transfer is complete, the message:
Subject transferred: commands to the database file Northwind2.mdb
Bookmarks