{"id":772,"date":"2016-06-09T21:42:24","date_gmt":"2016-06-10T04:42:24","guid":{"rendered":"https:\/\/database.guide\/?p=772"},"modified":"2016-06-09T22:47:21","modified_gmt":"2016-06-10T05:47:21","slug":"microsoft-access-tutorial-part-3-queries-forms-macros","status":"publish","type":"post","link":"https:\/\/database.guide\/microsoft-access-tutorial-part-3-queries-forms-macros\/","title":{"rendered":"Microsoft Access Tutorial (Part 3): Queries, Forms, &#038; Macros"},"content":{"rendered":"<p>This article is Part 3 of the <a href=\"https:\/\/database.guide\/microsoft-access-tutorial\/\">Microsoft Access tutorial<\/a>.<\/p>\n<p class=\"p1\">Here&#8217;s what&#8217;s included in this article:<\/p>\n<ul>\n<li class=\"p1\">Create a query (so you can &#8220;search\u00a0the database&#8221;).<\/li>\n<li class=\"p1\">Create a form for data entry.<\/li>\n<li class=\"p1\">Create a macro (so that a multi-step task can be done automatically &#8211; at the click of a button).<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>About Queries<\/h2>\n<p>Queries allow you to &#8220;search the database&#8221;. But\u00a0it&#8217;s not just any old search.<\/p>\n<p>A query allows you to specify\u00a0exactly which <a href=\"https:\/\/database.guide\/what-is-a-field\/\">fields<\/a>\u00a0you want returned, and from which <a href=\"https:\/\/database.guide\/what-is-a-table\/\">tables<\/a>.<\/p>\n<p>A query also lets you add criteria for filtering the data.\u00a0So for example, you could specify\u00a0that you only want to see orders worth more than $100, or only products of a particular brand, or only customers who have only ever\u00a0purchased one item, etc.<\/p>\n<p>Queries can also be saved to the database. So\u00a0no need to rebuild the same queries over and over again. Simply open it from the database and it&#8217;s ready to go.<\/p>\n<h2>Sample Data<\/h2>\n<p>You&#8217;ll need to have some data in your tables before you create a query.<\/p>\n<p>Here are the three tables that we created <a href=\"https:\/\/database.guide\/microsoft-access-tutorial-part-1-databases-tables-fields\/\">earlier in the tutorial<\/a>, but this time they contain\u00a0data.<\/p>\n<p>(If you already have data in your tables, skip this step).<\/p>\n<figure id=\"attachment_773\" aria-describedby=\"caption-attachment-773\" style=\"width: 475px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_customers_table_in_access.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-773\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_customers_table_in_access.png\" alt=\"Screenshot of the Customers table with data.\" width=\"485\" height=\"291\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_customers_table_in_access.png 485w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_customers_table_in_access-300x180.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/a><figcaption id=\"caption-attachment-773\" class=\"wp-caption-text\">The Customers table.<\/figcaption><\/figure>\n<figure id=\"attachment_775\" aria-describedby=\"caption-attachment-775\" style=\"width: 514px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_products_table_in_access.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-775\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_products_table_in_access.png\" alt=\"Screenshot of the Products table with data.\" width=\"524\" height=\"214\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_products_table_in_access.png 524w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_products_table_in_access-300x123.png 300w\" sizes=\"auto, (max-width: 524px) 100vw, 524px\" \/><\/a><figcaption id=\"caption-attachment-775\" class=\"wp-caption-text\">The Products table.<\/figcaption><\/figure>\n<figure id=\"attachment_774\" aria-describedby=\"caption-attachment-774\" style=\"width: 457px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_orders_table_in_access.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-774\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_orders_table_in_access.png\" alt=\"Screenshot of the Orders table with data.\" width=\"467\" height=\"313\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_orders_table_in_access.png 467w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/sample_orders_table_in_access-300x201.png 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" \/><\/a><figcaption id=\"caption-attachment-774\" class=\"wp-caption-text\">The Orders table.<\/figcaption><\/figure>\n<p>You can copy the data from these tables or you can add your own.<\/p>\n<p>Three\u00a0things to remember:<\/p>\n<ul>\n<li>The ID fields and <samp>DateCreated<\/samp> fields will be populated automatically. No need to enter data into those fields (remember, one&#8217;s an <samp>AutoNumber<\/samp> and the other has a <samp>Default Value<\/samp> set). Only enter data into the two middle fields of each table.<\/li>\n<li>Do\u00a0the <samp>Orders<\/samp> table\u00a0<strong>last<\/strong>.\u00a0Enter data into the <samp>Customers<\/samp>\u00a0table and the\u00a0<samp>Products<\/samp> table first. Then once all the <a href=\"https:\/\/database.guide\/what-is-a-primary-key\/\">primary keys<\/a> are populated, you can enter data into the <samp>Orders<\/samp> table. You need to do this\u00a0because\u00a0we set up the database\u00a0to enforce <a href=\"https:\/\/database.guide\/what-is-referential-integrity\/\">referential integrity<\/a>. This means\u00a0you\u00a0won&#8217;t be able to enter\u00a0a value into a <a href=\"https:\/\/database.guide\/what-is-a-foreign-key\/\">foreign key<\/a> field\u00a0that doesn&#8217;t\u00a0correspond to a value in the primary key field.<\/li>\n<li>On the <samp>Orders<\/samp> table, make sure the values of the <samp>CustomerId<\/samp> and <samp>ProductId<\/samp> fields match those in their respective primary key fields.<\/li>\n<\/ul>\n<h2>Create a Query<\/h2>\n<p>OK, so now that we have data, we can create the query.<\/p>\n<p>Click the <kbd>Query Design<\/kbd> button from the Ribbon.<\/p>\n<figure id=\"attachment_146\" aria-describedby=\"caption-attachment-146\" style=\"width: 568px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-146 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_1.png\" alt=\"Screenshot of the Query Design button on the Ribbon in Access 2013\" width=\"578\" height=\"145\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_1.png 578w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_1-300x75.png 300w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/a><figcaption id=\"caption-attachment-146\" class=\"wp-caption-text\">Click the Query Design button to create a query in Design view. You could also use the Query Wizard button next to it to launch the Query Wizard, however, Design view gives you more control over the query.<\/figcaption><\/figure>\n<p>Access will ask you to\u00a0select the tables to include in the query. Select all, click <kbd>Add<\/kbd>, then click <kbd>Close<\/kbd>:<\/p>\n<figure id=\"attachment_148\" aria-describedby=\"caption-attachment-148\" style=\"width: 324px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-148 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_2.png\" alt=\"Screenshot of the Show Tables dialog in Microsoft Access 2013\" width=\"334\" height=\"310\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_2.png 334w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_2-300x278.png 300w\" sizes=\"auto, (max-width: 334px) 100vw, 334px\" \/><\/a><figcaption id=\"caption-attachment-148\" class=\"wp-caption-text\">The Show Table dialog allows you to choose which tables to include in the query. You can also include other queries to use within a query.<\/figcaption><\/figure>\n<p>Access will display the <samp>Query Design View<\/samp>. This allows you to specify the exact criteria you&#8217;d like to use in the query.<\/p>\n<figure id=\"attachment_149\" aria-describedby=\"caption-attachment-149\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-149\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_3.png\" alt=\"Screenshot of Query Design View in Access 2013\" width=\"600\" height=\"451\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_3.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_3-300x226.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-149\" class=\"wp-caption-text\">Query Design View allows you to specify the precise criteria for the query. You can choose which tables are shown in the results, which fields to use, add filtering criteria, and more.<\/figcaption><\/figure>\n<p>Set it up like the above screenshot then click the <kbd>Run<\/kbd> button in the Ribbon:<\/p>\n<p><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-152 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_4.png\" alt=\"Screenshot of the query Run button in Microsoft Access 2013\" width=\"96\" height=\"104\" \/><\/a><\/p>\n<p>Clicking the <kbd>Run<\/kbd> button will run the query. Clicking the <kbd>View<\/kbd> button next to it will also run the query.<\/p>\n<h3>The Results<\/h3>\n<p>Access will now display the results of your query:<\/p>\n<figure id=\"attachment_153\" aria-describedby=\"caption-attachment-153\" style=\"width: 532px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-153\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_5.png\" alt=\"Screenshot of query results in Datasheet view in MS Access 2013\" width=\"542\" height=\"309\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_5.png 542w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_5-300x171.png 300w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/a><figcaption id=\"caption-attachment-153\" class=\"wp-caption-text\">The query results are displayed in Datasheet view.<\/figcaption><\/figure>\n<p>Notice the query is displaying\u00a0fields from two different tables, but\u00a0it is presented as though it&#8217;s a single table. Also, it is using a third table (<samp>Orders<\/samp>) but not displaying any fields from that table.<\/p>\n<p>Of course, this is how we designed the query. We could just as easily have included fields from the <samp>Orders<\/samp> table, but we didn&#8217;t need them in this case.<\/p>\n<p>So, queries provide a lot of flexibility\u00a0for retrieving data and displaying it.<\/p>\n<p>When you set up your database correctly (so that it maintains\u00a0<a href=\"https:\/\/database.guide\/what-is-data-integrity\/\">data integrity<\/a>), you can be confident that your queries will return all applicable results &#8211; no more, no fewer.<\/p>\n<h3>Save the Query<\/h3>\n<p>If you think you might need a query again, you can save it. Just\u00a0right click on the <kbd>Query<\/kbd> tab and click <kbd>Save<\/kbd>. Call it <samp>Customer Orders<\/samp>:<\/p>\n<figure id=\"attachment_154\" aria-describedby=\"caption-attachment-154\" style=\"width: 245px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-154\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/how_to_create_a_query_in_access_6.png\" alt=\"Screenshot of saving a query in Microsoft Access 2013\" width=\"255\" height=\"189\" \/><\/a><figcaption id=\"caption-attachment-154\" class=\"wp-caption-text\">Saving a query<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Check out <a href=\"https:\/\/database.guide\/how-to-create-a-query-in-access\/\">How to Create a Query in Access<\/a>\u00a0for an example of how to\u00a0make some minor modifications to the above query (scroll down to <samp>Modifying the Query<\/samp>).<\/p>\n<h2>Create a Form<\/h2>\n<p>Now let&#8217;s create a form. We&#8217;ll make it a form that enables users to enter new customers. So when a user enters data into the form, that data will be inserted into the <samp>Customers<\/samp> table.<\/p>\n<p>Access makes it easy to create forms like this. If you select a table or query,\u00a0Access will automatically create\u00a0a form based on the selected object. So to create a form based on the <samp>Customers<\/samp> table, all you need to do is select that table before\u00a0creating the form.<\/p>\n<p>So, ensuring that the <samp>Customers<\/samp> table is selected (in the left navigation frame), click the <samp>Form<\/samp> button from the <samp>CREATE<\/samp> tab on the Ribbon:<\/p>\n<figure id=\"attachment_166\" aria-describedby=\"caption-attachment-166\" style=\"width: 390px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-166\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_1.png\" alt=\"Screenshot of the Form button on the Ribbon in MS Access 2013.\" width=\"400\" height=\"100\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_1.png 400w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_1-300x75.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-166\" class=\"wp-caption-text\">The &#8220;Form&#8221; button on the Ribbon &#8211; under the &#8220;CREATE&#8221; tab. Clicking this button will create a form based on the selected table or query.<\/figcaption><\/figure>\n<p>This creates a\u00a0form based on the selected object (in this case, the <samp>Customers<\/samp> table).<\/p>\n<h3>The Form in Layout View<\/h3>\n<p>The\u00a0form is initially displayed in Layout view. Layout view allows you to set up\u00a0your form while it is populated with real data. You can even enter data while in this view:<\/p>\n<figure id=\"attachment_167\" aria-describedby=\"caption-attachment-167\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-167 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_2.png\" alt=\"Screenshot of form in Layout view in MS Access 2013.\" width=\"600\" height=\"441\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_2.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_2-300x221.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-167\" class=\"wp-caption-text\">After clicking the &#8220;Form&#8221; button, Access generates a form in Layout view. Clicking &#8220;Form View&#8221; (highlighted) will display the form as the user will see it.<\/figcaption><\/figure>\n<p>Go ahead and click <kbd>Form View<\/kbd> from the <samp>View<\/samp> button\/menu. If prompted to save the form, call it <kbd>Customer Form<\/kbd> and click <strong>OK<\/strong>.<\/p>\n<h3>The Form in Form View<\/h3>\n<p>This will display the form as the user will see it.<\/p>\n<figure id=\"attachment_168\" aria-describedby=\"caption-attachment-168\" style=\"width: 290px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-168 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_3.png\" alt=\"Screenshot of form in Form View in Access 2013.\" width=\"300\" height=\"201\" \/><\/a><figcaption id=\"caption-attachment-168\" class=\"wp-caption-text\">This form is in Form View. This is how the user will see the form.<\/figcaption><\/figure>\n<h3>The Form in Design View<\/h3>\n<p>Now switch to <samp>Design View<\/samp> (using the same <samp>View<\/samp> menu\u00a0as before).<\/p>\n<p>This displays the form in a\u00a0more design-oriented way.\u00a0You&#8217;ll see a grid across the background, which helps align elements such as labels, and input controls. You will also notice that no data is displayed in the form. This allows you to make changes without data getting in the way.<\/p>\n<figure id=\"attachment_170\" aria-describedby=\"caption-attachment-170\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-170 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_6.png\" alt=\"Screenshot of the Property Sheet in Design view in MS Access 2013.\" width=\"600\" height=\"442\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_6.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_form_in_access_2013_6-300x221.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-170\" class=\"wp-caption-text\">You can access the property sheet from the Property Sheet button on the Ribbon.<\/figcaption><\/figure>\n<p>The above\u00a0screenshot shows\u00a0<samp>Design View<\/samp>\u00a0with the Property Sheet open and highlighted. You can use this to make specific adjustments to the controls on\u00a0your form.<\/p>\n<p>For example, you can do things such as:<\/p>\n<ul>\n<li>Set a field to &#8220;locked&#8221; so that the user can&#8217;t edit, add, or delete the data. Try doing this to the <samp>CustomerId<\/samp> and <samp>DateCreated<\/samp> fields.<\/li>\n<li>Apply an <a href=\"https:\/\/database.guide\/what-is-the-input-mask-wizard-in-microsoft-access\/\">input mask<\/a>, so that users can&#8217;t enter data in the wrong format.<\/li>\n<li>Change colors, such as background color, border color, font color, etc.<\/li>\n<li>Change fonts and font styles, weights, etc.<\/li>\n<li>Specify the alignment for the text in the form.<\/li>\n<li>Set the height and width of the control.<\/li>\n<li>Show a date picker.<\/li>\n<li>Much\u00a0more.<\/li>\n<\/ul>\n<p>You can also use Design View to click and drag items around, add headers and footers, etc. You can also modify the labels (eg, add a space to\u00a0<samp>FirstName<\/samp> to make it\u00a0<samp>First Name<\/samp>, etc)<\/p>\n<p>Have a play around with the form to see how you can format it. Don&#8217;t be afraid to switch between views\u00a0to see how it looks.<\/p>\n<h2>Create a Macro<\/h2>\n<p>Now we come to macros. A macro is a set of actions that\u00a0can be run\u00a0automatically. For example,\u00a0can have a macro run whenever the user clicks a button, or you can have it run automatically when they\u00a0open the database.<\/p>\n<p>Macros are usually created to simplify common, repetitive tasks.<\/p>\n<p>For example, if you find yourself always opening the <samp>Customers Form<\/samp> every time you open the database, why not create a macro that opens it automatically? That will save you from\u00a0having to find the form and double click on it every single time you open the database.<\/p>\n<p>So, using that example, let&#8217;s go ahead and try it.<\/p>\n<p>Click <kbd>Macro<\/kbd> from the <samp>CREATE<\/samp> tab on the Ribbon.<\/p>\n<figure id=\"attachment_232\" aria-describedby=\"caption-attachment-232\" style=\"width: 156px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-232\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_1.png\" alt=\"Screenshot of the Macro button on the Ribbon in MS Access 2013.\" width=\"166\" height=\"100\" \/><\/a><figcaption id=\"caption-attachment-232\" class=\"wp-caption-text\">The &#8220;Macro&#8221; button on the Ribbon.<\/figcaption><\/figure>\n<p>You will see a\u00a0combo box. Select <kbd>OpenForm<\/kbd> from the combo box:<\/p>\n<figure id=\"attachment_233\" aria-describedby=\"caption-attachment-233\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-233\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_2.png\" alt=\"Screenshot of combo box while creating a macro in Access 2013.\" width=\"600\" height=\"440\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_2.png 600w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_2-300x220.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-233\" class=\"wp-caption-text\">A combo box displaying a list of actions when creating a macro.<\/figcaption><\/figure>\n<p>Here, we customise the <samp>OpenForm<\/samp> action (such as telling it which form to open, which view to open it in, etc). Use these settings:<\/p>\n<figure id=\"attachment_234\" aria-describedby=\"caption-attachment-234\" style=\"width: 491px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-234 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_3.png\" alt=\"Screenshot of the OpenForm dialog in Access 2013.\" width=\"501\" height=\"266\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_3.png 501w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_3-300x159.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><figcaption id=\"caption-attachment-234\" class=\"wp-caption-text\">The above dialog box is for configuring the OpenForm action. This allows you to add any parameters you require for the action.<\/figcaption><\/figure>\n<p>Now select\u00a0another action from the combo box.\u00a0This time select <kbd>GoToRecord<\/kbd>. This will make the form open a new record every time the macro runs.<\/p>\n<figure id=\"attachment_235\" aria-describedby=\"caption-attachment-235\" style=\"width: 494px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-235\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_4.png\" alt=\"Screenshot of creating a second action for a macro in Access 2013.\" width=\"504\" height=\"347\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_4.png 504w, https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_4-300x207.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/a><figcaption id=\"caption-attachment-235\" class=\"wp-caption-text\">Adding another action &#8211; this time using the GoToRecord action. This example is setting the macro to open a new record whenever it is run.<\/figcaption><\/figure>\n<p>Now save the macro by clicking the <kbd>Save<\/kbd> icon. Be sure to name it <kbd>AutoExec<\/kbd>. This\u00a0is a special name that causes the macro to run every time the database is opened.<\/p>\n<figure id=\"attachment_236\" aria-describedby=\"caption-attachment-236\" style=\"width: 258px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-236\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/05\/create_a_macro_in_access_2013_5.png\" alt=\"Screenshot of saving a macro in MS Access 2013.\" width=\"268\" height=\"114\" \/><\/a><figcaption id=\"caption-attachment-236\" class=\"wp-caption-text\">Saving the macro as &#8220;AutoExec&#8221;. By using this name, the macro will be run every time the user opens the database.<\/figcaption><\/figure>\n<p>This macro should now run every time the database is opened.\u00a0Test it out. Close the database, then open it again. You should see the <samp>Customers Form<\/samp> open at a new record, ready for a new customer to be entered.<\/p>\n<h3>Clicking a Button to Run a Macro<\/h3>\n<p>You probably won&#8217;t want\u00a0all your macros running every time the database opens. You might not want <em>any<\/em> running every time the database opens.<\/p>\n<p>One option is to create a button for the macro. So, the macro won&#8217;t run until the user clicks the button.<\/p>\n<p>Here&#8217;s\u00a0<a href=\"https:\/\/database.guide\/how-to-add-a-macro-button-to-a-form-in-access\/\">how to\u00a0add a macro button to a form<\/a>\u00a0so that the macro\u00a0only runs when the button is clicked.<\/p>\n<h2>Previously<\/h2>\n<p>Return to\u00a0<a href=\"https:\/\/database.guide\/microsoft-access-tutorial-part-2-design-view-field-properties-relationships\/\">Part 2: Design View, Field Properties, &amp; Relationships<\/a>.<\/p>\n<p>Return to\u00a0<a href=\"https:\/\/database.guide\/microsoft-access-tutorial-part-1-databases-tables-fields\/\">Part 1: Databases, Tables, &amp; Fields<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is Part 3 of the Microsoft Access tutorial. Here&#8217;s what&#8217;s included in this article: Create a query (so you can &#8220;search\u00a0the database&#8221;). Create a form for data entry. Create a macro (so that a multi-step task can be done automatically &#8211; at the click of a button).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[14,15,22,8,33],"class_list":["post-772","post","type-post","status-publish","format-standard","hentry","category-microsoft-access","tag-create-form","tag-create-query","tag-macros","tag-ms-access","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=772"}],"version-history":[{"count":7,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":794,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/772\/revisions\/794"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}