The ribbon interface takes up a significant chunk of screen real estate at the top of the database window. By using a small bit of Visual Basic code, the ribbon can be effectively removed from the screen entirely. In this movie, Adam shows how to implement the code and connect it to a pair of buttons to toggle the ribbon on and off as needed.
- View Offline
- [Voiceover] We saw in the start-up options that we had the ability to minimize the ribbon tabs that appear across the top of our application by toggling off the allow full menu checkbox. However this still leaves us with the file and home tabs across the screen, and it takes up a significant chunk of screen real estate. We can remove the ribbon interface entirely by adding a very small bit of visual basic code. What I want to do is modify my splash screen in order to remove the ribbon interface entirely with the splash screen first loads. To do that, I'll right-click on the splash screen and go into design view. Then we'll open up the property sheet, and on the event tab for the form properties, we'll find the property called on load.
I'll go ahead and click here, and then on the far right, I'll click on the build button. That'll ask me which building method I want to choose, and I'll choose the code builder. This'll launch visual basic for applications. Go ahead and press OK, and that starts up. On this window here, I can verify that I'm editing the code that's attached to splash screen form. Then I've got a private sub-routine called form load and the line at the end, that says it ends the sub-routine. The code that I'm going to type in is going to go between these two lines. I'm going to type in the object do command, or DO CMD.
I'll type in a period, and the method I want to call is called show toolbar. The show toolbar method has a couple of arguments that we supply. First, we need the name of the toolbar which in our case is called ribbon. So inside of quotation marks, I'll type in ribbon. Then I'll type in a comma, and the second argument is called AC toolbar no. I can either type it in or just select it from the pop-up list. Go ahead and press enter, and everything turns black then you know that you've typed it in correctly. If the text turns red, that means you have a typo and you need to go back and figure out what that is. Now essentially what this code is doing is saying when the splash screen loads, it's going to hide the ribbon.
When I'm done typing it in, let's go ahead and close the visual basic for applications and that'll save our changes to this event procedure here in the on load event. Then we can close the property sheet, and close the database and save our changes. When I double-click on the database again, you'll notice we get the pop-up menu here. We get this little dialogue box in the front telling me that if anything's wonky to contact myself. Press OK to that, and when the main menu opens up, you'll notice that our ribbon is completely hidden from the screen. So now our interface is looking much cleaner. Now as a last step, what I want to do is add an option here on the main menu to toggle that ribbon back on and off in case we need to get access to it without having to restart the database.
Let's go ahead and add that in. I'm going to close the database, then back inside of Windows Explorer, I'll hold down the shift key and double click on the ribbon to open it up. Then we're going to modify this main menu. So let's right-click on it, and open it straight into design view. On the design tab, I'll come up here and grab a button control. It's the rectangle with the four X's in it. We'll come down, and click once add in a new button. Now in the command button wizard, there's no option to turn the ribbon on or off so this isn't going to help us out. So go ahead and just press the cancel button, and we'll build the macro code manually. With the button selected, I'll go up here to the property sheet.
On the event tab, we'll go to the on-click events, and I'll click the build button over here on the far right. Once again we'll go into our code builder, and say OK. That'll create a new private sub-routine inside of our buttons code, and we'll type in the same code. Do command. Dot show toolbar. The name of the ribbon, and this time we'll say AC toolbar yes. That'll toggle the ribbon back on. Go ahead and say close this and we'll close visual basic to save those changes. Then we'll go over here to the format tab and we'll change the caption, which is the text that appears on the left, and we'll say Show Ribbon.
And close the property sheet, and we have our new button here. Let's make a copy of this. I'll press Control C on the keyboard to copy it, and then Control V to paste a copy of it. Then once again, we'll go to the property sheet for the second button. We'll change its caption to Hide Ribbon. Then we'll go in the event tab. On the on click event, I'll click build again. Once again, we'll go back into our code builder and for this command button, we'll type in do command dot show toolbar ribbon, AC toolbar no. If I press enter and everything turns black. I know we're good to go.
Let's go ahead and close out visual basic one more time and close out the property sheet. Now I've got two buttons that'll show and hide the ribbon. Let's move these into position. I'll shift click to select both of them, and just use the arrow keys to nudge them over. Then, I want to make sure that they stay anchored in the bottom right-hand corner of the screen. To do that, I'll go up here to the Arrange tab. Under anchoring, and choose bottom right. Finally let's format them so they fit in with the styling of the rest of the buttons. On the Format tab, we'll choose Quick Styles and we'll choose this gray option down here.
I'll press Control S on my keyboard to save the changes, and then Control W to close everything down. Now let's test it out. Let's close the database, and back inside of Windows Explorer, I'll open up the H+ Sport Ribbon file without holding down the shift key. We get our splash screen and this little dialogue box. We'll say OK to that. When the splash screen closes after three seconds, the main menu opens up. Notice that my ribbon is hidden, but I can come down here and show the ribbon or hide the ribbon again using these two toggle buttons that we've created down here. So now we have a database that automatically hides the ribbon interface on start-up by attaching the visual basic code to the splash screens on load events.
You also created a couple of toggle buttons to get the ribbon back if we need it while working, without having to close and restart the database. One thing to note 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 the form, or simply reveal the ribbon again whenever your users are going to be printing.
- Creating an AutoExec macro
- Creating a kiosk experience
- Working with hidden objects: queries, tables, and more
- Splitting a database into back and front ends
- Creating a dynamic reporting tool
- Adding shortcuts and other aids to end users
- Writing custom VBA functions
- Packaging and distributing your Access application