Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows 7

Microsoft Access 2010 : Enhancing the Queries That You Build - Everything You Need to Know About Query Basics

8/2/2014 9:38:15 PM

Creating a basic query is easy because Microsoft has provided a user-friendly, drag-and-drop interface. To start a new query, select Query Design from the Other group of the Create tab of the Ribbon; the Show Table dialog appears (see Figure 1). If you prefer, you can select Query Wizard from the Other group of the Create tab of the Ribbon. In that case the New Query dialog appears, allowing you to select from four predefined query wizards (see Figure 2). The Simple Query Wizard walks you through the steps of creating a basic query. The other wizards help you create three specific types of queries: Crosstab, Find Duplicates, and Find Unmatched queries.

Figure 1. The Show Table dialog box.


Figure 2. The New Query dialog box.


Adding Tables to Queries

If you choose to use Design view rather than one of the wizards, the Show Table dialog box appears (refer to Figure 1). In this dialog box, you can select the tables or queries that supply data to a query. Access doesn’t care whether you select tables or queries as the foundation for queries. You can select a table or query by double-clicking the name of the table or query you want to add or by single-clicking the table and then selecting the Add command button. You can select multiple tables or queries by holding down the Shift key while you select a contiguous range of tables or the Ctrl key while you select noncontiguous tables. After you have selected the tables or queries you want, you click Add and then click Close. This brings you to the Query Design window, shown in Figure 3.

Figure 3. The Query Design window.

Adding Fields to Queries

After you add tables to a query, you can select the fields you want to include in the query. The query shown in Figure 3 is based on the Customers table from the Northwind database that ships with Microsoft Access. Notice that the query window is divided into two sections: The top half of the window shows the tables or queries that underlie the query you’re designing, and the bottom half shows any fields that you will include in the query output. You can add a field to the query design grid on the bottom half of the query window in several ways:

  • You can double-click the name of the field you want to add.

  • You can click and drag a single field from the table in the top half of the query window to the query design grid below.

  • You can select multiple fields at the same time by using the Shift key (for a contiguous range of fields) or the Ctrl key (for a noncontiguous range). You can double-click the title bar of the field list to select all fields and then click and drag any one of the selected fields to the query design grid.


You can double-click the asterisk in the field list to include all fields within the table in the query result. Although this is very handy in that changes to the table structure magically affect the query’s output, this “trick” is dangerous. When you select the asterisk, you include all table fields in the query result, whether you need them or not. This can cause major performance problems in a local area network (LAN), wide area network (WAN), or client/server application.


The easiest way to run a query is to click the Run button on the toolbar. (It looks like an exclamation point.) You can click the Query View button to run a query, but this method works only for Select queries, not for Action queries. The Query View button has a special meaning for Action queries . Clicking Run is preferable because when you do that, you don’t have to worry about what type of query you’re running. After you run a Select query, you should see what looks like a datasheet that contains only the fields you selected. To return to the query’s design, you click the Query View button.


Access 2002 introduced shortcut keys that allow you to easily toggle between the various query views: Ctrl+>, Ctrl+period, Ctrl+<, and Ctrl+comma. Ctrl+> and Ctrl+period take you to the next view; Ctrl+< and Ctrl+comma take you to the previous view.


Removing a Field from the Query Design Grid

To remove a field from the query design grid, follow these steps:

1.
Find the field you want to remove.

2.
Click the column selector (that is, the small horizontal gray button) immediately above the name of the field. The entire column of the query design grid should become black (see Figure 4).

Figure 4. Removing a field from the query design grid.

3.
Press the Delete key or select Delete from the Edit menu. Access removes the field from the query.

Inserting a Field After a Query Is Built

The process for inserting a field after you have built a query depends on where you want to insert the new field. If you want to insert it after the existing fields, it’s easiest to double-click the name of the field you want to add. If you prefer to insert the new field between two existing fields, it’s best to click and drag the field you want to add and drop it onto the field you want to appear to the right of the inserted field.

Moving a Field to a Different Location on the Query Design Grid

Although the user can move a column while in a query’s Datasheet view, sometimes you want to permanently alter the position of a field in the query output. You can do this as a convenience to the user or, more importantly, to use the query as a foundation for forms and reports. The order of the fields in the query becomes the default order of the fields on any forms and reports you build by using any of the wizards. You can save yourself quite a bit of time by ordering queries effectively.

To move a single column, follow these steps:

1.
Select a column while in the query’s Design view by clicking its column selector.

2.
Click the selected column a second time, and then drag it to a new location on the query design grid.

Move More Than One Column

Follow these steps to move more than one column at a time:

1.
Drag across the column selectors of the columns you want to move.

2.
Click any of the selected columns a second time, and then drag them to a new location on the query design grid.

Moving a column in Datasheet view doesn’t modify the query’s underlying design. If you move a column in Datasheet view, subsequent reordering in Design view isn’t reflected in Datasheet view. In other words, Design view and Datasheet view are no longer synchronized, and you must reorder both manually. This actually serves as an advantage in most cases. If you want to sort by the Country field and then by the CompanyName field, the Country field must appear to the left of the CompanyName field in the design of the query. If you want the CompanyName field to appear to the left of the Country field in the query’s result, you must make that change in Datasheet view. The fact that Access maintains the order of the columns separately in both views allows you to easily accomplish both objectives.



Saving and Naming Queries

To save a query at any time, you can click the Save button on the toolbar. If the query is a new one, Access prompts you to name the query.

Access supplies default names for the queries that you create (for example, Query1, Query2). I suggest that you supply a more descriptive name. A query name should begin with qry so that you can easily recognize and identify it as a query.


It’s important to understand that when you save a query, you’re saving only the query’s definition, not the actual query result.

Other -----------------
- Using the Windows 7 Libraries : USING THE EXPLORER BROWSER CONTROL (part 2)
- Using the Windows 7 Libraries : USING THE EXPLORER BROWSER CONTROL (part 1) - Adding the Explorer Browser to Your Toolbox , Configuring the Explorer Browser Example
- Using the Windows 7 Libraries : CONSIDERING USER-DEFINED COLLECTIONS
- Using the Windows 7 Libraries : USING NON-FILESYSTEM CONTAINERS
- Using the Windows 7 Libraries : WORKING WITH KNOWN FOLDERS
- Conducting Research in OneNote 2010 : Translating Text
- Conducting Research in OneNote 2010 : Researching a Topic, Customizing the Research Task Pane
- Conducting Research in OneNote 2010 : Handling the Research Task Pane
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Macro Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting ActiveX Security Options
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro