VBA Immediate Window Line and Character Limits

Don't take my word for it (or anyone else's on the internet, for that matter). Prove the limits to yourself with some simple VBA.

VBA Immediate Window Line and Character Limits

Did you ever wonder how many characters would fit on a single line in the Immediate Window?  Or how many lines would display before the first ones got chopped off?  Well wonder no more!

tl;dr: 200 Lines of 1,023 Characters

The immediate window will display a maximum of 200 lines of text.

Each line will display a maximum of 1,023 characters before wrapping around to the next line.

But don't take my word for it!  Use the code below to test it for yourself.

Testing the Character Limit

This is easy to do from the immediate window itself using the String() function:

Testing the Line Limit

We'll do this with a standalone subroutine:

Public Sub ImmediateWindowLineTest()
    Const MaxLines As Long = 200
    Dim i As Long
    For i = 1 To MaxLines
        If i < MaxLines Then
            Debug.Print i
            'trailing semi-colon prevents the automatic line break
            '   from being added on the last trip through the loop
            Debug.Print i;   
        End If
    Next i
End Sub

IMPORTANT: Be sure to clear the immediate window before running the above subroutine.  There's no reliable way to do that in code in Access, so just do it manually with a:

  • [Ctrl] + [G]: Go to immediate window
  • [Ctrl] + [A]: Select all
  • [Delete]: Umm...delete

After executing the ImmediateWindowLineTest() routine, scroll up to the top of the immediate window.  You will see the first line is "1".

Now scroll to the bottom of the immediate window.  Notice that the cursor is blinking on an empty line below the number 200.

If you begin typing on that line–even something as simple as pressing the space bar–that now becomes the 200th line of text.  Scroll back up to the top of the immediate window and you will see that the top line is now "2".

Tip o' the Hat to Access MVP Adrian Bell

His conversation with fellow Access MVP Crystal Long in the LinkedIn comments section got me thinking this would be a good article to write along with some verifiable test code.

Here's Adrian's original comment:

[I]t's actually 200 lines.  Each line can take up to 1,023 characters. Shorter lines have no effect on the total number of lines.
So, 204,600 characters is an absolute maximum but this can only be achieved with all lines (including the last with no CR LF added) filled to the max of 1,023.  Anything after that causes the first line to scroll out of the pane.
- Adrian Bell

Image by jplenio from Pixabay

All original code samples by Mike Wolfe are licensed under CC BY 4.0