How to Display Immediate Window Without Module Window  

Summary:

Access version 1.0 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 browse mode of a form. By
calling two Windows API functions from Access Basic, the Immediate
window can be displayed at any time, even without the Module window
visible.

More Information:

To display the Immediate window at any time, you will 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, a SendKeys action in the Autokeys
macro, or add it to your Toolbar.

To display the Immediate window, do the following:

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

2. Add the following declarations to the Global section of the module:
   (You must include each declaration on a separate line.)

   Option Explicit
   Declare Function ShowWindow% Lib "user" (ByVal hWnd%, ByVal nCmd%)
   Declare Function FindWindow% Lib "user" (ByVal lpClassName 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)

      'Note that the MsgBox function must be on one line.
      If IhWnd% = 0 Then MsgBox _
                  ("You need to open the IW once for this to work.")

      ApiResults% = ShowWindow(IhWnd%, SW_SHOW)
   End Function

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

5. When you first start Access, the Immediate window is not displayed.
   When you open a module and display the Immediate window then close
   it, Access sets the window's Visible property to False. Calling
   ShowWindow will reset the Visible property to True. If you call
   this function without first displaying the Immediate window at
   least once, you will receive the error message, because Access has
   not created the Immediate window yet, and thus cannot return a
   window handle.
   
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
   browse mode will display the Immediate window. Any Debug.Print
   statements will now be visible.

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

