Home  |  About  |   Search   

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

RunCommand Constants

Terms of Use


 

API: Close the VBE window in Access 2000

Author(s)
Dev Ashish

  Programmatically close the Visual Basic Editor window in Access 2000. 

     Application.VBE.MainWindow.Visible = False

 An alternative approach would be to locate the handle to the window, and if found, send it a request to close itself.

  This code sample shows you how to implement the alternative mentioned above.

' ******** Code Start ********
'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Private Const WM_CLOSE = &H10
 
Private Declare Function apiPostMessage _
    Lib "user32" Alias "PostMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) _
    As Long
 
Private Declare Function apiFindWindow _
    Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As String) _
    As Long
 
Private Declare Function apiIsWindow _
    Lib "user32" Alias "IsWindow" _
    (ByVal hwnd As Long) _
    As Long
 
Function fCloseVBEWindow() As Boolean
' Closes the VBE window if it's currently open
'
Const VBE_CLASS = "wndclass_desked_gsk"
Dim hwnd As Long
    hwnd = apiFindWindow(VBE_CLASS, VBE.MainWindow.Caption)
    If hwnd Then
        Call apiPostMessage( _
                hwnd, _
                WM_CLOSE, _
                0, _
                ByVal 0&)
        fCloseVBEWindow = (apiIsWindow(hwnd) <> 0)
    End If
 
End Function
' ******** Code End ********	

1998-2009, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer