From the course: Access 2019: Forms and Reports

Refine button macros

From the course: Access 2019: Forms and Reports

Start my 1-month free trial

Refine button macros

- [Instructor] On our main menu form that we set up in the last movie, we have this button that says open employee directory. And when I click on it, it opened up the employee directory form here in a new tab. Now I can enhance this behavior by having the H+ Sport Main Menu disappear when the employee directory opens up. Essentially what I want to do is have this tab replace the main menu tab and only have one open at a time. I can accomplish this by modifying the macro that this button is triggering. Let's go ahead and take the main menu into design view, and I'm going to select the button and open up the properties sheet. Then on the events tab in the on click event, we have this embedded macro. This is the macro that the Wizard built for us when we went through that process. I'm going to select it and then click on the build button over on the right hand side. This'll open up that macro in a new editing window where we can change its behavior. When we went through the Wizard, we only chose to have it open up a single form. So we have the one step, open form, and the form was the employee directory. I'm going to come down here to the add new action and the new action that I want to add is called close window. I'll simply type it in to the box. Then access wants to know what object we want to close, but if I hover my mouse over this, you'll see the popup text that says select the type of object to close, leave blank to select the active window. If I leave my macro in this order right now, it's going to open up a form called the employee directory and then it's going to close the active window. But at this point, the active window is going to be the employee directory. So essentially this macro would open the employee directory and then immediately close it again. What I need to do is move this step up to the beginning. I'll do that by pressing the green arrow on the right. Now the macro will close the active window, and at this point it's going to by the main menu because that's the form that's open when we click on the button. Then, after that, it'll open up the employee directory. Let's go ahead and close the macro and I'll save the change. Now we can switch over into form view and test it out. I'll click the button and it's going to prompt me to save here because this is the first time that this main menu is closing since we made any changes to it. So I'll save the design of it. And when I do that, it opens up the employee directory and you can notice that the main menu has now closed. Now what I need to do is provide a button on the employee directory to return me back to the main menu. I'll take the employee directory into design view. Then I'll come up here into my controls group and I'll grab the button button. I'll come down into the header section and click to add in a command button. Once again, we'll see the command button wizard and I'm going to choose form operations, open a form. I'll press next. The form I want to open is the main menu. Go ahead and press next. This time, I'll just choose the text option and type in return to main menu. I'll press next and accept the default name and press finish. That'll create a new button over here on the right hand side of my form. Now I'm going to go back to the properties sheet and we'll edit that macro. So back on the event tab in the on click event, I'll click on the build button. Once again I'll add in my close window step. I'll leave the object type blank, but I'll move this step up to the beginning. Then I can go ahead and close the macro and save the change. Now I want to style my button to maintain a consistent appearance throughout the database, so I'll go to the format tab and I'll change its quick styles to this gray option here in the middle of the screen. Then I want to make sure that this button stays in a consistent position as I use it in other forms on my database. In order to position it exactly, I'm going to go over here to the format tab and I'm going to adjust some of the width and height properties here. I'm going to change the width to an even 1.5 inches. Then I'll press the down arrow key on my keyboard to go to height and I'll make it an even quarter inch tall by typing in 0.25. Then I want to position this exactly so I'm going to type in 0.5 for the top location. That'll move it down on the header section a little bit. And the left position, I'm going to lock it at exactly six inches. I'll type in six and press enter. Then I'm going to make sure that my form is exactly eight inches wide. So I'm going to click on this edge here and drag it over to the eight inch marker, looking at the top of the ruler right up above. Finally, I want to make sure that this button stays locked in the upper right hand corner of the form. To do that, I'll go over to the arrange tab, I'll click on anchoring, and then anchor it to the top right corner. Now I can go ahead and close the properties sheet and I'll save my form. And I'll switch back into form view to test it out. I'll go ahead and click on the return to main menu button and that switches me over here to the main menu. You'll notice that that tab closes. If I press open employee directory, it switches me over to that. Also notice here on the tabs that we're having a nice transition because we've named these consistently. So I have H+ Sport Employee Directory. When I click on the main menu button, that cleanly changes over to H+ Sport Main Menu. And I think that provides a really nice transition effect. So as our database grows and we add additional functionality through other forms and reports, we can return to this main menu and add additional navigation buttons that'll get our end users to where they need to go and back.

Contents