From the create tab, select the macro button in the other group when you want to create a macro. I am going to open an existing query for this first macro.  When I run this, I see the majorQuery that I created.


When I want to change the macro, I open it in design view.  Below you can see the saved query with the name I gave it, openMajorQuery.


Now I am going to add another action where I am going to find a particular record. When I run the query the record I want to find will be highlighted and the cursor points to it. The action I use is FindRecord.  The record I want to find is 12567.

 



Now I am going to create another macro.  I am going to create a from that will contain the information on the query, I am then going to have the macro open the form and go to the last record.  Remember, a macro is simply of sequence of actions that the developer puts together to form a particular task. First, I used the wizard and created a simple form. Then I started a new Macro using create and picked the Actions I wanted to do from the Action list.  The first Action I wanted to do was Open the Form (OpenForm) and the second action was go to the last record.  For each Action, I fill in the Action Arguments at the bottom of the form and Access then writes the Arguments on the list.


This shows the first Action, now I am going to have the go to last action.

 

 

 

 

 

 

 

 

 

 


When I executed this macro, it opened the form and went to the last record on the form.

I now went in and started a new macro where I am going to create conditions so I needed to have macro name and conditions.

 

 

 

 

 


I am going to write a macro to check and see if the state is there, so first I went back and removed the state from the record where the city was Wareham.  Then I created the Student form with information from the student table. Below is the Macro – I am giving you two views to see the setting up of the last two commands – the form open simply opened the Student form that I just created.


Note the IsNull test on the form.  It is specifically testing the stuState field on the Student form which is on Forms (type of object).  The ! Is the bang notation which basically sets it so it know we are dealing with Forms, specifically the Student form and the field stuState on that form.  On the next picture, note the ellipsis in the line that called for the close. This means if the condition is true, this line will be executed.  Note that I need to make this macro test – run it – on each record as I move through the form.  I need to test each record individually.  Not very practical so I will improve it later.


Note that I need to run the Macro on each record as it appears in the form. I am now going to Run and show you the result. After the msgbox is shown, and I click OK, the form will close.  For the others this did not happen.

 

 

 

 



To automate this process, I will put a button on the form that will execute the macro CheckState automatically.  This means the person can click the button to check. Now obviously with something like state null they really do not need this, but there are other times when they will have something more complex. I am now adding the button to the form.


On the next wizard screen, I picked the CheckState macro and labeled with text etc.  Now I have the macro button and I can click it for each form.

 

 

 

 



Now I can click on the Run Macro button when I move through the forms.

 

 

 

 

 

 

 



Now I want to write a macro that will allow me to search for something.  I decided to use city. First I needed to create a query of distinct cities so I would have a list of the cities I needed to search for. I created a simple SQL query for distinct cities. Then I needed to establish a form that would allow me to do a search for a particular city using the cities in the distinct list.


I am now making a form with a combo box. Before I move in the combo box and the rectangle around it, I make sure that the wizard is on. I am selection the option that I want the wizard to look up values in a table or query.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 


 


I then went on and selected the stuCity which was the only city available because of the nature of the query. I am now setting up a group macro I named FindCity.  It is going to contain other macros related to finding the city.


The first macro in the group is OpenCityDialog and it has an action of open form and I selected the form as shown below.

I then went on to write the rest of the group macro as shown here.  I would strongly suggest that you look at these in the actual database to see the details.  After I wrote the group macro FindCity, I went back to the forms put buttons on the forms to execute the macros. Again, please look at the actual database for more detailed information.

 

 

 

 

 

 


Note that I had the control wizard on when I am doing this.

The previous button on the student form got changed to Check State and the button to execute the FindCity macros is named Find City.

 

 

 


When I click on FindCity, the form with the choice of city comes up.

 

 

 

 

 



Then I click on Do Search.


The first record with Providence comes up. I can move through because they are sorted in order.