[AccessD] Database window

Stuart McLachlan stuart at lexacorp.com.pg
Wed Mar 2 15:19:56 CST 2011


The simple way is  to select an object in the database window first and then hide the window 
when it becomes active.

DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide

The disadvantage of this is that it "flashes"  the database window on top of everything.

The better way is to paste the following code into a module and call "ShowDbWindow False":

Option Compare Database
Option Explicit

Private Declare Function GetClassNameA Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) _
    As Long
Private Declare Function GetWindow Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal wCmd As Long) _
    As Long
Private Declare Function ShowWindowAsync Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal nCmdShow As Long) _
    As Boolean

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Const SW_HIDE = 0
Private Const SW_SHOW = 5

Private Function GetClassName( _
    ByVal hwnd As Long) _
    As String

    Dim lpClassName As String
    Dim lLen As Long

    lpClassName = String(255, 32)
    lLen = GetClassNameA(hwnd, lpClassName, 255)
    If lLen > 0 Then
        GetClassName = Left(lpClassName, lLen)
    End If

End Function

Public Sub ShowDbWindow(ByVal bCmdShow As Boolean)

Dim hWndApp As Long

hWndApp = GetWindow(Application.hWndAccessApp, GW_CHILD)
Do Until hWndApp = 0
    If GetClassName(hWndApp) = "MDIClient" Then
        Exit Do
    End If
    hWndApp = GetWindow(hWndApp, GW_HWNDNEXT)
Loop

If hWndApp > 0 Then
    hWndApp = GetWindow(hWndApp, GW_CHILD)
    Do Until hWndApp = 0
        If GetClassName(hWndApp) = "ODb" Then
            Exit Do
        End If
        hWndApp = GetWindow(hWndApp, GW_HWNDNEXT)
    Loop
End If

If hWndApp > 0 Then
    ShowWindowAsync hWndApp, IIf(bCmdShow, SW_SHOW, SW_HIDE)
End If

End Sub




 


On 2 Mar 2011 at 15:39, Ralf Lister wrote:

> Hello to all of you,
> 
> 
> 
> How do I hide the database window using code?
> 
> 
> 
> TIA and Saludos
> 
> Actuary Ralf Lister
> 
> La Paz, Bolivia
> 
> Registrado en ASFI
> 
> No. Registro: Act.Mat. 001
> 
> NIT: 1016725022
> 
> Skype Name: ralf.martin.lister
> 
> Tel.: 222 26 61, Cel. 70136531
> 
> rlister at actuarial-files.com
> 
> www.actuarial-files.com
> 
> Environment
> 
> 
> 
> 






More information about the AccessD mailing list