How to Clear the Debug Window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sedrick
    New Member
    • Aug 2011
    • 43

    #1

    How to Clear the Debug Window

    Is there any good way to use VBA to clear the Immediate Window? I found this answer but it only clears down to the current cursor position. Any way to place the cursor at the end of the window and execute this code?

    Thanks!

    Code:
    Debug.Print String(256, vbCrLf)
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Clearing the Debug Window
    1. Make sure the Debug Window is Open and has the Focus
    2. Send the Cursor to the End of the Debug Window
    3. Execute your CrLfs
    4. Send the Cursor back to the ULC of the Debug Window
      Code:
      DoCmd.RunCommand acCmdDebugWindow
      
      SendKeys "^{END}", True
      
      Debug.Print String(256, vbCrLf)
      
      SendKeys "^{HOME}"

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Nice work ADezii :-) I didn't expect that to be workable, but it was. Here's another version that deletes the text rather than scrolling it off :
      Code:
      Call DoCmd.RunCommand(acCmdDebugWindow)
      SendKeys("^{HOME}^+{END} {BS}")
      I tried using ^A (Select entire contents) but that didn't work with SendKeys() (although it does from the keyboard of course).

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        1. Strictly out of curiosity, NeoPa, what made you think that it wouldn't work?
        2. Nice, condensed, more efficient, Version of my Code to Clear the Debug Window.
        3. Does the {BS} stand for Backspace or something different? (LOL)

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          @NeoPa:
          Actually
          Code:
          DoCmd.RunCommand acCmdDebugWindow
          
          SendKeys "^a"
          Will Select the entire contents of the Debug Window

          Finalized Code:
          Code:
          Call DoCmd.RunCommand(acCmdDebugWindow)
          SendKeys ("^a{BS}")
          Last edited by ADezii; Oct 12 '11, 04:59 PM. Reason: Added Finalized Code

          Comment

          • Sedrick
            New Member
            • Aug 2011
            • 43

            #6
            Thanks! I didn't know SendKeys even existed! There must be something different about Access 97 though. I can't get it to do the Control Sequences. If I do SendKeys "
            Code:
            SendKeys ("^a{BS}")
            It just puts the backspace mneumonic - "BS" - at the cursor position.

            Not a problem though. My original intent was to let the user see what was printed in the window. But I recalled that I was collecting the information anyway and could just do it in a regular form.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              You must enclose BS in Braces ({...}):
              Code:
              SendKeys ("^a{BS}")

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Originally posted by ADezii
                ADezii:
                Strictly out of curiosity, NeoPa, what made you think that it wouldn't work?
                Interesting. When I tested with "^A", as indicated by the example in the Help, it failed. Now I've tested with "^a", your version, it works fine.

                Originally posted by ADezii
                ADezii:
                Nice, condensed, more efficient, Version of my Code to Clear the Debug Window.
                Thank you. I appreciate praise from another experienced coder.
                Originally posted by ADezii
                ADezii:
                Does the {BS} stand for Backspace or something different? (LOL)
                If you check the Help page though, you'll see a whole lot of special codes in braces ({}) that you can work with. I tried using "{DEL}" and that didn't seem to work either (though it should have done according to the Help page) :-(
                Last edited by NeoPa; Oct 12 '11, 09:50 PM.

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  NeoPa:
                  I tried using "{DEL}" and that didn't seem to work either
                  Code:
                  'Will work just as well
                  Call DoCmd.RunCommand(acCmdDebugWindow)
                  SendKeys ("^a{DEL}")

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32669

                    #10
                    Well, this is just BACKSPACE! I just tried that again exactly as you had it and, what do you know, it worked fine. It seems I just need to explain what I tested before that failed, for you to find that it works after all. It's been fun testing though :-)

                    Comment

                    Working...