Microsoft KB Archive/124903

= ACC2: Application Hangs Using COMMDLG.DLL =

Article ID: 124903

Article Last Modified on 11/6/2000

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q124903





SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.

An application stops responding (hangs) when you try to close it after the application displays the common Open File dialog box from COMMDLG.DLL. For example, the AreTablesAttached function in the Solutions sample application (SOLUTION.MDB) exhibits this behavior if you click anywhere outside the "Where is NWIND?" common dialog box and then try to quit the Solutions sample application or Microsoft Access without first closing the common dialog box.



CAUSE
This problem occurs when you fail to set the hWnd member of the OpenFileName structure passed to the GetOpenFileName function in COMMDLG.DLL.



RESOLUTION
Make sure that the parent window's handle is passed in the hWnd member of the OpenFileName structure. If the proper handle is passed in the structure, the common dialog box will be opened as a modal dialog box and users will not be able to close the parent window without first closing the common dialog box.



STATUS
Microsoft has confirmed this to be a problem in Microsoft Access version 2.0. This problem no longer occurs in Microsoft Access version 7.0.



Steps to Reproduce Problem
These steps assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Building Applications" manual.

WARNING: The following steps will cause Microsoft Access to hang, forcing you to restart Windows. Make sure to save and close any open work on your computer before following these steps.


 * 1) Rename the NWIND.MDB file in the ACCESS\SAMPAPPS subdirectory to NWINDX.MDB.
 * 2) Start Microsoft Access and open the Solutions sample application (SOLUTION.MDB).
 * 3) When the "Where is NWIND.MDB?" common dialog box is displayed, click outside the dialog box and then choose Exit from the File menu. Microsoft Access hangs.
 * 4) Press CTRL+ESC to open the Windows Task List. Select Microsoft Access in the Task List, and then choose End Task.
 * 5) Quit and then restart Windows.

Steps to Correct Problem in SOLUTION.MDB
 Start Microsoft Access. From the File menu, choose Open Database. In the File Name box, select SOLUTION.MDB. Press down and hold the SHIFT key while you choose the OK button.  Add the following lines to the Declarations section of the Reattach NWIND module.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

     Option Explicit Declare Function MSA_FindWindow Lib "User" Alias "FindWindow" _ (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code. </li>  Locate the GetMDBName function in the Reattach NWIND module. Change the line that reads

<pre class="fixed_text">     OFN.hwndOwner = 0

to read:

<pre class="fixed_text">     OFN.hwndOwner = MSA_FindWindow("OMain", 0&) </li> Save the module and then close it. Close SOLUTION.MDB.</li> Open SOLUTION.MDB. When the "Where is NWIND?" common dialog box is displayed, note that you cannot click outside the common dialog box. You cannot close SOLUTION.MDB or Microsoft Access until you close the common dialog box.</li></ol>

<div class="references_section">