Access menu commands provide built-in procedures you can run to take many actions. In this video, learn how to run a menu command.
- [Instructor] The typical Access application limits what users can do, usually by hiding significant chunks of the user interface. If you want to allow your users to take actions they would usually initiate through the user interface, you can attach a run command code segment to a command button. I'll demonstrate how to do that in this movie. I have opened the course database and displayed the product form. I want to add a command button to this form, so that means I need to work with it in design view.
On the home tab of the ribbon, I'll go to the view button, click it's down arrow, and click design view. I will resize the detail section and then on the design contextual tab of the ribbon, which displayed for me because I'm looking at the form in design view, I'll go to the controls gallery, click the button item, and then click inside of the detail section on a blank spot. And you can see my command button was created.
I don't want to use the command button wizard, so I'll click cancel and I will edit the command button's label to say export and click away. Now that I have the button on the form, I can add code to it. So I'll right click, click build event, click code builder, and click OK. And here you see that I have a command 14 underscore click event handler, so whenever this command button is clicked it will run this command.
I'll press enter a couple of times to give myself some space to work. To run a menu command from a command button, you use do command then a period and run command so we're using the do command objects run command method followed by a left parentheses and then you need to give the command that you want to use. And, as you can see, there is a huge list. They start with A-C-C-M-D, and then you have Align Bottom, Align Center, Align Left, and so on.
In this case, we will use A-C-C-M-D, and that's common for all the commands you're going to run, ACCMD stands for Access Command, and then Export Excel followed by a left parentheses. So whenever the form is open and someone clicks the button, Access will attempt to export the data to excel. I'll press Alt + F11 to move back to the visual based editor, change back to form view, so I'll go to the view control and click the main body of the button which takes us back to form view, click export and we can select the destination for the export, the file format, and everything else from the usual Access Export functionality.
I won't go through with it in this case. It's just a series of wizard steps that you can go through so I'll click cancel, and now we have our code in place to export our data whenever we want to from the products form.
- Working with macros
- Running a VBA procedure
- Debugging VBA code
- Defining variables, constants, and calculations
- Displaying a calculated result in a message box
- Repeating tasks with loops
- Manipulating database objects
- Adding, editing, and deleting records
- Looking up values in a table
- Automating processes with macros
Skill Level Advanced
What you should know1m 38s
1. Introduction to Visual Basic for Applications
2. Define Variables, Constants, and Calculations
3. Add Logic to Your VBA Code
4. Debug Your VBA Code
5. Manipulate Database Objects Using DoCmd
6. Read and Manipulate Table Data
7. Manipulate a Database Using the Application Object
8. Control Forms and Reports Using the Me Object
9. Automate Processes Using Macros
Next steps1m 7s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.