acCmdWindowHide has no effect

K

Ken Warthen

In the Form_Load event of my login form I test to see if the Navigation Pane
is visible and use the following line to hide it:

DoCmd.RunCommand acCmdWindowHide

The line seems to have no effect as it does not close or hide the Navigation
Pane. Does anybody have any idea on why this code would not work?

TIA,

Ken
 
D

Dirk Goldgar

Ken Warthen said:
In the Form_Load event of my login form I test to see if the Navigation
Pane
is visible and use the following line to hide it:

DoCmd.RunCommand acCmdWindowHide

The line seems to have no effect as it does not close or hide the
Navigation
Pane. Does anybody have any idea on why this code would not work?


I don't have Access 2007 handy to test, but in earlier versions, when doing
the equivalent, you would have to first select something in the window you
want to hide, so you'd use code along these lines:

DoCmd.SelectObject acForm, Me.Name, True
RunCommand acCmdWindowHide

Did you do the SelectObject first?
 
K

Ken Warthen

Dirk,

Thanks for your input. In my code I do select a table first. The Form_Load
event code looks like the following.

Private Sub Form_Load()
On Error GoTo PROC_ERROR

' Initialize the login attempts value
gLoginAttempts = 1

' If the Navigation Pane is visible, hide it
If isNavWindowVisible = True Then
DoCmd.SelectObject acTable, "tblTest", True
DoCmd.RunCommand acCmdWindowHide
End If

PROC_EXIT:
Exit Sub
PROC_ERROR:
Call ShowError("frmLogin", "Form_Load", Err.Number, Err.Description,
Err.Source)
Resume PROC_EXIT
Resume
End Sub
 
D

Dirk Goldgar

Ken Warthen said:
Dirk,

Thanks for your input. In my code I do select a table first. The
Form_Load
event code looks like the following.

Private Sub Form_Load()
On Error GoTo PROC_ERROR

' Initialize the login attempts value
gLoginAttempts = 1

' If the Navigation Pane is visible, hide it
If isNavWindowVisible = True Then
DoCmd.SelectObject acTable, "tblTest", True
DoCmd.RunCommand acCmdWindowHide
End If

PROC_EXIT:
Exit Sub
PROC_ERROR:
Call ShowError("frmLogin", "Form_Load", Err.Number, Err.Description,
Err.Source)
Resume PROC_EXIT
Resume
End Sub


That looks fine to me, but of course I can't see what goes on in
"isNavWindowVisible". Can you step through the code and verify that the
statements that hide the nav pane are actually executed?
 
K

Ken Warthen

Dirk,

I have stepped through each line of code, and though Access appears to
execute the code to hide the Navigation Pane, it does not hide. It's all
very annoying. BTW, here's the code for isNavWindowVisible:

'API function to find a child window for an application handle
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
' API function that returns 1 if a window handle is visible, 0 if
invisible or the handle is zero
Private Declare Function isWindowVisible Lib "user32" Alias
"IsWindowVisible" (ByVal hwnd As Long) As Long


Public Function isNavWindowVisible() As Boolean
On Error GoTo PROC_ERROR
Dim hwnd As Long

If Val(SysCmd(acSysCmdAccessVer)) >= 12 Then
hwnd = FindWindowEx(Application.hWndAccessApp, 0,
"NetUINativeHWNDHost", vbNullString)
Else ' Database Browser is a subwindow of MDIClient inside of Access
' get Access MDI client Window
hwnd = FindWindowEx(Application.hWndAccessApp, 0, "MDIClient",
vbNullString)
' get the Access Database Window
hwnd = FindWindowEx(hwnd, 0, "Odb", vbNullString)
End If

isNavWindowVisible = (isWindowVisible(hwnd) <> 0)


PROC_EXIT:
Exit Function
PROC_ERROR:
Call ShowError("modAPI", "isNavWindowVisible", Err.Number,
Err.Description, Err.Source)
Resume PROC_EXIT
Resume
End Function
 
D

Dirk Goldgar

Ken Warthen said:
Dirk,

I have stepped through each line of code, and though Access appears to
execute the code to hide the Navigation Pane, it does not hide. It's all
very annoying.

Hmm, I just tested the basic code in Access 2007 and it worked fine. I'm
not sure what's going on here. Is there any other code executing, maybe in
a Timer event, that might show the nav pane again?
 
K

Ken Warthen

Dirk,

There's nothing else going on, however, I discovered that if I have the
Display Document Tabs selected in Current Database options, the code works.
When I have the tabs option deselected the code does not work. There's no
logical reason why this would be so, but it appears to be true.

Ken
 
D

Dirk Goldgar

Ken Warthen said:
Dirk,

There's nothing else going on, however, I discovered that if I have the
Display Document Tabs selected in Current Database options, the code
works.
When I have the tabs option deselected the code does not work. There's no
logical reason why this would be so, but it appears to be true.


Interesting, but I don't see the same behavior. I'm testing with a simple
form having code to hide the nav pane in its Open event:

DoCmd.SelectObject acForm, Me.Name, True
RunCommand acCmdWindowHide

I've tested it with the Document Window Options set to "Overlapping
Windows", to "Tabbed Documents" with "Display Document Tabs" checked, and to
"Tabbed Documents" with "Display Document Tabs" unchecked. In every case,
the nav pane is successfully hidden when the form is opened.

So there's something happening for you that is not happening for me. I have
SP1 applied; do you?
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
Interesting.

Here’s my test. With SP1 applied.

In Access options – Current Database – Document Window Option, the default
is
check on Overlapping Windows with disable “Display Document Tabsâ€

I ran the form in the OnOpen event. The Nav Pane is still visible.

Change to “Tabbed Documentsâ€, the checkbox is now enable on the “Display
Document Tabsâ€, but leave the default enabled. Restart Access again.

I ran the form again. The Nav Pane is now hidden.

Back to Access Option, uncheck the “Display Document Tabsâ€. Restart Access
again.

I ran form again. The Nav Pane is still able to hide.

Back to Access Option, this time I will reset back to the original
defaults.
Eg.
Check on “Overlapping Windows†and it will auto disable the “Display
Document
Tabsâ€. Restart access again.

I ran the form again, this time the Nav Pane is able to hide.

It seems like Access2007 needs to do a run-in like car engines! Is MS
tryng
to influence the automotive industries or copying them? LOL.


Well, this is odd. I can't reproduce that. There is no code in my form's
Open event but the code to select the form -- or a table, I've tried it both
ways -- in the database window, and then hide the window. In each case I
set the options, closed the database, reopened the database, and opened the
form. I tried it four ways:

+ Overlapping Windows, "Display Tabs" unchecked and disabled
--> the Nav Pane was hidden when I opened the form

+ Overlapping Windows, "Display Tabs" checked but disabled
--> the Nav Pane was hidden when I opened the form

+ Tabbed Documents, "Display Tabs" checked
--> the Nav Pane was hidden when I opened the form

+ Tabbed Documents, "Display Tabs" unchecked
--> the Nav Pane was hidden when I opened the form

I also tried the first variation with the form set as the database's startup
form, so that it opened automatically. This time, too, the navigation pane
was hidden. In that test, I exited Access completely, rather than just
closing and reopening the database.

I'm completely puzzled why yours isn't behaving the same way. Do you want
to send it to me, to see what it does here?
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
PS. Ok, I have create a new blank database called Test1.
1. Create new form - Onopen event use Docmd.RunCommand acCmdWindowHide.
2. Run the form, the nav pane is still visible.
3. Close the database.
4. Re-open the database.
5. Run the form - the nav pane is hidden.

It seem that you need to close the database before you can use the
acCmdWindowHide?

I just tested the same thing: new database, create form, add code to Open
event:

DoCmd.SelectObject acForm, Me.Name, True
RunCommand acCmdWindowHide

Close and save form, open form in form view, the nav pane was hidden. Go
figure.
One my second test again with a new blank database called Test2, I could
not
replicate this problem.

Weird?

Weird. It must be some timing problem.
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
All my previous test are in Trusted Location and is without any hotfix.

On further test, I created a new database called Test3 in an Untrusted
Location.

Docmd failed to hide the nav pane 3 times. I enable the "Enable this
content"
the security warnings, ran the form - the nav pane was hidden. It will not
work unless you enable the the content.

Yes, of course. In an untrusted location, by default, no code will run, so
the code to hide the nav pane would not be executed.
It seems that A2007 sometimes or at random have problems with macros even
in
Trusted Locations?

I wouldn't jump to the conclusion that what you're experiencing is a problem
with trust and code suppression. If you want to test that, though, you
could add a Debug.Print statement or a MsgBox call to the event procedure to
give clear indication of whether the code was executed.
I don't it's the database file is the problem. The problem seems to
manifest
in A2007/Vista installation.

But I can't reproduce it, even using A2007 under Vista, so there seems to be
some specific condition that we haven't discovered.
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
2.Command1 button to unhide nav pane. Run-time Error '2046' The command or
action 'WindowUnhide' isn't available now. The Error is on DoCmd line but
if
I add a line before the Docmd "On Error Resume Next" the nav pane was
unhidden!

Without the Resume Next the DoCmd will fail.

I'm really puzzle on this one.


I'm guessing that your code for that button was incorrect. Did you maybe
write something like this:

DoCmd.SelectObject acTable, , True
RunCommand acCmdWindowUnhide

? If so, that explains the error. The act of selecting the object in the
database window "unhides" the window; after that, the window is not hidden
and so the RunCommand acCmdWindowUnhide statement will fail. All you need
to show the database window after you've hidden it is:

DoCmd.SelectObject acTable, , True

I've been reminded, since I originally wrote, that you don't actually need
to specify the name of an object when calling DoCmd.SelectObject to hide or
unhide the database window.
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
Yes, but not a table as there none. I use the form.

So, are you saying after hiding the Nav Pane you can't use the RunCommand
acCmdWindowUnhide but use "DoCmd.SelectObject acTable, , True" or the form
to
show the Nav Pane?

Yes. You can use any of these:

DoCmd.SelectObject acTable, , True
DoCmd.SelectObject acQuery, , True
DoCmd.SelectObject acForm, , True
DoCmd.SelectObject acReport, , True
DoCmd.SelectObject acMacro, , True
DoCmd.SelectObject acModule, , True
DoCmd.SelectObject acModule, , True

.... to show the navigation pane, positioned at the group or tab for the
indicated object type. BUT, in Access 2007, you can only do that if there
are objects of that type. This is different from previous versions of
Access, where the tabs existed in the database window regardless of whether
there were any objects of that type in the database.
I wondering what acCmdWindowUnhide do or is redundant.

I'm not sure.
The problem of hiding the Nav Pane still hold true even at the user
machine
as in Ken's problem. I did not proceed with the test as it will solve the
problem as in my end. I decide to leave it as it is.

I don't know what is causing the problem for you. As I said, I can't
reproduce it.
 
D

Dirk Goldgar

AccessVandal via AccessMonster.com said:
Dirk,

I think I found the problem. Your first clue was this.
DoCmd.SelectObject acTable, , True

I was wondering, why select a table/form? You got me thinking of retracing
the steps of the original error.

When I first created a new database, by default A2007 create an unnamed
table,
close the table without saving. Create a new form – events on buttons or
events on form.

I ran the form without saving. The problem appears. This is not an error
as I
soon discovered.

That explains it. It never even occurred to me that you might not have
saved any objects.

I'm still somewhat confused, though, because if I execute DoCmd.SelectObject
acTable ( or acForm, or whatever) in Access 2007, and there are no objects
of that type, an error is raised. But you didn't report any error. Does
your code have error-handling suppressed by On Error Resume Next?

Hmm, further testing shows something interesting. It's possible to
hide/collapse the Forms group in the nav pane, in which case
"DoCmd.SelectObject acForm" doesn't work and doesn't give an error. I'll
bet that's what happened to you.
The acCmdWindowHide is the puzzle. What does it do? I my opinion, it does
not
truly hide the Navigation Pane at all.

The command does what it says: it hides the active window. If you have
successfully selected the navigation pane, and thus made that the active
window, then the navigation pane is hidden. If you have not selected the
navigation pane, then your form is still the active window, and that form
window will be hidden.
In my opinion, the acCmdWindowHide command is best use with precaution.

In Access 2007, I'd say you're right. In practice, though, any working
database will have at least one table or one form, and you -- the database
designer -- will know that to be the case. And you'll probably have decided
either not to present the nav pane to your users, in which case you'll have
set that option in your startup settings, or else you'll be using it as part
of your intended user interface, in which case you will not be hiding it.
 
Joined
Feb 1, 2010
Messages
1
Reaction score
0
No Solution I'm afraid but I have been able to replicate this problem. It seems that if you have custom groups in the navigation pane and these are not expanded then this code doesn't hide the navigation pane but it does still disable the option to view forms etc in design view.
Apologies if this further complicates the issue but I thought it might provide a clue to those more knowledgeable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top