showing and hiding toolbars depending on which form is active/focused

K

Keith G Hicks

Wasn't getting any answers in "commandbarsui" NG so I moved it here. Hope
someone can help! :)

In the application I'm building I run most of the main forms with the
following settings
border = Dialog
Popup = True

I have toolbars that I've built (not as macros, but as actual toolbars) that
need to show or hide depending on which form is up. For example if Form1 has
the focus, Toolbar1 should appear in the main access window menu area (not
on the form itself). If Form2 has the focus (Form1 could still be running),
Toolbar1 should vanish and Toolbar2 should appear in the main access window
menu area (again, not on the form itself). I've tried so many things like
the following (and in other events as well - OnGotFocus, OnLoad, etc.)

Private Sub Form_Activate()

Dim i As Integer
For i = 1 To CommandBars.Count
If CommandBars(i).Name = "mnuClientDetail" Then
CommandBars(i).Enabled = True
End If
Next i

End Sub

or

Private Sub Form_Activate()
DoCmd.ShowToolbar "mnuClientDetail", acToolbarYes
End Sub

I've also tried setting the menu bar property of the form.

I should also note that when this program is in production, I have all the
startup features unchecked (show database window, full menus, etc).

The above ONLY seem to work if the form is NOT popup and NOT Dialog. There
has to be a way to do what I need here. Does anyone have any suggestions?
(other than using macros for the menus). I need some really good direction
on all of this. It's very unintuitive.

Thanks,

Keith
 
J

Jim Allensworth

Wasn't getting any answers in "commandbarsui" NG so I moved it here. Hope
someone can help! :)

In the application I'm building I run most of the main forms with the
following settings
border = Dialog
Popup = True

I have toolbars that I've built (not as macros, but as actual toolbars) that
need to show or hide depending on which form is up. For example if Form1 has
the focus, Toolbar1 should appear in the main access window menu area (not
on the form itself). If Form2 has the focus (Form1 could still be running),
Toolbar1 should vanish and Toolbar2 should appear in the main access window
menu area (again, not on the form itself). I've tried so many things like
the following (and in other events as well - OnGotFocus, OnLoad, etc.)

Private Sub Form_Activate()

Dim i As Integer
For i = 1 To CommandBars.Count
If CommandBars(i).Name = "mnuClientDetail" Then
CommandBars(i).Enabled = True
End If
Next i

End Sub

or

Private Sub Form_Activate()
DoCmd.ShowToolbar "mnuClientDetail", acToolbarYes
End Sub

I've also tried setting the menu bar property of the form.

I should also note that when this program is in production, I have all the
startup features unchecked (show database window, full menus, etc).

The above ONLY seem to work if the form is NOT popup and NOT Dialog. There
has to be a way to do what I need here. Does anyone have any suggestions?
(other than using macros for the menus). I need some really good direction
on all of this. It's very unintuitive.

What I do is Hide the menus and toolbars when the main form is opened.
Then just assign my custom toolbars to the individual forms. If none
is assigned then nothing shows at all.

Private Sub Form_Load()

DoCmd.ShowToolBar "Menu Bar", acToolbarNo
DoCmd.ShowToolBar "Form View", acToolbarNo

End Sub

Now just put the name of your custom toolbar in the forms Toolbar
property.

- Jim
 
K

Keith G Hicks

Your suggestion works ok if the main form is set to Popup=No, but if
Popup=Yes, the menu just doesn't appear at all whether you show it in code
or in the form's Toolbar property. The previous programmer used macros for
all the menus and it worked fine. I have a feeling I'll have revert to that
setup. Would rather not, but looks like I have no choice. Any other ideas?

Thanks,

Keith
 

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