Solved

VBA - Is Access 2013 Navigation Pane Visible

Posted on 2014-04-17
9
2,486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 58

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 58
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 58
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 58
ID: 40007730
Glad to hear your squared away...

Jim.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

717 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