Solved

VBA - Is Access 2013 Navigation Pane Visible

Posted on 2014-04-17
9
2,389 Views
Last Modified: 2014-04-17
I use the following code to hid the navigation pane:
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.RunCommand acCmdWindowHide

I use the following code to show the navigation pane:
DoCmd.SelectObject acTable, , True

What code do I use for:
Public Function IsNavigationPaneVisible() as boolean
dim fReturn as boolean
fReturn=?????
IsNavigationPaneVisible=fReturn
Exit Function
0
Comment
Question by:rmk
  • 5
  • 4
9 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40006641
Not sure if this will work in A2013 or not.  Give it a shot:

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long

Private Declare Function isWindowVisible Lib "user32" Alias "IsWindowVisible" (ByVal hwnd As Long) As Long

Public Function isDbWindowVisible() As Boolean
Dim hWindow As Long
If Int(SysCmd(acSysCmdAccessVer)) >= 12 Then
hWindow = FindWindowEx(Application.hWndAccessApp, 0, "NetUINativeHWNDHost", vbNullString)
hWindow = FindWindowEx(hWindow, 0, "NetUIHWND", vbNullString)
Else
hWindow = FindWindowEx(Application.hWndAccessApp, 0, "MDIClient", vbNullString)
hWindow = FindWindowEx(hWindow, 0, "Odb", vbNullString)
End If
isDbWindowVisible = (isWindowVisible(hWindow) <> 0)
End Function
0
 

Author Closing Comment

by:rmk
ID: 40006719
That's exactly what I needed. THANKS !
0
 

Author Comment

by:rmk
ID: 40006748
Actually, I thing your code needs a couple of minor changes for VBA7, i.e. the Declare statement needs PtrSafe and the handles should be delcared as LongPtr instead of Long

Declare PtrSafe Function IsWindowVisible Lib "user32" Alias "IsWindowVisible" (ByVal hwnd As LongPtr) As Long

Dim hWindow As LongPtr
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:rmk
ID: 40006917
It works fine when I open my application with the shift key depressed and then manually open the startup form called frmMain. I can use F11 to toggle the navigation pane and the code always returns the correct true or false value.

However the code always returns true when I open my application without the shift key depressed. There is no autoexec macro and the DisplayForm drop down list is set to frmMain. The only psuedo startup code is:

Public grbnForm                     As IRibbonUI
Public grbnBackStage                As IRibbonUI

Public Sub FormRibbonOnLoad(ribbon As IRibbonUI)
    Set grbnForm = ribbon
End Sub

Public Sub BackStageRibbonOnLoad(ribbon As IRibbonUI)
    Set grbnBackStage = ribbon
End Sub

Any ideas ?????
0
 
LVL 57
ID: 40006944
<<Actually, I thing your code needs a couple of minor changes for VBA7, i.e. the Declare statement needs PtrSafe and the handles should be delcared as LongPtr instead of Long>>

 That's only if your running 64 bit instead of 32 bit Office.

<<Any ideas ????? >>

 In frmMain, try an explicit hide of the nav pane, and then see if it starts returning the correct value.

Jim.
0
 

Author Comment

by:rmk
ID: 40007077
The explicit hide did not work.

Since 32 bit Office is running on 64 bit Windows, I thought all window handles were 64 bit and therefore had to be declared with PtrSafe as LongPtr. At least that's what it implies in Win32API_PtrSafe.txt that I downloaded as part of Office 2010 Developer Resources which has the following preambel
'
'             Win32API_PtrSafe.TXT -- Declare statements for
'         Visual Basic for Applications and Microsoft Office 2010
'
'              Copyright (C) 2010 Microsoft Corporation.
'                         All rights reserved.
'
'
' This file contains Declare statements for many functions in the
' Microsoft Windows API for use with Visual Basic for Applications (VBA)
' and Microsoft Office 2010 on 32-bit (x86) and 64-bit (x64) platforms.
'
' The declare statements in this file are not compatible with VB6 or
' previous versions of Microsoft Office. Refer to the Microsoft Windows
' Programmer's Reference for further information on the use of Windows APIs.
'
' You may use, modify, reproduce, and distribute this file (and/or any
' modified version), for use with any of the Microsoft technologies
' described above.  THIS FILE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF
' FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
0
 
LVL 57
ID: 40007121
<<Since 32 bit Office is running on 64 bit Windows, I thought all window handles were 64 bit and therefore had to be declared with PtrSafe as LongPtr. At least that's what it implies in Win32API_PtrSafe.txt that I downloaded as part of Office 2010 Developer Resources which has the following preambel>>

 No, it's optional when making calls from 32 bit.  It's only required when your using 64 bit office. Read the section "Application Programming Interface Compatibility"  here:

http://msdn.microsoft.com/en-us/library/ee691831%28v=office.14%29.aspx

and note that:

"Note that the PtrSafe attribute is optional on the 32-bit version of Office 2010. This enables existing Declare statements to work as they always have. "

 as for why it's not working, I don't know.  I'd have to dig into it and don't have the time at the moment.

   I picked up the code somewhere just out of interest on the chance that I might use it some day.  Never tried it.

Jim.
0
 

Author Comment

by:rmk
ID: 40007211
I read your link carefully this time, and as usual you are correct.
BTW, I unchecked the  the Display Navigation Pane check box in Current Database Options and explicitly hide the navigation window in frmMain. Now the IsVisible function works properly.
You continue to be one of most valued resources - thank you for your superb support!
0
 
LVL 57
ID: 40007730
Glad to hear your squared away...

Jim.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question