ACC: How to Make the Immediate Window Available at All Times

Last reviewed: August 6, 1997
Article ID: Q88925
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

Microsoft Access versions 1.x and 2.0 have a debugging tool called the Immediate window that enables you debug Access Basic code. By using the Immediate window, you can try out an expression to see if it returns the expected value (or any value at all); you can debug macros; you can debug procedures, and so on. However, in the Microsoft Access versions 1.x and 2.0 user interface, the Immediate window is only available when a module window is selected.

This article shows you how you can use a macro to make the Immediate window available at all times.

For an overview of how to use the Immediate window, see the "Overview of the Immediate Window" section below. For instructions on how to create the macro to make the Immediate Window available at all times, see "Making the Immediate Window Available at All Times" section below.

NOTE: In Microsoft Access for Windows 95 version 7.0, the Immediate window is called the Debug window. The Debug Window in Microsoft Access 7.0 is available at all times even without a module open. To open the Debug Window in Microsoft Access 7.0, press CTRL+G.

MORE INFORMATION

Overview of the Immediate Window

You can type an expression in the Immediate window and see the results of that expression, without having to write and run an Access Basic procedure. To run an expression in the Immediate window, use the Access Basic "?" command (without the quotation marks) as demonstrated below:

   ? 2 + 2

When you type this statement in the Immediate window and press ENTER, Microsoft Access displays the number 4 just below the expression.

Another example of using the Immediate window is to set the value of a variable or to test for the value of a variable. For example, to set the value of a variable and then to test for the value of the variable, type the following lines in the Immediate window:

   MyVar = 2
   ? MyVar

The "?" statement returns the number 2 because that is the value you assigned to the variable MyVar.

The Immediate window is helpful for debugging Access Basic code because you can suspend execution of the procedure and set the values of variables in the procedure to see what kind of result you would receive with different values. You can also use the Immediate window to suspend a procedure and check for the value of a variable or expression to see if it is calculating as you expect it to.

In the same way that an Immediate window can be helpful for debugging code, it can also be helpful for other tasks, such as:

  • Trying out a form expression such as Forms!MyForm!MyControl to see if it returns a value.
  • Trying out a query expression, such as a DSum().
  • Trying out a macro action with the DoCmd command to see if the macro action produces the desired results.

Making the Immediate Window Available at All Times

You can make the Immediate window available at all times by following these steps:

  1. In the database window, choose Macro.

  2. If you already have a macro called AutoKeys, open it in Design view. Otherwise, choose New.

  3. If the Macro Name column does not appear in the macro sheet, choose Macro Names from the View menu.

  4. If the Condition column does not appear in the macro sheet, choose Conditions from the View menu.

  5. Add the following action and its corresponding property:

        Macro name    Condition                                  Action
        --------------------------------------------------------------------
        ^I                                                       SendKeys
                                                                 DoMenuItem
                                                                 SendKeys
                     MsgBox ("IW already on the screen?",4)=7    DoMenuItem
    
        SendKeys Actions
        -----------------
        KeyStrokes: {F11}
        Wait:       Yes
    
        DoMenuItem Action
        -------------------
        Menu Bar:  Database
        Menu Name: View
        Command:   Modules
    
        SendKeys Actions
        ----------------
        KeyStrokes: %N
        Wait:       Yes
    
        DoMenuItem Actions
        ---------------------------
        Menu Bar:  Module
        Menu Name: View
        Command:   Immediate Window
    
    

  6. Save and then close the macro. If the macro is not already called AutoKeys, save it with that name.

From this point on, you can press CTRL+I to activate the Immediate window. Follow these steps for an example of how this works:

  1. Open any form in Design view.

  2. Press CTRL+I. A new module window is opened. You must close each instance yourself.

    After some screen activity, a prompt appears asking if the Immediate window is already on the screen. If you do not see the Immediate window on the screen, choose No. Doing so causes the macro to execute one extra step that would otherwise not be necessary.

    Note that a small module window appears. The Immediate window is now available to use.

  3. Click once on the form design window or on the Database window. Note that the Immediate window disappears.

  4. Click once on the module window mentioned in step 2. Note that the Immediate window reappears.

You should only need to use CTRL+I once to make the Immediate window and the shrunken module window appear. Every subsequent request for the Immediate window can be made by clicking once on the module window. If the module window is closed, press CTRL+I to bring up the Immediate window again.
Keywords          : McrHowto kbprg kbusage PgmOthr
Version           : 1.0 1.1 2.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 6, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.