4. MICROSOFT ACCESS QUERIES

4.1: Simple Query

The simplest query is one that displays a complete table – all rows and columns. Suppose we want to list all books in the library. The process of creating the query is as follows:

      • Click on the Create tab if necessary and then click on the Query Design icon; then:
      • drag the Book table from the Tables panel into the Relationships area, or,
      • right-click in the Relationships area and choose the Show Table. Double-click Book.
image
                                          Figure 4.3: Select a table for the query

MS Access displays the Book table and its fields in the Relationships area. The first in this list is an * which stands for all attributes – double-click the *. Note the contents of the Grid area:

 

image
          Figure 4.4: Choosing all fields of the table

You can run a query when using Query Design view. If the Run button is not visible, click the “Design” tab. Now, to run the query, click the “Run” button in the “Results” button group:

 

image
                                                    Figure 4.5: Run a query

There are other views of a query. If you click the drop-down just below View:

image
 Figure 4.6: Several views for a query

You can see all the ways of viewing a query, including:

      • Datasheet View
      • Design View
      • SQL View.

You can run a query by choosing Datasheet View. When developing a query, one often alternates between Datasheet View and Design View to get the query working as required. When you run a query, MS Access will retrieve the information requested. Our results of running the query are:

 

image
                                                  Figure 4.7: Query results

You can save the query: right-click the name and then give the query a new name:

image
                              Figure 4.8a: Save a query and give it a name “List all books”

Now, provided you have selected ‘All Access Objects’ you will see the query as a database object. See figure 4.8b.

 

Figure 4.8b: The drop-down determines what objects you see

The query can be run any time by an end user. The results of the query are not stored or saved – only the definition of the query. Whenever a user runs the query the current contents of the Book table are accessed.

License

Share This Book