From the course: Access 2019: Tips, Tricks, and Techniques

Hide the ribbon

From the course: Access 2019: Tips, Tricks, and Techniques

Start my 1-month free trial

Hide the ribbon

- [Instructor] 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 checkbox. However, that still leaves us with the File and the Home tab at the top of our screen. And this can take up a significant amount of screen real estate here in our window. We can remove the ribbon interface entirely by using a very small bit of Visual Basic code. Let's go ahead and close out of this database. And once again I'll find it here in my Exercise Files. This time we're working on one called H+ Sport - Ribbon. I'll hold down the Shift key and Double Click on it to open it up, bypassing the startup options. Then I'm gonna Right Click on my Splash Screen and open it straight into Design View. If I just Double Click on it, it's gonna open it and then the macro will kick in and close it down and open up that main menu. So, that's why we need to go through this Right Click menu to go into Design View. Then I'm gonna go on the Design tab and open up the Property Sheet and switch over to the Event tab. I wanna create a Visual Basic routine that starts in the On Load event. So, when the Splash Screen opens up, it's gonna kick in this macro. I'll click on the Build button. And then we'll switch over. Instead of using the Macro Builder, I'm gonna choose the Code Builder. I'll say OK to that. And that'll open up Visual Basic for Applications. Now, the command that I need to run is pretty simple, it's just DoCmd.ShowToolbar and then two arguments. Inside double quotes, the first argument is Ribbon. That's the toolbar name. And then I'll type in a comma and the second argument is acToolbarNo. This is the code that'll tell Access not to display the ribbon. Let's go ahead and close out of Visual Basic. I'll press the X in the upper right-hand corner here. That'll save the event procedure in the On Load event. We can go ahead and close out of the Property Sheet and test it out. I'll press Control + W on my keyboard to close out of the form. That'll prompt me to save it, and I'll say Yes. Then if I Double Click on the Splash Screen to open it up normally, you'll see that my ribbon immediately disappears from the screen. Now, it would actually be nice to have a toggle button here on my main menu in order to get the ribbon back on again if I'd like. Let's go ahead and add that in as well. To do that, I actually need to get my ribbon back. So, I'm gonna close out of this database. Then we'll open it up again by holding down that Shift key and Double Clicking on the Ribbon database. This time we'll go over here to the main menu and I'll Right Click on it and go into Design View. On the Design tab of the ribbon, I'm gonna click on the Button control and add one down here above my Exit Database button. That'll start up the Command Button Wizard, which is not what we're gonna use here. So, I'm gonna press the Cancel button. And then open up the Property Sheet. With that Command Button still selected, I'm gonna go over here to the Format tab. And for the Caption, I'm gonna type in Show Ribbon. Then on the Other tab, we'll give this button a name. Instead of Command32, I'll call it btnShowRibbon. And finally, we can go over to the Event tab and find the On Click event and click on the Build button to the right. Once again we're gonna use the Code Builder and say OK. That'll open up Visual Basic again. And this time the command is DoCmd.ShowToolbar "Ribbon", acToolbarYes. Once again we can close out of Visual Basic when that's put in. And that saves the event procedure for that button. And close the Property Sheet. And we'll go ahead and resize my button a little bit to make it the same size as the Exit Database button. And we might as well format it as well. I'll click on Quick Styles and then I'll choose the gray option here in the center. Next, let's go ahead and copy that button. I'll press Control + C on my keyboard. And then Control + V to paste a copy of it down below. Then I'll go back to the Design tab, open up the Property Sheet once again. Back on the Format tab, we'll change the Caption from Show Ribbon to Hide Ribbon. Then on the Other tab we'll rename the button to btnHideRibbon. And finally, we'll go back to the Event tab and find the On Click event for this. I'll click on the Build button, go into Code Builder, say OK. And then, once again I'll type in DoCmd.ShowToolbar "Ribbon", acToolbarNo. Once that's all done, I'll go ahead and close out of Visual Basic. And that'll save the event procedure for that button. So, now let's go ahead and close the Property Sheet and test everything out. I'll switch my view back into Form View. And now I have two buttons here, one called Show Ribbon and one called Hide Ribbon. Let's go ahead and click on the Hide Ribbon button and you'll see that my ribbon disappears. I'll click on the Show Ribbon button and you'll see that it appears again. Let's go ahead and attach these two buttons over here to the right side of my form so that they stay on top of the Exit Database button. Once again I'll go back into Design View. I'll highlight both of these buttons. And then on the Arrange tab, I'll go to Anchoring and choose to anchor them to the Top Right corner. That'll link them to the right side of my screen so that they move over when we switch back into Form View. So, let's go ahead and test out our entire procedure. I'll close out of the database. I'll save all my changes. And then we'll go ahead and open up that Ribbon database once again. This time I'm not gonna hold down the Shift key, I'll just let it process normally. Well, you can see that I get my Splash Screen here. I'll say OK to this dialog box. Then I get my database it opens up. We can see I don't have the ribbon, I don't have the navigation pane. I have a really clean interface that focuses me here inside of the H+ Sport database. I also have two buttons over here to show the ribbon if I need it or hide it when I don't. So, 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, though, is that if the ribbon is hidden completely, that'll also remove the Print Preview ribbon from showing up when trying to print reports. If this is functionality that you need, then you need to either provide your own controls, say with buttons on a form, or simply reveal the ribbon again when your users are gonna be printing.

Contents