Solved

VBA - Is Access 2013 Navigation Pane Visible

Posted on 2014-04-17
9
2,287 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Backup Your Microsoft Windows Server®

Backup 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.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now