Hi Martin
There is no easy "built-in" way of doing this, as far as I know. I use
calls to the Windows API to do it. My code is below.
Basically, what it does is find the handle of the application's MDI window
(hWndMDI), then find the database window (hWndDb) then call the
IsWindowVisible function to return a result.
It might look a bit scary if you're not used to API programming, but it
should work if you just copy and paste it into a module. All you have to do
is call the final function:
If IsDbWindowVisible Then ...
================ start code ============================
Option Compare Database
Option Explicit
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(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 Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function IsWindowVisible Lib "user32" _
(ByVal hwnd As Long) _
As Long
Public Function hWndDb(Optional hWndApp As Long) As Long
Dim hwnd As Long
hWndDb = 0
If hWndApp <> 0 Then
If WindowClassName(hWndApp) <> "OMain" _
Then Exit Function
End If
hwnd = hWndMDI(hWndApp)
If hwnd = 0 Then Exit Function
hwnd = GetWindow(hwnd, GW_CHILD)
Do Until hwnd = 0
If WindowClassName(hwnd) = "ODb" Then
hWndDb = hwnd
Exit Do
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End Function
Public Function hWndMDI(Optional hWndApp As Long) As Long
Dim hwnd As Long
hWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hwnd = GetWindow(hWndApp, GW_CHILD)
Do Until hwnd = 0
If WindowClassName(hwnd) = "MDIClient" Then
hWndMDI = hwnd
Exit Do
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End Function
Public Function WindowClassName(hwnd As Long) As String
Const cMaxBuffer = 255
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = GetClassName(hwnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
WindowClassName = Left(sBuffer, iLen)
End If
End Function
Public Function IsDbWindowVisible() As Boolean
IsDbWindowVisible = IsWindowVisible(hWndDb)
End Function
====================== end code ===============
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
Martin said:
Is there a way to check with VBA if the database window is visible? I
have
seen code on how to show or hide the database window, but cannot see
if/how
to check the status of the window. What I am thinking of is something
like
this:
If dbwindow is visible Then
[Do something]
End If
Thanks.
PS: Forgive me if this is a double-post. I got an error on the first
posting attempt.