Join Adam Wilbert for an in-depth discussion in this video Hiding the ribbon, part of Access 2013: Tips & Tricks.
We saw in the startup options that we had the ability to minimize the ribbon that appears at the top of our application by toggling off the Allow Full Menu check box. However, that still leaves us with a file and home tab at the top, and it takes up a significant chunk of screen real estate at the top of our database window. We can remove the ribbon interface entirely. By using a very small bit of visual basic code. Let's go ahead and add that to our KinetEco database. I've got open the KinetEco-hide ribbon database right now. And remember, if you're following along with the exercise files, you'll need to hold down the shift key when you open this file to bypass the start up options that we've installed.
First, I'm going to go ahead and open up the splash screen. I'll find it in the forms section, I'll right-click on it, and choose Design View. Next, I'm going to open up the property sheet, and go to the event tab here. Now what I want to do is add in a new event on the On Load section of this form. I'll go to the On Load section, and click the Build button over here on the right. Instead of using the macro builder this time, I'm going to go ahead and jump into the visual basic code builder. I'll choose the code builder option here and press OK. That'll open up Microsoft Visual Basic for Applications. We can see the file that's open right here,KinetEco -hide ribbon forms_Splashscreen.
This is the code that is attached to our splash screen form. And we've got this private subroutine here called form load. In between the private subroutine line and the end sub line, I'm going to put in a little bit of code. First I'm going to type in do command, D-O-C-M-D. The method I'm going to use is called show toolbar. So I'll put a period and then show toolbar. I'll type in a space. The toolbar name that I want to affect is called Ribbon. So in quotation marks I'll type in ribbon, end quote. I'll type a comma, and the next thing I want to do is tell it that I don't want to display it.
So I'm going to choose the option for AC toolbar no. I can either type it in, or choose it from the list here. I'll double click on it to choose it. And I'll press enter to finish the line. If everything turns black, that means you've typed in the code correctly. If you have any red code, you need to go through and figure out what the typo is. Let's go ahead and close out Microsoft Visual Basic. I'll just click on the red x up here in the top right corner; that'll automatically save the code and return me to Access. Now we can goa head and restart the database to see if it works. Let's go ahead and close the file here. It's going to ask me if I want to save the changes to the splash screen, so I will, and now I'll go ahead and open up the file without holding down the shift key.
So I'll find the KinetEco hide ribbon file here. I'll double click on it. I get my little pop up message here telling me if anything is wonky that I can contact myself. Go ahead and say OK. And you notice tha when the splash screen loaded it actually automatically hid the ribbon entirely. I don't have anything across the top of the screen except for the title bar. Let's go through and add a few steps to this main menu screen so that we can reveal and hide the ribbon as needed. I'll press the exit database button here to close out of the database. And back in Windows Explorer, I'll find the file, I'll hold down the shift key this time to bypass the startup options.
And I'll double-click it. Now that we have our database open, I want to go ahead and create a new Options menu. I'm going to borrow some of the elements that we've already destined inside of this Main Menu Reports file, so we keep a consistent look to our database. I'll find main menu reports here. I'll right click and go into Design View. I'm going to go ahead and make a marquee selection by clicking and dragging a rectangle, to choose the blue rectangle, the word report menu at the top, and this button over here on the right. I'll go ahead and press Ctrl C on my keyboard to copy those elements to the clipboard. Okay let's go ahead and close out this form.
I'll press Ctrl W to close that form, and we'll create a new form. Go to the create tab, form design. I'll go ahead and press control V on my keyboard to paste those elements into the top of the screen. Next, I'll change this from report menu, by double clicking on it, and I'll change this to options. Let's go ahead, and change the size of this. I'll come down to the bottom, and drag up to about the three inch mark there. And we're going to change some of the properties for this form. Over here in the properties sheet, if it's not open you can press the Properties Sheet button here on the ribbon. I'm going to change in this drop down menu, form to make sure that I'm editing the properties for the form itself.
And in the format tab of the properties, I'm going to change the caption here to KinetEco Database options. The auto center property, here, I'm going to change from yes to no. The border style I'm going to change from sizeable to dialogue. The record selectors I'm going to turn off. I'll double-click on that to turn it to no. The navigation buttons, I'll change those to No as well, and the scroll bars, I'll change from both to neither. On the other tab of the properties, I'm going to change Pop Up to Yes, and Modal to Yes as well. This will create an option screen that floats on top of my other windows.
Let's go ahead and save this file. I'll press Ctrl S to bring up the save as dialog. And I'll call it main menu-options. Go ahead and say OK to save it. And now we're going to put a couple of buttons here to toggle the ribbon on and off. First I'll come up to the controls group of the design tab and choose the ribbon button here. The one with the four x's. I'll choose that and click down on my options screen. That's going to start the command button wizard and this actually isn't going to help us at all, because there is no command in the options wizard in order to toggle the ribbon on and off. So I'm going to press the escape key to remove the wizard from the screen. Let's go ahead and change a couple of the properties of this button. I'll come over here to the format tab. I'm going to change the caption of this button from command 0 to hide ribbon. And so that my buttons all look consistent through the interface, I'm going to choose the use theme option here to no. That'll make the button gray like all the other buttons. On the other tab, I'm going to change the name of this button from command 0 to BTN hide ribbon. That's so we can recognize this button's name in code. Now, let's switch over to the event tab.
What I want to do is create an on click event for this button. So for the on click property, I'll click build. Again, it's going to ask me if I want to use the macro builder or the code builder. I'll choose to use this in visual basic, so code builder. And we'll say OK and we'll type in the same code that we typed in before. Do command, docmd.show tool bar space in quotation marks ribbon, the name of the ribbon and in quotation marks ribbon, the name of the tool bar we want to affect, a comma and then AC tool bar, no. We'll go ahead and close Visual Basic. And now I've got a button that'll hide the ribbon. Let's go ahead and create one more button that'll reveal the ribbon. I can use this button and copy it. So I'll select it and press Ctrl C. And then immediately press Ctrl V. Now I've got a copy of that button. What I can do is go into the other tab and change its name to BTN show ribbon. And on the format tab, I'll change it's caption from hide ribbon, to show ribbon. Now we need to put in the code for this button. I'll go to the event tab, the on click event. We'll click build again, we'll choose the code builder once again and say OK. And this time for the BTN show ribbon click event. We'll do the same thing. DoCmd.ShowToolbar, the name of the toolbar is Ribbon in quotation marks, comma, and this time, we want to choose acToolbar yes. That'll reveal the ribbon when we click on it. Okay. I've got that typed in. I can close the Visual Basic once again. And now I've got my two buttons finished. Let's go ahead and view this form. Click on the Form View button right over here on the ribbon, and you can see that I've got a pop-up window that shows my options screen. If I press return to main menu,. >> Then I'll close the screen. Oops, it's going to first ask me to save it, so I'll choose save, or yes. That'll return me to my main menu. Now I only need a way to get to my options screen. So from the Main Menu, I want to create a button that'll launch the options. For the main menu I'll right click on it and choose Design View.
This time we can use the button wizard so I'll choose the button up here in the design tab and I'll just click anywhere on the screen on the button. And I'm going to choose form operation open a form. We'll say next the form I want to open is the main menus options. Go ahead and say next. And on the next screen it asks me what I want to appear on my button. I'm going to choose the picture option here and choose this show all picture that'll load all of the pictures in access. I'm going to scroll down towards the bottom until I find one called tools. I think this represents the option screen pretty well.
We'll go ahead and say next. And give it the name dtn main menu options. Go ahead and say finish. And now we can change some of the properties for those buttons to blend them into our form. I'll go to the format tab I'll choose back color from accent one lighter 40% I'll click on the build button here and choose automatic. And for the border style I'm going to change it from solid to transparent. Next I'm going to move my button to the bottom righthand corner of my screen. There and I want to make sure that it sticks there regardless of what size computer the end user is going to be using. In order to do that I'll go to the arrange tab, we'll choose anchoring and I'll chose bottom right.
Now when the user enlarges the screen, that button will always stay in the bottom right hand corner. Let's go ahead and save it and test it out. I'll press the save icon here, we'll go to the home tab, and switch to form view. Now I can press my tools button here, that should launch the options. I can show and hide the ribbon. And everything looks like it's working. Now we have a database that automatically hides the ribbon interface on startup by attaching the visual basic code to the splash screen's on load event. We also created a couple of toggle buttons to get the ribbon back if we need it while working without having to restart the database.
One thing to note is that if the ribbon is hidden completely, that will also remove the print preview ribbon from showing whenever somebody is trying to print reports. If this is functionality that you need, then you need to either provide your own controls, say with a button on a form, or simply reveal the ribbon again whenever your users are going to be printing.
- Creating a kiosk experience
- Hiding the ribbon
- Creating cascading combo boxes
- Working with hidden objects
- Creating a separate back end
- Building a dynamic reporting tool
- Writing custom functions in Visual Basic
- Distributing your application