Microsoft KB Archive/88171

= ACC: Using SetSysModalWindow API Call in Access Basic =

Article ID: 88171

Article Last Modified on 5/9/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q88171



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

In Microsoft Access Basic, you can make an application modal so that users cannot switch to other Windows-based programs while the Microsoft Access application is active. This functionality is achieved with the following Windows application program interface (API) functions:

  SetSysModalWindow

-and-

  FindWindow

This article discusses the use of the SetSysModalWindow API function and provides an example of its use in Access Basic.

NOTE: The SetSysModalWindow API function is not supported under Win32. As a result, you cannot use this function with Microsoft Access for Windows 95 version 7.0.



MORE INFORMATION
Microsoft Windows is designed so that the user can switch between applications without terminating one program to run another. There may be times, however, when a Microsoft Access application needs to restrict the user from switching to another application. Examples of this are a security system or time-critical application that needs to run uninterruptedly.

SetSysModalWindow Function Usage Notes
Consider all of the following usage notes before making a window system-modal:


 * 1) If an application passes the handle of the window as an argument to the SetSysModalWindow function, the user is limited to that window. This prevents the user from moving to other applications or bringing up the Task List (either with the mouse or by pressing CTRL+ESC).
 * 2) If an application uses the SetSysModalWindow function in conjunction with the GetSystemMenu function, the Control (system) menu is disabled and the user is prevented from quitting Windows by pressing ALT+F4.
 * 3) A window that is system-modal cannot be minimized, maximized, moved, or sized. Microsoft Access Help is created with a separate Windows Help file; therefore, help windows created with the Windows Help Compiler are not available to the user.
 * 4) When an application uses the SetSysModalWindow API function, the system-modal window must be closed before other applications or windows can be accessed. Therefore, when using this function, be sure that the application has a means to exit Microsoft Access.
 * 5) Any child window that is created by a system-modal window becomes a system-modal window. For example, if Microsoft Access is system- modal and a form is opened, that form becomes system-modal until it is closed.

How to Use the SetSysModalWindow Function
To use the SetSysModalWindow API function within Access Basic, create the sample code below.

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

  Type the following lines in the Declarations section:

Option Explicit

Declare Function SetSysModalWindow% Lib &quot;User&quot; ( _                     ByVal hwnd%)

Declare Function FindWindow% Lib &quot;User&quot; (_                     ByVal lpszClassName As Any, _                      ByVal lpszWindow As Any)   Type the following procedure:

Function System_Modal_Test

Const lpClassName = &quot;OMain&quot; ' Declares the class name constant used in       ' the FindWindow API function.

Dim AccessHandle Dim Success As Integer

' The FindWindow functions returns the handle for Microsoft ' Access. AccessHandle = FindWindow(lpClassName, 0&) 'Note this is a zero

' The handle for Microsoft Access is sent; then, Microsoft Access ' becomes modal. Success = SetSysModalWindow(AccessHandle)

End Function  Save the module as Modal Access, and then choose the OK button. From the Run menu, choose Compile All. Type the following line in the Immediate window, and then press ENTER:

?System_Modal_Test </ol>

After running the program, test the modal functionality by trying to select other windows or resize or move the system-modal window.

<div class="references_section">