Microsoft KB Archive/89594

= ACC: How to Display Immediate Window Without Module Window =

Article ID: 89594

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 Q89594



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

Microsoft Access does not display the Immediate window unless the Module window is visible. This can be a problem if the user wants to print to the Immediate window while in Datasheet view of a form. By calling two Windows application programming interface (API) functions from Access Basic, the Immediate window can be displayed at any time, even without the Module window visible.

NOTE: In Microsoft Access for Windows 95 version 7.0 you no longer have to have a module open to display the Debug window. The Debug window can be brought up anytime in an active database by pressing CTRL+G.



MORE INFORMATION
To display the Immediate window at any time, you need to call the FindWindow API function to get the handle to the Immediate window, and then call the ShowWindow API function to make the actual window visible. You can attach the Access Basic function that includes these API functions to a command button or a RunCode action in the Autokeys macro, or you can add it to your toolbar.

To display the Immediate window, follow these steps:

 Create a new module, or open an existing module.  Add the following declarations to the Global section of the module.

NOTE: In the following 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.

Option Explicit

Declare Function ShowWindow% Lib &quot;user&quot; (ByVal hWnd%, ByVal nCmd%) Declare Function FindWindow% Lib &quot;user&quot; (ByVal lpClassName As Any, _     ByVal lpWindowName As Any)   Add the following ShowImmediateWindow function:

Function ShowImmediateWindow Dim IhWnd%               ' Handle to the Immediate Window. Dim ApiResults%          ' Returns the previous state of IW. Const MyNull = 0& Const SW_SHOW = 5        ' Internal constant to show window. Const ClassName = &quot;OImmediate&quot;   ' Internal ClassName of IW.

IhWnd% = FindWindow(ClassName, MyNull)

If IhWnd% = 0 Then MsgBox (&quot;You need to open the IW once for this to work.&quot;) End If

ApiResults% = ShowWindow(IhWnd%, SW_SHOW) End Function  Attach the code to a command button of a form. When you first start Microsoft Access, the Immediate window is not displayed. When you open a module and display the Immediate window, and then close it, Microsoft Access sets the window's Visible property to False. Calling ShowWindow resets the Visible property to True. If you call this function without first displaying the Immediate window at least once, you receive an error message because Microsoft Access has not created the Immediate window yet and therefore cannot return a window handle.

For information about displaying the Immediate window without displaying the Module window, see the following article the Microsoft Knowledge Base:

89594 ACC: How to Display Immediate Window Without Module Window

With the information in the article referenced above, you can open the Immediate window with macros once, and then use the code from this article to display the Immediate window at any time. If you have registered the Immediate window with Windows by opening it at least once, pressing the command button of the form while in Datasheet view displays the Immediate window. Any Debug.Print statements should then be visible.</ol>

NOTE: This is unsupported code, and there may be instances when this example does not work.

Keywords: kbhowto kbprogramming KB89594

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.