Microsoft KB Archive/160875

= ACC97: TransferDatabase Causes Page Fault If Object Exists =

Article ID: 160875

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q160875



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use TransferDatabase to copy an object to a target database, you may receive the following error message if the target database already contains the same type of object with the same name:

Object invalid or no longer set.

That message is followed by an invalid page fault which causes Microsoft Access to shut down:

MSACCESS caused an invalid page fault in module MSJET35.DLL

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.



RESOLUTION
To work around the error, test for the existence of the object in the target database and delete it before you use TransferDatabase, as in the following example:  Create a copy of the sample database Northwind.mdb as Northwind2.mdb. Open the sample database Northwind.mdb.  Create a module and type the following procedure: Public Function TransferObject(Filename As String, _                                    objType As Integer, _                                     objName As String) On Error GoTo TransferObject_Err Dim 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: Type the full path and file name for Northwind2.mdb as the first parameter in the following function. ?TransferObject("Northwind2.mdb", acForm, "Orders") Note that when the transfer is complete, you receive the message:

Transferred Object: Orders to database file Northwind2.mdb



<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in Microsoft Access 97.

<div class="moreinformation_section">

Using a Visual Basic Procedure
WARNING: Following these steps will cause an invalid page fault on your computer. Make sure you save and close any open work on your computer before following these steps.

 Create a copy of the sample database Northwind.mdb as Northwind2.mdb.</li> Open the sample database Northwind.mdb.</li>  Create a module and type the following procedure.

NOTE: Type the full path and file name for Northwind2.mdb in the Database Name argument of the TransferDatabase method in this example. Function XferError DoCmd.TransferDatabase acExport, "Microsoft Access", _ "Northwind2.mdb", acForm, "Orders", "Orders", False End Function </li> Save the module as Module1 and close it.</li> To test this function, type the following line in the Debug window, and then press ENTER:

?XferError

Note that you may have to execute the function twice to produce the invalid page fault error.</li></ol>

Using a Macro
WARNING: Following these steps will cause an invalid page fault on your computer. Make sure you save and close any open work on your computer before following these steps.  Create a copy of the sample database Northwind.mdb as Northwind2.mdb.</li> Open the sample database Northwind.mdb.</li>  Create the following new macro.

NOTE: Type the full path and file name for Northwind2.mdb in the Database Name argument of the TransferDatabase action in this example. <pre class="fixed_text">     Macro: XferError       Action --                           TransferDatabase

XferError Actions --     TransferDatabase Transfer Type: Export Database Type: Microsoft Access Database Name: Northwind2.mdb Object Type: Form Source: Orders Destination: Orders Structure Only: No                   </li> Save the XferError macro and close it.</li> Run the macro. You may need to run the macro twice to produce the following error message:

Object Invalid or no longer set.

When you click OK in response to the error message, you receive the invalid page fault error.</li></ol>

<div class="references_section">