ACC: How to Display Immediate Window Without Module Window

ID: Q89594


The information in this article applies to:


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:

  1. Create a new module, or open an existing module.


  2. 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 "user" (ByVal hWnd%, ByVal nCmd%)
          Declare Function FindWindow% Lib "user" (ByVal lpClassName As Any, _
          ByVal lpWindowName As Any) 


  3. 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 = "OImmediate"    ' Internal ClassName of IW.
    
             IhWnd% = FindWindow(ClassName, MyNull)
    
             If IhWnd% = 0 Then
                MsgBox ("You need to open the IW once for this to work.")
             End If
    
             ApiResults% = ShowWindow(IhWnd%, SW_SHOW)
          End Function 


  4. Attach the code to a command button of a form.


  5. 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:

    Q89594 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.


  6. 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.


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


Keywords          : kbprg 
Version           : 1.0 1.1 2.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: March 9, 1999