Trouble unhiding a toolbar

CarlyS

Registered User.
Local time
Today, 03:54
Joined
Oct 9, 2004
Messages
115
I have used ghudson's code in the Open event of my main form:

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i

To hide all menus and toolbars. I would like to show a single, custom toolbar when reports are opened so they can be printed and then closed. When I use DoCmd.Showtoolbar that toolbar becomes deleted from the list. Am I using ghudson's code improperly perhaps? Has anyone had any experience doing something similar?

Thanks in advance,
Carly
 
Yeah, that method appears to not allow what you want.

Try these to hide or unhide each specific menu or tool bar. You can follow what I am doing and add your custom tool bars to the code below. You might have more to add or you might need to remove any of the below commands for any tool bars that you do not have.
Code:
Public Function ResetToolbars()
On Error GoTo Err_ResetToolbars

    'Sets all of the standard (and custom if called) Access toolbars to display "where appropriate".
    
    ' Turns on the Menu bar.
    DoCmd.ShowToolbar "Menu Bar", acToolbarYes
    ' Turns on the Database toolbar.
    DoCmd.ShowToolbar "Database", acToolbarYes
    ' Turns on the Relationship toolbar.
    DoCmd.ShowToolbar "Relationship", acToolbarWhereApprop
    ' Turns on the Table Design toolbar.
    DoCmd.ShowToolbar "Table Design", acToolbarWhereApprop
    ' Turns on the Table Datasheet toolbar.
    DoCmd.ShowToolbar "Table Datasheet", acToolbarWhereApprop
    ' Turns on the Query Design toolbar.
    DoCmd.ShowToolbar "Query Design", acToolbarWhereApprop
    ' Turns on the Query Datasheet toolbar.
    DoCmd.ShowToolbar "Query Datasheet", acToolbarWhereApprop
    ' Turns on the Form Design toolbar.
    DoCmd.ShowToolbar "Form Design", acToolbarWhereApprop
    ' Turns on the Form View toolbar.
    DoCmd.ShowToolbar "Form View", acToolbarWhereApprop
    ' Turns on the Filter/Sort toolbar.
    DoCmd.ShowToolbar "Filter/Sort", acToolbarWhereApprop
    ' Turns on the Report Design toolbar.
    DoCmd.ShowToolbar "Report Design", acToolbarWhereApprop
    ' Turns on the Print Preview toolbar.
    DoCmd.ShowToolbar "Print Preview", acToolbarWhereApprop
    ' Turns on the Toolbox toolbar.
    DoCmd.ShowToolbar "Toolbox", acToolbarWhereApprop
    ' Turns on the Formatting (Form/Report) toolbar.
    DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarWhereApprop
    ' Turns on the Formatting (Datasheet) toolbar.
    DoCmd.ShowToolbar "Formatting (Datasheet)", acToolbarWhereApprop
    ' Turns on the Macro Design toolbar.
    DoCmd.ShowToolbar "Macro Design", acToolbarWhereApprop
    ' Turns on the Visual Basic toolbar.
    DoCmd.ShowToolbar "Visual Basic", acToolbarWhereApprop
    ' Turns on the Utility1 toolbar.
    DoCmd.ShowToolbar "Utility 1", acToolbarWhereApprop
    ' Turns on the Utility2 toolbar.
    DoCmd.ShowToolbar "Utility 2", acToolbarWhereApprop
    ' Turns on the Web toolbar.
    DoCmd.ShowToolbar "Web", acToolbarWhereApprop
    ' Turns on the Source Code Control toolbar.
    DoCmd.ShowToolbar "Source Code Control", acToolbarWhereApprop

Exit_ResetToolbars:
    Exit Function

Err_ResetToolbars:
    MsgBox "ResetToolbars", Err.Number, Err.Description
    Resume Exit_ResetToolbars

End Function
Code:
Public Function ToolbarsOff()
On Error GoTo Err_ToolbarsOff

    'Sets all of the standard (and custom if defined) Access toolbars to NOT display.

    ' Turns off the Menu bar.
    DoCmd.ShowToolbar "Menu Bar", acToolbarNo
    ' Turns off the Database toolbar.
    DoCmd.ShowToolbar "Database", acToolbarNo
    ' Turns off the Relationship toolbar.
    DoCmd.ShowToolbar "Relationship", acToolbarNo
    ' Turns off the Table Design toolbar.
    DoCmd.ShowToolbar "Table Design", acToolbarNo
    ' Turns off the Table Datasheet toolbar.
    DoCmd.ShowToolbar "Table Datasheet", acToolbarNo
    ' Turns off the Query Design toolbar.
    DoCmd.ShowToolbar "Query Design", acToolbarNo
    ' Turns off the Query Datasheet toolbar.
    DoCmd.ShowToolbar "Query Datasheet", acToolbarNo
    ' Turns off the Form Design toolbar.
    DoCmd.ShowToolbar "Form Design", acToolbarNo
    ' Turns off the Form View toolbar.
    DoCmd.ShowToolbar "Form View", acToolbarNo
    ' Turns off the Filter/Sort toolbar.
    DoCmd.ShowToolbar "Filter/Sort", acToolbarNo
    ' Turns off the Report Design toolbar.
    DoCmd.ShowToolbar "Report Design", acToolbarNo
    ' Turns off the Print Preview toolbar.
    DoCmd.ShowToolbar "Print Preview", acToolbarNo
    ' Turns off the Toolbox toolbar.
    DoCmd.ShowToolbar "Toolbox", acToolbarNo
    ' Turns off the Formatting (Form/Report) toolbar.
    DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarNo
    ' Turns off the Formatting (Datasheet) toolbar.
    DoCmd.ShowToolbar "Formatting (Datasheet)", acToolbarNo
    ' Turns off the Macro Design toolbar.
    DoCmd.ShowToolbar "Macro Design", acToolbarNo
    ' Turns off the Visual Basic toolbar.
    DoCmd.ShowToolbar "Visual Basic", acToolbarNo
    ' Turns off the Utility1 toolbar.
    DoCmd.ShowToolbar "Utility 1", acToolbarNo
    ' Turns off the Utility2 toolbar.
    DoCmd.ShowToolbar "Utility 2", acToolbarNo
    ' Turns off the Web toolbar.
    DoCmd.ShowToolbar "Web", acToolbarNo
    ' Turns off the Source Code Control toolbar.
    DoCmd.ShowToolbar "Source Code Control", acToolbarNo

Exit_ToolbarsOff:
    Exit Function

Err_ToolbarsOff:
    MsgBox "ToolbarsOff", Err.Number, Err.Description
    Resume Exit_ToolbarsOff

End Function
 
Correct me am also confused but not dazed!

ghudson,

this doesn't hide the tool bars on form load/open like when one hides using commandbars. it works magic when you have explicitly opened the application,in form design and you load the form or click a button to hide and unhide the toolbars.

How can i hide the bars for example "Menu Bar" when the whole application is starting!!! so that i unhide it back to view my report!.
 
Last edited:
I do not understand your question. The ToolbarsOff() & ResetToolbars() functions work as is. I just copied those functions into Access 2003, assigned each function to a command button and they worked as expected.

You can call the functions from any event or command button of your choice if and when you want to hide or unhide all the tool bars and menu bars. If you just want to hide or unhide a specific tool bar then you just need to call the line that references the tool bar or menu bar of your choice.
 
You are right ghudson, the functions work magic when you assign command buttons to them which implies that the application starts when the toolbars are enabled so when a particular form loads, you hide them or vise versa.
But My situation is that i want my the application to start when the toolbars are off completely like the magic from commandbars...

Here is what i want. in the OnOpen form event, i call the ToolbarsOff function to hide the toolbars(To be more specific that Menu bar), then in my OnOpen Report Event, i call ResetToolBars to bring it back so that i can print , then On_Report_Close event i turn off the toolbars again. Ideally, this is how its meant to work, but iit does not!!!. Try it my way and tell me.
 
Last edited:
You should create a custom tool bar that has the print options you want the user to access. In the Reports OnOpen event, display only that one custom tool bar. In the reports OnClose event, hide the custom tool bar.
 
Yes, i can do this, but the main thing is to keep the main thing the main thing.

The Main thing is to hide the access menu bar at startup of the application. then may be my custom toolbar can be called later.
If this does not work then its better i use commandbars and snapshot viewer which i dont wanna use coz its a big price for the size of my database.

My Qtn: Cant i totally hide this menu bar from the start!! I mean as my application starts or similar to the action of the commandbars... utility.
 
Cant i totally hide this menu bar from the start
Yes, just run the toolbarsoff function when the db is first opened. Run the function in the AutoExec macro or in the first form that is opened.
 
Man Hudson, am sorry you will have to post an example where you use
Code:
DoCmd.ShowToolbar "Menu Bar", acToolbarYes
At Application Startup and
Code:
DoCmd.ShowToolbar "Menu Bar", acToolbarNo
When Opening a Report.

With Me it doesnt seem to work. Am using Access 2002
What i have resorted to is to keep my menubar there and use two functions in my module
Ftn1: Hides the menus on the menubar when the application starts
Ftn2: Opens The Menu Bar with my custom menus when my report is opened.
 
I used both Ghudson's Hide/Show all Access Menubar and Toolbar code and ResetToolbar code, Rich's ShowToolbar "Menu", acYes, and then some more. Yet, when I click on show Access, I get this:

untitled.jpg


The codes doesn't work because the toolbars visible property is already set as true... but this isn't what I see...

What can I do to fix this?
 
Here's how I do it. On opening the database I hide all menu bars using GHudson's code:

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i

Then in the report's declarations area I have:

Dim i As Integer
Dim rpt As Integer

Then on report open I run this:

'SHOW THE CUSTOM REPORTS TOOLBAR

For i = 1 To CommandBars.Count

If CommandBars(i).Name = "CustomReports" Then

CommandBars(i).Enabled = True
CommandBars(i).Visible = True
rpt = i

End If

Next i

And finally on report close:

'HIDE THE CUSTOM REPORTS TOOLBAR

CommandBars(rpt).Visible = False
CommandBars(rpt).Enabled = False


There are perhaps better ways of doing it, but this method works well.

Larry
 

Users who are viewing this thread

Back
Top Bottom