ACC1x: Form Handle Not Released When Closed with Access BasicID: Q95644
|
After closing a form (using the Close macro action) that was opened through
Access Basic code, the file handle for the table that the form is based on
is not released. Because the file handle is not released, no functions that
require exclusive use on that table can be executed (for example, deleting
the table). When a function that needs exclusive use of that table is
executed, the following error will occur:
Couldn't lock table '<tablename>'; currently in use.
You are not guaranteed that the user interface (UI) will be synchronized with the underlying Microsoft Access code in all cases. In this case, the record locking is done behind the scenes. Microsoft Access releases the table when it hits its idle loop (that is, the UI optimization).
After the form is opened in Access Basic code, insert a DoEvents command before the function that needs exclusive use of the table, to cause Microsoft Access to yield execution to the operating system, so that it can process events. When the DoEvents command occurs it allows Microsoft Access to process the pending unlock sequence.
This behavior no longer occurs in Microsoft Access version 2.0.
The following steps provide example code that reproduces this error. There is a comment in the Access Basic code identifying where to insert a DoEvents command to resolve this error.
'*************************************************************
'Declarations section of the module.
'*************************************************************
Option Explicit
'================================================================
' Create and save the following TempCust() function in the Module
'================================================================
Function TempCust()
DoCmd SelectObject a_table, "Customers", True
DoCmd CopyObject , "Cust2"
DoCmd OpenForm "Customers 2", a_normal, "", "", a_edit, a_dialog
'**** This is where the DoEvents should be inserted to fix ****
DoCmd SelectObject a_table, "Cust2", True
DoCmd DoMenuItem 1, 1, 4
End Function
Object: Command Button
-----------------------
ControlName: Close Form
Caption: Close Form
OnPush: ExitForm
Macro Name Action
-------------------
ExitForm Close
Macro Name Action Argument
------------------------------------
OpenCustForm RunCode TempCust()
Delete Table 'Cust2'?
Couldn't lock table 'Cust2'; currently in use.
Keywords : kbprg PgmErr
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: March 19, 1999