Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    619

    Clear the immediate window in VBA

    I ran across several sites that propose this solution (mostly for Excel) to clear the immediate window:

    Code:
    Application.SendKeys "^g ^a {DEL}"
    However, when I try to compile the line I get: Method or data member not found.



    Why doesn't this work, and how?

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,637
    I never use send keys so couldn't tell ya.

    Since the immediate window is limited to a couple hundred lines

    Code:
        Dim i As Integer
        For i = 0 To 200
            Debug.Print ""
        Next i
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    619
    Quote Originally Posted by moke123 View Post
    I never use send keys so couldn't tell ya.

    Since the immediate window is limited to a couple hundred lines

    Code:
        Dim i As Integer
        For i = 0 To 200
            Debug.Print ""
        Next i
    I'll have to try that again, if I recall correctly, it left the cursor way down there, so then we need a trick to get it back to the top.

    There have been other situations where I wanted to use .SendKeys, so I would like to know how to get it to work in Access.

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    619
    If someone else is in the same boat someday, this video might help:
    https://youtu.be/qc-7uYr7kHE

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    2,991
    If you have MZ-tools there is a command button for that.
    Very useful.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    Personally, I avoid any solution based on SendKeys as these are notoriously unreliable, particularly after version changes.

    As well as the excellent MZ Tools, there is also a free utility IDBE Tools 2010 which includes a feature to clear the Immediate window: https://www.avenius.de/en/
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,773
    Quote Originally Posted by isladogs View Post
    Personally, I avoid any solution based on SendKeys as these are notoriously unreliable, particularly after version changes.

    As well as the excellent MZ Tools, there is also a free utility IDBE Tools 2010 which includes a feature to clear the Immediate window: https://www.avenius.de/en/
    Colin,
    I just downloaded the 32bit version and tried to run it and AVG reported as below?
    Attached Thumbnails Attached Thumbnails IDE.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,637
    While poking around to see if there is a way to do it with VBA extensibility, I noted a post from Chip Pearson basically saying he has tried everything and using send keys is the only way.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    Hi Paul
    I've used IDBE Tools 2010 for about 10 years. Its perfectly safe. The author Gunter Avenius is totally trustworthy and has several useful tools on his website.
    However, I just re-downloaded and installed the 64-bit version on my tablet and noticed it got smart screen warnings using MS Edge browser.
    For more info, see my article Smart Screen Warnings (isladogs.co.uk)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    @moke123
    The VBIDE library does include this item vbext_wt_Immediate.
    However I haven't tried to use it as I already have 2 tools to do the job
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,773
    Quote Originally Posted by isladogs View Post
    Hi Paul
    I've used IDBE Tools 2010 for about 10 years. Its perfectly safe. The author Gunter Avenius is totally trustworthy and has several useful tools on his website.
    However, I just re-downloaded and installed the 64-bit version on my tablet and noticed it got smart screen warnings using MS Edge browser.
    For more info, see my article Smart Screen Warnings (isladogs.co.uk)
    I would expect that if you recommended that program, however.... I extracted the 32bit version and submitted it to Jotti.
    One AV found something?
    Attached Thumbnails Attached Thumbnails Jotti.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    Never heard of Jotti but it looks useful

    Hopefully a false flag or it would be picked up by most/all AV programs.
    Its happened to my own software as well but was quickly resolved.

    Would you mind sending these screenshots to Gunter Avenius so he can follow up
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,773
    Quote Originally Posted by isladogs View Post
    Never heard of Jotti but it looks useful

    Hopefully a false flag or it would be picked up by most/all AV programs.
    Its happened to my own software as well but was quickly resolved.

    Would you mind sending these screenshots to Gunter Avenius so he can follow up
    Do you have his email address that you can PM me.

    Edit: I have used the mailform and inserted links to my two posts with pictures. I also mentioned that you had asked me to alert him to this.

    Definitely something amiss, as I just used Virustotal as well and it reports from 3 AV programs? One of them is the same Avast from Jotti, plus my AV program AVG.
    Attached Thumbnails Attached Thumbnails VirusTotal.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    I do have his email but see whether he responds to the contact already made.
    AFAIK the utility is identical to that I have used for years. No idea what is flagging these warnings
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,925
    NOTE: SendKeys is not part of the Application object in Access. It belongs to VBA.Interaction

    So, if you really MUST use SendKeys then this works in Access

    Code:
    VBA.Interaction.SendKeys "^g ^a {DEL}"
    or just use
    Code:
    SendKeys "^g ^a {DEL}"
    However, here is a VBA solution by @ProfoundlyOblivious which I found at excel - Use VBA to Clear Immediate Window? - Stack Overflow
    SendKeys NOT used

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
    Private Declare PtrSafe Function FindWindowExA Lib "user32" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
    Private Declare PtrSafe Function PostMessageA Lib "user32" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
    Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
    
    
    Private Const WM_ACTIVATE As Long = &H6
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_CONTROL = &H11
    
    
    Public Sub ClearImmediateWindow()
        Dim hwndVBE As LongPtr
        Dim hwndImmediate As LongPtr
        
        hwndVBE = FindWindowA("wndclass_desked_gsk", vbNullString)
        hwndImmediate = FindWindowExA(hwndVBE, ByVal 0&, "VbaWindow", "Immediate") ' English caption
        If hwndImmediate = 0 Then hwndImmediate = FindWindowExA(hwndVBE, ByVal 0&, "VbaWindow", "Direct") ' Dutch caption
        PostMessageA hwndImmediate, WM_ACTIVATE, 1, 0&
        
        keybd_event VK_CONTROL, 0, 0, 0
        keybd_event vbKeyA, 0, 0, 0
        keybd_event vbKeyA, 0, KEYEVENTF_KEYUP, 0
        keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
       
        keybd_event vbKeyDelete, 0, 0, 0
        keybd_event vbKeyDelete, 0, KEYEVENTF_KEYUP, 0
    End Sub
    The cursor is at the top after this is run

    NOTE: for A2007 or earlier, replace LongPtr with Long and remove PtrSafe
    Last edited by isladogs; 01-30-2023 at 02:21 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2022, 06:49 PM
  2. lock immediate window to bottom of code window...???
    By Synergy.ron@gmail.com in forum Access
    Replies: 1
    Last Post: 05-14-2021, 03:45 PM
  3. Replies: 10
    Last Post: 12-05-2017, 01:14 AM
  4. Replies: 5
    Last Post: 10-29-2017, 06:46 AM
  5. Replies: 3
    Last Post: 10-23-2013, 08:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums