Académique Documents
Professionnel Documents
Culture Documents
A database is a tool for collecting and organizing information. Databases can store information about people, products, orders, or anything else. Many databases start as a list in a word-processing program or spreadsheet. As the list grows bigger, redundancies and inconsistencies begin to appear in the data. The data becomes hard to understand in list form, and there are limited ways of searching or pulling subsets of data out for review. Once these problems start to appear, it's a good idea to transfer the data to a database created by a database management system (DBMS), such as Office Access 2007.
A computerized database is a container of objects. One database can contain more than one table. For example, an inventory tracking system that uses three tables is not three databases, but one database that contains three tables. Unless it has been specifically designed to use data or code from another source, an Access database stores its tables in a single file, along with other objects, such as forms, reports, macros, and modules. Databases created in the Access 2007 format have the file extension .accdb, and databases created in earlier Access formats have the file extension .mdb. You can use Access 2007 to create files in earlier file formats (for example, Access 2000 and Access 2002-2003).
Edit existing data in the database, such as changing the current location of an item
Share the data with others via reports, e-mail messages, an intranet , or the Internet
Tables
Tables
A database table is similar in appearance to a spreadsheet, in that data is stored in rows and columns. As a result, it is usually quite easy to import a spreadsheet into a database table. The main difference between storing your data in a spreadsheet and storing it in a database is in how the data is organized.
A table contains data about a particular subject, such as employees or products. Each record in a table contains information about one item, such as a particular employee. A record is made up of fields, such as name, address and telephone number. A record is also commonly called a row, and a field is also commonly called a column.
Record or row
Field or column
Your database can contain many tables, each storing information about a different subject. Each table can contain many fields of different types, including text, numbers, dates, and pictures.
The following list shows some common examples of tables you might create.
A customers table that lists your companys customers and their addresses
A catalog of products you sell, including prices and pictures for each item
You should plan and design your database carefully to ensure its correctness and to avoid having to make too many changes later.
Forms
Forms are sometimes referred to as "data entry screens." They are the interfaces you use to work with your data, and they often contain command buttons that perform various commands. You can create a database without using forms by simply editing your data in the table datasheets. However, most database users prefer to use forms for viewing, entering, and editing data in the tables.
Forms provide an easy-to-use format for working with the data, and you can also add functional elements, such as command buttons, to them. You can program the buttons to determine which data appears on the form, open other forms or reports, or perform a variety of other tasks. For example, you might have a form named "Customer Form" in which you work with customer data. The customer form might have a button which opens an order form where you can enter a new order for that customer.
Forms also allow you to control how other users interact with the data in the database. For example, you can create a form that shows only certain fields and allows only certain operations to be performed. This helps protect data and to ensure that the data is entered properly.
Reports
Reports are what you use to summarize and present data in the tables. A report usually answers a specific question, such as "How much money did we receive from each customer this year?" or "What cities are our customers located in?" Each report can be formatted to present the information in the most readable way possible.
A report can be run at any time, and will always reflect the current data in the database. Reports are generally formatted to be printed out, but they can also be viewed on the screen, exported to another program, or sent as email message.
Queries
Queries are the real workhorses in a database, and can perform many different functions. Their most common function is to retrieve specific data from the tables. The data you want to see is usually spread across several tables, and queries allow you to view it in a single datasheet. Also, since you usually don't want to see all the records at once, queries let you add criteria to "filter" the data down to just the records you want. Queries often serve as the record source for forms and reports.
Certain queries are "updateable," meaning you can edit the data in the underlying tables via the query datasheet. If you are working in an updateable query, remember that your changes are actually being made in the tables, not just in the query datasheet.
Queries come in two basic varieties: select queries and action queries. A select query simply retrieves the data and makes it available for use. You can view the results of the query on the screen, print it out, or copy it to the clipboard. Or, you can use the output of the query as the record source for a form or report.
An action query, as the name implies, performs a task with the data. Action queries can be used to create new tables, add data to existing tables, update data, or delete data.
Macros
Macros in Access can be thought of as a simplified programming language which you can use to add functionality to your database. For example, you can attach a macro to a command button on a form so that the macro runs whenever the button is clicked. Macros contain actions that perform tasks, such as opening a report, running a query, or closing the database. Most database operations that you do manually can be automated by using macros, so they can be great time-saving devices.
Modules
Modules, like macros, are objects you can use to add functionality to your database. Whereas you create macros in Access by choosing from a list of macro actions, you write modules in the Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) programming language. A module is a collection of declarations, statements, and procedures that are stored together as a unit. A module can be either a class module or a standard module. Class modules are attached to forms or reports, and usually contain procedures that are specific to the form or report they're attached to. Standard modules contain general procedures that aren't associated with any other object. Standard modules are listed under Modules in the Navigation Pane, whereas class modules are not.
You can create a table by creating a new database, by inserting a table into an existing database, or by importing or linking to a table from another data source such as a Microsoft Office Excel 2007 workbook, a Microsoft Office Word 2007 document, a text file, or another database. When you create a new blank database, a new empty table is automatically inserted for you. You can then enter data to start defining your fields.
2.
In the File Name box, type a file name. To change the location, click the folder icon to browse.
3.
Click Create.
The new database is opened, and a new table named Table1 is created and opened in Datasheet view.
2.
3.
A new table is inserted in the database and the table is opened in Datasheet view.
Top of Page
1.
2.
3.
On the Create tab, in the Tables group, click Table Templates and then select one of the available templates from the list.
Top of Page
NOTE
In some cases, you cannot make changes to your data source through a linked table, most notably when
2.
3.
In the File Name text box, type a file name. To change the location, click the folder icon.
Click Create.
The new database is opened, and a new table named Table1 is created and opened in Datasheet view.
4.
On the External Data tab, in the Import group, click one of the available data sources.
5.
Access creates the new table and displays it in the Navigation Pane.
It is important that you choose fields carefully. For example, it's usually a bad idea to create a field to store a calculated value. You can usually have Office Access 2007 calculate the value when needed instead. When choosing
fields, try to store information in its smallest useful parts. For instance, instead of a FullName, consider storing a LastName and a FirstName. Generally speaking, if you need to report, sort, search or calculate on an item of information, put it in a column by itself. For more information about designing a database and choosing fields, see the article Database design basics.
A field has certain defining characteristics. For example, every field has a Name that uniquely identifies the field within a table. A field also has a data type that's chosen to match the information to be stored. The data type determines the values that can be stored and the operations that can be performed, as well as how much storage space to set aside for each value. Every field also has an associated group of settings called properties that define the appearance or behavior characteristics of the field. For example, the Format property defines a field's display layout that is, how it should appear when displayed.
When you create a new table, the table opens in Datasheet view. You can immediately add a field by typing some information in the Add New Field column.
2.
3.
In the Navigation Pane, double-click one of the available tables to open it.
4.
Type your data in the cell below the Add New Field column header.
2.
3.
Access inserts a new table in the database and opens it in Datasheet view.
4.
Type your data in the cell below the Add New Field column header.
When you enter data in the new column, Office Access 2007 uses the information you type to recognize the appropriate data type for the field. For example, if you type a date in the column, such as 1/1/2006, Office Access 2007 sees the information you entered, recognizes it as a date, and sets the data type for the field to Date/Time. If Access doesn't have enough information from what you enter to guess the data type, the data type is set to Text.
The following table shows how automatic data type detection works in Datasheet view.
If you type: John http://www.contoso.com You can use any valid Internet protocol prefix. For example, http://, https://, and mailto: are valid prefixes.
Office Access 2007 creates a field with a data type of: Text Hyperlink
50000 50,000 50,000.99 50000.389 12/31/2006 The date and time formats recognized are those of your user locale.
Number, Long Integer Number, Long Integer Number, Double Number, Double Date/Time
17:50 $12.50 The currency symbol recognized is that of your user locale.
Date/Time Currency
In addition to determining the data type, Office Access 2007 may set the Format property, depending on what you enter. For example, if you type 10:50 am, Access sets the data type Date/Time and the Format property to Medium Time.
If you want to explicitly set the data type and format for a field, overriding the choice that Office Access 2007 makes, you can do so by using the commands in the Data Type & Formatting group on the Datasheet tab.
2.
2.
When you add a field by typing information into the cell below the Add New Field header, Office Access 2007 automatically assigns a name to the field. These names start with Field1 for the first field, Field2 for the second field, and so on. It is a good practice to use more descriptive field names. You can rename the field by right-clicking its header, and then clicking Rename Column on the shortcut menu.
Field names can consist of up to 64 characters (letters or numbers), including spaces. You should try to give fields descriptive names so that you can easily identify them when you view or edit records. For example, you might use field names such as Last Name, Address, and Home Phone.
Top of Page
A field template is a predefined set of characteristics and properties that describes a field. The field template definition includes a field name, a data type, a setting for the field's format property, and also a number of other field properties that, when taken together, form a model that serves as the basis for creating a new field.
1.
2.
On the Datasheet tab, in the Fields & Columns group, click New Field.
3.
Select one or more fields in the Field Templates pane and drag them to the table. When the insertion line appears, drop the fields in position.
Field templates are models. They provide a basis from which you can create a new field. But it is not the only basis from which you can create a new field. In addition to creating a new field from a field template, you can also create a new field from an existing field in another table.
Top of Page
1.
2.
3.
In the Navigation Pane, double-click the table in which you want to add an existing field.
4.
On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
The Field List pane lists all of the other tables in your database, grouped into categories. When you work with a table in Datasheet view, two categories appear in the Field List pane: Fields available in related tables, and Fields available in other tables. The first category lists all of the tables with which the table you have open has a relationship. The second category lists all of the tables with which your table does not have a relationship.
For more information about table relationships, see the article Create, edit or delete a relationship.
When you click the plus sign (+) next to a table to, you see a list of all of the fields available in that table. To add a field to your table, drag and drop the field you want from the Field List pane to the table in Datasheet view.
2.
3.
In the Navigation Pane, double-click the table in which you want to add an existing field.
4.
On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
5.
Click the plus sign (+) next to a table to display the list of fields in that table.
6.
Drag the field you want from the Field List pane to the table in Datasheet view.
7.
8.
After you have completed the wizard, the field appears in the table in Datasheet view.
NOTE
When you drag and drop a field from an unrelated table and then complete the Lookup Wizard, a new one-
to-many relationship is automatically created between the table in the Field List pane and the table you have open.
Top of Page
If you want to explicitly set the data type and format for a field, overriding the choice that Office Access 2007 makes, you can do so by using the commands in the Data Type & Formatting group on the Data tab.
2.
2.
The following table describes the data types available for fields in Office Access 2007.
Stores Alphanumeric characters Use for text, or text and numbers that are not used in calculations (for example, a product ID).
Memo
Alphanumeric characters (longer than 255 characters in length) or text with rich text formatting. Use for text greater than 255 characters in length, or for text that uses rich text formatting. Notes, lengthy descriptions, and paragraphs with formatting such as bold or italics are good examples of where you would use a Memo field.
Up to 1 gigabyte of characters, or 2 gigabytes of storage (2 bytes per character), of which you can display 65,535 characters in a control.
Number
Numeric values (integers or fractional values). Use for storing numbers to be used in calculations, except for monetary values (use the Currency for data type for
monetary values).
Date/Time
Dates and times. Use for storing date/time values. Note that each value stored includes both a date component and a time component.
8 bytes.
Currency
8 bytes.
AutoNumber
A unique numeric value that Office Access 2007 automatically inserts when a record is added. Use for generating unique values that can be used as a primary key. Note that AutoNumber fields can be incremented sequentially, by a specified increment, or chosen randomly.
Yes/No
Boolean values. Use for True/False fields that can hold one of two possible values: Yes/No or True/False, for example.
OLE Object
OLE objects or other binary data. Use for storing OLE objects from other Microsoft Windows applications.
Up to 1 gigabyte.
Attachment
Pictures, Images, Binary files, Office files. This is the preferred data type for storing digital images and any type of binary file.
For compressed attachments, 2 gigabytes. For uncompressed attachments, approximately 700k, depending on the degree to which the attachment can be compressed.
Hyperlink
Hyperlinks. Use for storing hyperlinks to provide single-click access to Web pages through a URL (Uniform Resource Locator) or files through a name in UNC (universal naming convention) format. You can also link to Access objects stored in a database.
Up to 1 gigabyte of characters, or 2 gigabytes of storage (2 bytes per character), of which you can display 65,535 characters in a control.
Lookup Wizard
Not actually a data type; instead, this invokes the Lookup Wizard. Use to start the Lookup Wizard so you can create a field that uses a combo box to look up a value in another table, query or list of values.
Table or query based: The size of the bound column. Value based: The size of the Text field used to store the value.
TIP
For phone numbers, part numbers, and other numbers you dont intend to use for mathematical calculations, you
should select the Text data type, not the Number data type.
For the Text and Number data types, you can specify the field size or data type more specifically by setting a value in the FieldSize property box.
Top of Page
Save a table
After you add fields to a table, you should save its design. When you save a new table for the first time, give it a name that describes the information it contains. You can use up to 64 characters (letters or numbers), including spaces. For example, you might name a table Customers, Parts Inventory, or Products.
1.
-or-
Right-click the table's document tab, and then click Save on the shortcut menu.
-or-
2.
If you are saving the table for the first time, type a name for the table, and then click OK.
Top of Page
A good candidate for the primary key has several characteristics. First, it uniquely identifies each row. Second, it is never empty or null there is always a value. Third, it rarely (ideally never) changes. Access uses primary key fields to quickly bring together data from multiple tables.
You should always specify a primary key for a table. Access automatically creates an index for the primary key, which helps speed up queries and other operations. Access also ensures that every record has a value in the primary key field, and that it is always unique.
When you create a new table in Datasheet view, Access automatically creates a primary key for you and assigns it a field name of ID and the AutoNumber data type. The field is hidden in Datasheet view, but you can see it if you switch to Design view.
- or -
Right-click the table name in the Navigation Pane, and then click Design View.
- or -
To change or remove the primary key, or to set the primary key for a table that doesn't already have one, you must use Design view.
2.
Select the field or fields you want to use as the primary key.
To select one field, click the row selector for the field you want.
To select more than one field, hold down the CTRL key and then click the row selector for each field.
3.
A key indicator is added to the left of the field or fields that you specify as the primary key.
2.
If the primary key consists of a single field, click the row selector for that field.
If the primary key consists of multiple fields, click the row selector for any field in the primary key.
3.
The key indicator is removed from the field or fields you previously specified as the primary key.
NOTE
When you save a new table without setting a primary key, Access prompts you to create one. If you choose
Yes, Access creates an ID field that uses the AutoNumber data type to provide a unique value for each record. If your table already includes a AutoNumber field, Access uses it as the primary key.
Top of Page
The data type of the field determines the properties you can set. For example, the AppendOnly property applies only to a field that is set to the Memo data type. You cannot set this property on a field with any other data type.
Access uses the field property settings when you view and edit data. For example, the Format, InputMask, and Caption properties affect how your information appears in table and query datasheets. In addition, any controls on new forms and reports that are based on the fields in the table inherit these same property settings by default. You use other properties to set a default value for a field or to require a user to enter a value, which Access enforces whenever you add or edit data in the table.
2.
Click in the field for which you want to set the property.
3.
On the Datasheet tab, in the Data Type & Formatting group, select one of the following commands:
4.
Is Required Toggles the setting of the Required property. If it was set to Yes, it is set to No. If it was set to No, it is set to Yes.
You can set only a few of the available field properties in Datasheet view. To set additional field properties, you must open the table in Design view.
To have access to and set the complete list of field properties, you must use Design view.
2.
In the upper portion of the table design grid, click the field for which you want to set properties (or move to the field by using the arrow keys).
3.
Access displays the properties for this field in the lower portion of the table design grid. The data type of the field determines the properties you can set.
4.
In the lower portion of the window, under Field Properties, click the box for the field property you want to set. Alternatively, you can press F6 and then move to the property by using the arrow keys.
5.
Type a setting for the property or, if an arrow appears at the right side of the property box, click the arrow to choose from a list of settings for the property.
Use this field property FieldSize Format DecimalPlaces NewValues InputMask Caption DefaultValue ValidationRule ValidationText Required AllowZeroLength Indexed UnicodeCompression IMEMode IMESentenceMode SmartTags AppendOnly
To Set the maximum size for data stored as a Text, Number, or AutoNumber data type. Customize the way the field appears when displayed or printed. Specify the number of decimal places to use when displaying numbers. Set whether an AutoNumber field is incremented or assigned a random value. Display editing characters to guide data entry. Set the text displayed by default in labels for forms, reports, and queries. Automatically assign a default value to a field when new records are added. Supply an expression that must be true whenever you add or change the value in this field. Enter text that appears when a value violates the ValidationRule expression. Require that data be entered in a field. Allow entry (by setting to Yes) of a zero-length string ("") in a Text or Memo field. Speed up access to data in this field by creating and using an index. Compress text stored in this field when a large amount of text is stored (> 4,096 characters) Control conversion of characters in an Asian version of Windows. Control conversion of characters in an Asian version of Windows. Attach a smart tag to this field. Allow versioning (by setting to Yes) of a Memo field.
TextFormat
Choose Rich Text to store text as HTML and allow rich formatting. Choose Plain Text to store only text. Specify the default alignment of text within a control. Specify the total number of digits allowed, including those both to the right and the left of the decimal point. Specify the maximum number of digits that can be stored to the right of the decimal separator.
TextAlign Precision
Scale
If you want more space to enter or edit a property setting in the property box, press SHIFT+F2 to display the Zoom box. If you are entering an input mask or validation expression and would like help in building it, click next to the property box to display the appropriate builder.
6.
-or-
Right-click the table's document tab, and then click Save on the shortcut menu.
-or-
The following table provides additional information about the FieldSize, Format and New Values field properties.
Description Enter a value from 1 to 255. Text fields can range from 1 to 255 characters. For larger text fields, use the Memo data type. Select one of the following: Byte For numeric values that range from 0 to 255. Storage requirement is a single byte.
Number
Integer For numeric values that range from -32,768 to +32,768. Storage requirement is two bytes. Long Integer For numeric values that range from -2,147,483,648 to +2,147,483,647. Storage requirement is four bytes. TIP Use Long Integer for storing as a foreign key the value that appears in another table's primary key AutoNumber field.
Single For numeric floating point values that range from -3.4 x 1038 to +3.4 x 1038 and up to seven significant digits. Storage requirement is four bytes. Double For numeric floating point values that range from -1.797 x 10 308 to +1.797 x 308 10 and up to fifteen significant digits. Storage requirement is eight bytes. Replication ID For storing a globally unique identifier required for replication. Storage requirement is sixteen bytes. Note that replication is not supported using the .accdb file format. Decimal For numeric values that range from -9.999... x 1027 to +9.999... x 1027. Storage requirement is twelve bytes.
AutoNumber
Select one of the following: Long Integer For unique, numeric values that range from 1 to +2,147,483,648 when the New Values field property is set to Increment, and -2,147,483,648 to +2,147,483,647 when the New Values field property is set to Random. Storage requirement is four bytes. Replication ID For storing a globally unique identifier required for replication. Storage requirement is sixteen bytes. Note that replication is not supported using the .accdb file format.
Format property Text You can define a custom format. For more information, see Format data in tables, forms, and reports. Select one of the following: General Number Displays the number as entered.
Number
For example, 3456.789 becomes 3456.789 Currency Displays the number using the thousand separator, and applies the settings in the Regional and Language Options in the Control Panel for negative amounts, decimal and currency symbols, and decimal places. For example, 3456.789 becomes $3,456.79 Euro Displays the number using the Euro currency symbol, regardless of the symbol specified in the Regional and Language Options. Fixed Displays at least one digit and applies the settings in the Regional and Language Options in the Control Panel for negative amounts, decimal and currency symbols, and decimal places. For example, 3456.789 becomes 3456.79 Standard Displays the number using the thousand separator and applies the settings in the Regional and Language Options in the Control Panel for negative amounts, decimal symbols, and decimal places. This format does not display a currency symbol. For example, 3456.789 becomes 3,456.79 Percent Multiplies the value by 100 and displays the number with a percent sign added to the end. Applies the settings in the Regional and Language Options in the Control Panel
for negative amounts, decimal symbols, and decimal places. For example, 0.3456 becomes 35% Scientific Displays the value in standard scientific notation.
Date/Time
Select one of the following predefined display formats: General Date settings. Displays the value using a combination of the Short Date and Long Time
Long Date Displays the value using the Long Date setting from the Regional and Language Options settings in the Control Panel. Medium Date Displays the value using the format dd-mmm-yy (14-Jul-06, for example).
Short Date Displays the value using the Short Date setting from the Regional and Language Options in the Control Panel. Long Time Displays the value using the Time setting in the Regional and Language Options in the Control Panel. Medium Time Displays the value using the format HH:MM PM where HH is the hour, MM is the minute, and PM is either AM or PM. The hour can range from 1 to 12. The minute can range from 0 to 59. Short Time Displays the value using the format HH:MM where HH is the hour and MM is the minute. The hour can range from 0 to 23 and the minute from 0 to 59.
Yes/No
Select one of the following: True/False Yes/No On/Off NOTE Displays the value as either True or False. Displays the value as either Yes or No. Displays the value as either On or Off.
In the above, On, True and Yes are equivalent. False, No and Off are also equivalent.
New Values property AutoNumber Select one of the following (for the AutoNumber data type only): Increment Random Start value at 1 and increment by 1 for each new record. Start with a random value and assign a random value to each new record.
Top of Page
2.
3.
4.
LinkChildFields
LinkMasterFields SubdatasheetHeight
SubdatasheetExpanded Orientation
Set whether to expand all subdatasheets when you open the table. Set the view orientation, according to whether your language is read left-to-right, or right-toleft. Specify whether forms and reports associated with this table should be available on the View menu in Windows SharePoint Services if the database is published to a SharePoint site. Automatically apply the filter criteria in the Filter property (by setting to Yes) when the table is opened in Datasheet view. Automatically apply the sort criteria in the OrderBy property (by setting to Yes) when the table is opened in Datasheet view.
DisplayViewsOnSharePoint
FilterOnLoad
OrderByOnLoad
If you want more space to enter or edit a setting in the property box, press SHIFT+F2 to display the Zoom box. If you are setting the ValidationRule property to an expression and would like help in building it, click next to the ValidationRule property box to display the Expression Builder.
5.
-or-
Right-click the table's document tab, then click Save on the shortcut menu.
-or-
You set the field size by opening the table in Design view and changing the Field Size property. For information about changing the properties of a Number field, see the section Set or change field properties. For information about the field properties, see the section Number field property reference.
The following table lists the values that each Field Size setting can contain and explains when to use each size setting.
Description A 1-byte integer containing values from 0 to 255. A 2-byte integer containing values from -32,768 to +32,767. A 4-byte integer containing values from -2,147,483,648 to 2,147,483,647. A 4-byte integer containing values from -3.4 x 10 38 to +3.4 x 10 38 and up to 7 significant digits. An 8-byte floating point number containing values from -1.797 x 10308 to +1.797 x 10308 and up to 15 significant digits. A 16-byte globally unique identifier (GUID). Randomly generated GUIDs are long enough that they are not likely to overlap. You use them for a variety of applications, such as tracking goods. A 12-byte integer with a defined decimal precision that can contain values from -1028 to +1028. The default precision is 0. The default scale (the number of decimal places displayed) is 18. You can set the scale up to 28.
Replication ID
Decimal
In addition to setting field sizes and other field properties, you can apply custom and predefined display formats and input masks to your number data.
For more information about formatting Number data, see the article Format data in tables, forms, and reports. For information about input masks, see the article Create an input mask to enter field or control values in a specific format.
Datasheet view You can add a Number field to a new or existing table in Datasheet view by adding a new field and then typing a number into a blank row in the field, or by pasting a number into a blank row. You can also select the Number data type from a drop-down list and set properties such as Is Required, which forces users to enter a date in the field, and Unique, which forces users to enter a non-duplicate value in the field.
Design view You use Design view to add a Number field and set properties for the field that you cannot set in Datasheet view. Those properties include input masks and a default value for the field. For more information about the properties, see the section Number field property reference.
Top of Page
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
If necessary, scroll horizontally to the first blank field. By default, Access displays Add New Field in the header row of all new fields, like so:
5.
Double-click the header row, and then type a name for the new field.
6.
Select the first blank row under the header, and then type or paste a block of numbers. Access infers the Number data type for the field when you enter numbers or paste numbers.
-or-
On the Datasheet tab, in the Data Type & Formatting group, from the Data Type list, select Number, and then from the Format list, select the number format you want.
If you type or paste data into the field, Access sets the Field Size setting based on the size of the number that you enter.
7.
2.
3.
Access opens the new table in Datasheet view. This figure illustrates a new table:
4.
Click Save
, and in the Save As dialog box, enter a name for the new table.
5.
Double-click the header row for the first table field (the one labeled Add New Field), and then type a name for the field.
6.
Select the first blank row under the header, and then type a block of numbers. Access infers the Number data type for the field when you enter numbers.
In addition, Access sets the Field Size property based on the size of the number that you enter or paste.
Top of Page
2.
3.
In the Navigation Pane, right-click the table that you want to change, and then click Design View
4.
In the Field Name column, select the first blank row, and then type a name for the field.
5.
Select the adjacent cell in the Data Type column, and then select Number from the list.
6.
2.
3.
4.
Click Save, and in the Save As dialog box, enter a name for the new table.
5.
Right-click the document tab for the new table and click Design View on the shortcut menu.
6.
In the Field Name column, select the first blank row and type a name for the field.
7.
Select the adjacent cell in the Data Type column, and then select Number from the list.
8.
Save your changes. If you want to set properties for the field, leave the table open in Design view and go to the next steps.
2.
Select the field next to the property name. Depending on the property, you enter data (such as default text or an input mask), start the Expression Builder by clicking ..., or select an option from a list.
For information about how to use each field property, select the property and then press F1.
Top of Page
You can use Datasheet view or Design view to delete a Number field from a table. However, when you delete a Number field that contains data, you lose that data permanently you cannot undo the deletion. For that reason, you should back up your database before you delete any table fields or other database components.
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
Locate the Number field, right-click the header row (the field name), and then click Delete Column.
2.
3.
In the Navigation Pane, right-click the table that you want to change, and then click Design View.
4.
Click the row selector (the blank square) next to the Number field, and then press DELETE.
-or-
5.
Top of Page
Usage Controls the size of the value that you can enter and store in the field. For more information about the Field Size property, see Number field specifications earlier in this article. You enter custom formatting characters to define a display format. Formats defined here appear in datasheets, forms, and reports. For more information about custom formats, see the article Format data in tables, forms, and reports.
Format
Sets the number of decimal places for the values in the field. Default value: Auto. Other possible values range from 0 to 15. You define an input mask when you need to control how users enter data in the field. For more information about using input masks, see the article Create an input mask to enter field or control values in a specific format.
Caption
Specifies the name of your Text field. This property accepts up to 2,048 characters. If you don't specify a caption, Access applies the default field name. Specifies the value that automatically appears in a field when you create a new record.
Specifies the requirements for data entered into an entire record, an individual field, or a control. When users enter data that violates the rule, you can use the Validation Text property to specify the resulting error message. Maximum length: 2,048 characters. For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Validation Text
Specifies the text in the error message that appears when users violate a validation rule. Maximum length: 255 characters. For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Required
When this property is set to Yes, you must enter a value in the field or in any controls bound to the field. In addition, the value cannot be null. You use an index to speed up queries, sorting, and grouping operations run against large amounts of data. You can also use indexes to prevent users from entering duplicate values. Choices: No Turns off indexing (default). Yes (Duplicates OK) Indexes the field and allows duplicate values. For example, you may have duplicate first and last names.
Indexed
Yes (No Duplicates) Indexes the field and does not allow duplicate values.
Smart Tags
You specify one or more smart tags for the field and any controls bound to the field. Smart tags are components that recognize the types of data in a field and allow you to take action based on that type. For example, in an E-mail Address field, a smart tag can create a new mail message or add the address to a list of contacts. Click Build (...) to see a list of available smart tags.
Text Align
Specifies the alignment for data. Choices: General Aligns text to the left, numbers and dates to the right (default setting). Left Aligns all text, dates, and numbers to the left. Right Aligns all text, dates, and numbers to the right. Center Centers all text, dates, and numbers. Distribute Justifies all text, dates, and numbers evenly against both sides of the field or text box.
For more information about formatting Text data, see the article Format data in tables, forms, and reports. For information about input masks, see the article Create an input mask to enter field or control values in a specific format.
Datasheet view You can add a Text field to a new or existing table in Datasheet view by adding a new field and then typing text into a blank row in the field, or by pasting as many as 256 characters of text into a blank row. You can also select the data type from a drop-down list, and set properties such as Is Required, which forces users to enter a date in the field, and Is Unique, which forces users to enter a nonduplicate value in the field.
Design view You use Design view to add a Text field and to set properties for the field that you cannot set in Datasheet view. Those properties include input masks and a default value for the field. For more information about the field properties that you can set in Design view, see Text field property reference at the end of this article.
Top of Page
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
If necessary, scroll horizontally to the first blank field. By default, Access displays Add New Field in the header row of all new fields.
5.
Double-click the header row, and then type a name for the new field.
6.
Select the first blank row under the header, and then type a block of text or a combination of text and numbers. You can enter a maximum of 256 characters. Access infers the Text data type for the field when you enter text or a mix of text and numbers, and you enter no more than 256 characters. If you enter more than 256 characters, Access infers the Memo data type.
-or-
7.
1.
2.
3.
Access opens the new table in Datasheet view. This figure illustrates a new table:
4.
Click Save
, and in the Save As dialog box, enter a name for the new table.
5.
Double-click the header row for the first table field (the one labeled Add New Field), and then type a name for the field.
6.
Select the first blank row under the header, and then type a block of text or a combination of text and numbers. You can enter a maximum of 256 characters. Access infers the Text data type for the field when you enter text or a mix of text and numbers, and you enter no more than 256 characters. If you enter more than 256 characters, Access infers the Memo data type.
-or-
-or-
On the Datasheet tab, in the Data Type & Formatting group, from the Data Type list, select Text.
Top of Page
You use Design view to add a Text field to a new or existing table and then to set or change field properties that you cannot set or change in Datasheet view. For example, you can specify an input mask or a default value. The steps in this section explain how to add a Text field and set properties for the field.
2.
3.
In the Navigation Pane, right-click the table that you want to change, and then click Design View.
4.
In the Field Name column, select the first blank row, and then type a name for the field.
5.
Select the adjacent cell in the Data Type column, and then select Text from the list.
6.
2.
3.
4.
Click Save
, and in the Save As dialog box, enter a name for the new table.
5.
Right-click the document tab for the new table and click Design View.
6.
In the Field Name column, select the first blank row, and then type a name for the field.
7.
Select the adjacent cell in the Data Type column, and then select Text from the list.
8.
Save your changes. If you want to set properties for the field, leave the table open in Design view and go to the next steps.
2.
Select the field next to the property name. Depending on the property, you can enter data (such as default text or an input mask), start the Expression Builder by clicking , or select an option from a list.
For information about how to use each field property, select the property and then press F1.
Top of Page
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
Locate the Text field, right-click the header row (the name), and then click Delete Column.
2.
3.
In the Navigation Pane, right-click the table that you want to change and then click Design View.
4.
Click the row selector (the blank square) next to the Text field, and then press DELETE.
-or-
5.
Top of Page
Usage Controls the size of your Text fields. Valid values: 0 to 255. If you leave this property blank, the field accepts 256 characters. You enter custom formatting characters to define a display format. Formats defined here appear in datasheets, forms, and reports. For more information about custom formats, see the article Format data in tables, forms, and reports.
Format
Input Mask
You define an input mask when you need to control how users enter data in the field. For more information about using input masks, see the article Create an input mask to enter field or control values in a specific format.
Caption
Specifies the name of your Text field. This property accepts up to 2,048 characters. If you don't specify a caption, Access applies the default field name. Specifies the value that automatically appears in a field when you create a new record. For example, in an addresses table, you can set the default value for the City field to a certain city. When users add a record to the table, they can either accept this value or enter the name of a different city. Maximum length: 255 characters. Specifies requirements for data entered into an entire record, an individual field, or a control. When a user enters data that violates the rule, you can use the Validation Text property to specify the resulting error message.
Default Value
Validation Rule
Maximum length: 2,048 characters. For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Validation Text
Specifies the text in the error message that appears when users violate a validation rule. Maximum length: 255 characters. For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Required
When this property is set to Yes, you must enter a value in the field or in any controls that are bound to the field. In addition, the value cannot be null. When this property is set to Yes, you can enter zero-length strings in a field. A zero-length string contains no characters. You use it to indicate that you know no value exists for a field. You enter a zero-length string by typing two double quotation marks with no space between them ("") . You use an index to speed up queries, sorting, and grouping operations run against large amounts of data. You can also use indexes to prevent users from entering duplicate values. Choices: No Turns off indexing (default). Yes (Duplicates OK) Indexes the field and allows duplicate values. For example, you may have duplicate first and last names. Yes (No Duplicates) Indexes the field and does not allow duplicate values.
Indexed
Unicode Compression
Access uses Unicode to represent data in Text, Memo, and Hyperlink fields. Because Unicode uses 2 bytes per character instead of 1, it takes up more storage space. To offset this effect and help ensure optimal performance, Access sets the default value of this property to Yes for Text, Memo, and Hyperlink fields. When the property is set to Yes, any character whose first byte is 0 is compressed when it is stored and uncompressed when it is retrieved.
IME Mode
Specifies an Input Method Editor, a tool for using English versions of Access with files created in Japanese or Korean versions of Access. Default value: No Control. For more information about using this property, press F1. Specifies the type of data you can enter by using an Input Method Editor. For more information about using this property, press F1. You specify one or more smart tags for the field and any controls bound to the field. Smart tags are components that recognize the types of data in a field and allow you to take action based on that type. For example, in an Email Address field, a smart tag can create a new mail message or add the address to a list of contacts.
Click
Text Align
Specifies the alignment for data in a Text field. Choices: General Aligns all text to the left.
Left Aligns all text to the left. Center Centers all text. Right Aligns all text to the right. Distribute Justifies all text evenly against both sides of the field or text box.
Regardless of how Access formats the date and time data, and regardless of how you enter the date or time data, Date/Time fields store the dates and times as double-precision floating point numbers a system also called serial dates. The following figure represents a typical serial date and time value.
The integer portion of the value, to the left of the decimal point, represents the date. The fractional portion, to the right of the decimal point, represents the time.
The number in this figure represents December 24, 2003, at 9:00 P.M. The date component is the number of whole days that have elapsed since the starting or "base" date of 12/30/1899. In this example, 37,979 days have elapsed from 12/30/1899 to 12/24/2003. The time component is a fraction of a 24-hour day. So, a value of 0.875 multiplied by 24 hours equals 21 hours, or 9:00 P.M.
Negative values in the date component represent dates prior to the base date. For example, a value of -1 as the date component resolves to one day prior to the base date, or 12/29/1899.
Valid date values range from -657,434 (January 1, 100 A.D.) to 2,958,465 (December 31, 9999 A.D.). Valid time values range from 0.0 to 0.9999, or 23:59:59.
Storing the date and time values as numbers allows you to perform a large number of calculations on date and time data. For example, you can calculate a total number of hours worked (for a time card), or determine the age of an invoice.
For more information about using predefined and custom formats, see the article Format data in tables, forms, and reports.
For information about input masks, see the article Create an input mask to enter field or control values in a specific format.
Datasheet view You can add a Date/Time field to a new or existing table in Datasheet view by adding a new field and then entering a date manually, or by copying and pasting a date. You can also select the data type from a drop-down list and set properties such as Is Required, which forces users to enter a date in the field, and Is Unique, which forces users to enter a non-duplicate value in the field.
Design view You use Design view to add a Date/Time field and set properties for the field that you cannot set in Datasheet view, including input masks and default values.
Top of Page
1.
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
If necessary, scroll horizontally to the first blank field. By default, Access displays Add New Field in the header row of all new fields, like so:
5.
Double-click the header row and type a name for the new field.
6.
Select the first blank row under the header and type a date.
-or-
-or-
On the Datasheet tab, in the Data Types & Formatting group, from the Data Type list, select Date/Time.
7.
1.
2.
3.
Access opens the new table in Datasheet view. This figure illustrates a new table:
4.
Click Save
, and in the Save As dialog box, enter a name for the new table.
5.
Double-click the header row for the first table field (the one labeled Add New Field), and type a name for the field.
6.
Select the first blank row under the header, and type a date. Access infers the Date/Time data type automatically when you enter a date.
-or-
-or-
On the Datasheet tab, in the Data Type & Formatting group, from the Data Type list, select Date/Time.
Top of Page
You use Design view to add a Date/Time field to a new or existing table and then to set or change the field properties that you can't set or change in Datasheet view. For example, you can specify an input mask or a validation rule. For more information about input masks and other properties, see the section Date/Time field property reference.
1.
2.
3.
In the Navigation Pane, right-click the table that you want to change, and then click Design View
4.
In the Field Name column, select the first blank row, and then type a name for the field.
5.
Select the adjacent cell in the Data Type column, and then select Date/Time from the list.
6.
1.
2.
3.
4.
Click Save
, and in the Save As dialog box, enter a name for the new table.
5.
Right-click the document tab for the new table and click Design View.
6.
In the Field Name column, select the first blank row, and then type a name for the field.
7.
Select the adjacent cell in the Data Type column, and then select Date/Time from the list.
8.
Save your changes. If you want to set properties for the field, leave the table open in Design view and continue to the next steps.
1.
On the General tab in the lower section of the table designer, under Field Properties, locate the property that you want to change.
2.
Select the field next to the property name. Depending on the property, you can do any of the following:
For information about how to use each field property, select the property and then press F1.
Top of Page
1.
2.
3.
In the Navigation Pane, double-click the table that you want to change.
4.
Locate the Date/Time field, right-click the header row (the name), and click Delete Column.
5.
1.
2.
3.
In the Navigation Pane, right-click the table that you want to change and then click Design View
4.
Click the row selector (the blank square) next to the Date/Time field, and then press DELETE.
-or-
5.
Top of Page
Input Mask You enter an input mask string, or click to start the Input Mask Wizard.
For more information about creating and using input masks, see the articles Create an input mask to enter field or control values in a specific format and Format data in tables, forms, and reports.
Specifies the name of your Date/Time field. If you don't specify a caption, Access applies the default field name. Specifies the value that automatically appears in a field when you create a new record. For example, you can enter a function such as Date() to automatically display today's date. Specifies requirements for data entered into an entire record, an individual field, or a control on a form or report. When a user enters data that violates the rule, you can use the Validation Text property to specify the resulting error message. Maximum length: 2,048 characters.
For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Validation Text
Specifies the text in the error message that appears when users violate a validation rule. Maximum length: 255 characters. For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Required
When this property is set to Yes, you must enter a value in the field or in any controls that are bound to the field. In addition, the value cannot be null. You use an index to speed up queries, sorting, and grouping operations that are run against large amounts of data. You can also use indexes to prevent users from entering duplicate values. Choices: No Turns off indexing (default). Yes (Duplicates OK) Indexes the field and allows duplicate values. For example, you may have duplicate first and last names. Yes (No Duplicates) Indexes the field and does not allow duplicate values.
Indexed
IME Mode
Specifies an Input Method Editor, a tool for using English versions of Access with files created in Japanese or Korean versions of Access. Default value: No Control. For more information about using this property, press F1. Specifies the type of data you can enter by using an Input Method Editor. For more information about using this property, press F1.
You specify one or more smart tags for the field and any controls that are bound to the field. Smart tags are components that recognize the types of data in a field and allow you to take action based on that type. For example, you can select a Date/Time field and then use a smart tag to open your personal calendar.
Click
Text Align
Specifies the alignment for data in a Date/Time field. Choices: General Aligns text to the left, numbers and dates to the right. Left Aligns all text, dates, and numbers to the left. Right Aligns all text, dates, and numbers to the right. Center Centers all text, dates, and numbers. Distribute Justifies all text, dates, and numbers evenly against both sides of the field or text box.
Shows or hides a pop-up calendar control that appears when users click Date/Time fields. Default: For dates. Select Never to hide the control.
Introduction
After you have created a table for each subject in your database, you must provide Office Access 2007 with the means by which to bring that information back together again when needed. You do this by placing common fields in tables that are related, and by defining relationships between your tables. You can then create queries, forms, and reports that display information from several tables at once. For example, the form shown here includes information drawn from several tables:
The customer name in the Bill To box is retrieved from the Customers table, the Order ID and the Order Date values come from the Orders table, the Product name comes from the Products table, and the Unit Price and Quantity values come from the Order Details table. These tables are linked to each other in a variety of ways to bring information from each into the form.
In the preceding example, the fields in the tables must be coordinated so that they show information about the same order. This coordination is accomplished by using table relationships. A table relationship works by matching data in key fields often a field with the same name in both tables. In most cases, these matching fields are the primary key from one table, which provides a unique identifier for each record, and a foreign key in the other table. For example, employees can be associated with orders for which they are responsible by creating a table relationship between the EmployeeID fields in the Employees and the Orders tables.
Top of Page
A one-to-many relationship
Consider an order tracking database that includes a Customers table and an Orders table. A customer can place any number of orders. It follows that for any customer represented in the Customers table, there can be many orders represented in the Orders table. The relationship between the Customers table and the Orders table is, therefore, a one-to-many relationship.
To represent a one-to-many relationship in your database design, take the primary key on the "one" side of the relationship and add it as an additional field or fields to the table on the "many" side of the relationship. In this case, for example, you add a new field the ID field from the Customers table to the Orders table and name it Customer ID. Access can then use the Customer ID number in the Orders table to locate the correct customer for each order.
A many-to-many relationship
Consider the relationship between a Products table and an Orders table. A single order can include more than one product. On the other hand, a single product can appear on many orders. Therefore, for each record in the Orders table, there can be many records in the Products table. In addition, for each record in the Products table, there can be many records in the Orders table. This type of relationship is called a many-to-many relationship because, for any product, there can be many orders and, for any order, there
can be many products. Note that to detect existing many-to-many relationships between your tables, it is important that you consider both sides of the relationship.
To represent a many-to-many relationship, you must create a third table, often called a junction table, that breaks down the many-to-many relationship into two one-to-many relationships. You insert the primary key from each of the two tables into the third table. As a result, the third table records each occurrence, or instance, of the relationship. For example, the Orders table and the Products table have a many-to-many relationship that is defined by creating two one-to-many relationships to the Order Details table. One order can have many products, and each product can appear on many orders.
A one-to-one relationship
In a one-to-one relationship, each record in the first table can have only one matching record in the second table, and each record in the second table can have only one matching record in the first table. This type of relationship is not common because, most often, the information related in this way is stored in the same table. You might use a one-to-one relationship to divide a table with many fields, to isolate part of a table for security reasons, or to store information that applies only to a subset of the main table. When you do identify such a relationship, both tables must share a common field.
Top of Page
To work with records from more than one table, you often must create a query that joins the tables. The query works by matching the values in the primary key field of the first table with a foreign key field in the second table. For example, to return rows that list all of the orders for each customer, you construct a query that joins the Customers table with the Orders table based on the Customer ID field. In the Relationships window, you can manually specify the fields to join. However, if you already have a relationship defined
between the tables, Office Access 2007 supplies the default join, based on existing the table relationship. In addition, if you use one of the query wizards, Access uses the information it gathers from the table relationships you have already defined to present you with informed choices and to prepopulate property settings with appropriate default values.
When you design a form or report, Office Access 2007 uses the information it gathers from the table relationships you have already defined to present you with informed choices and to prepopulate property settings with appropriate default values.
Table relationships are the foundation upon which you can enforce referential integrity to help prevent orphan records in your database. An orphan record is a record with a reference to another record that does not exist for example, an order record that references a customer record that does not exist.
When you design a database, you divide your information into tables, each of which has a primary key. You then add foreign keys to related tables that reference those primary keys. These foreign key-primary key pairings form the basis for table relationships and multi-table queries. It is important, therefore, that these foreign key-primary key references stay synchronized. Referential integrity helps ensure that references stay synchronized and is dependent upon table relationships.
Top of Page
Suppose you have a one-to-many relationship between Shippers and Orders and you want to delete a Shipper. If the shipper you want to delete has orders in the Orders table, those orders will become "orphans" when you delete the
Shipper record. The orders will still contain a shipper ID, but the ID will no longer be valid, because the record that it references no longer exists.
The purpose of referential integrity is to to prevent orphans and keep references in sync so that this hypothetical situation never occurs.
You enforce referential integrity by enabling it for a table relationship (see Enforce referential integrity for step-by-step instructions). Once enforced, Access rejects any operation that would violate referential integrity for that table relationship. This means Access will reject both updates that change the target of a reference, and deletions that remove the target of a reference. However, it is possible you might have a perfectly valid need to change the primary key for a shipper that has orders in the Orders table. For such cases, what you really need is for Access to automatically update all the effected rows as part of a single operation. That way, Access ensures that the update is completed in full so that your database is not left in an inconsistent state, with some rows updated and some not. For this reason Access supports the Cascade Update Related Fields option. When you enforce referential integrity and choose the Cascade Update Related Fields option, and you then update a primary key, Access automatically updates all fields that reference the primary key.
It's also possible you might have a valid need to delete a row and all related records for example, a Shipper record and all related orders for that shipper. For this reason, Access supports the Cascade Delete Related Records option. When you enforce referential integrity and choose the Cascade Delete Related Records option, and you then delete a record on the primary key side of the relationship, Access automatically deletes all records that reference the primary key.
Top of Page
1.
2.
3.
4.
If the database contains relationships, the Relationships window appears. If the database does not contain any relationships and you are opening the Relationships window for the first time, the Show Table dialog box appears. Click Close to close the dialog box.
5.
This displays all of the defined relationships in your database. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless the Show Hidden Objects check box is selected in the Navigation Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation Pane.
A table relationship is represented by a relationship line drawn between tables in the Relationships window. A relationship that does not enforce referential integrity appears as a thin line between the common fields supporting
the relationship. When you select the relationship by clicking its line, the line thickens to indicate it is selected. If you enforce referential integrity for this relationship, the line appears thicker at each end. In addition, the number 1 appears over the thick portion of the line on one side of the relationship, and the infinity symbol () appears over the thick portion of the line on the other side.
You can select from the following commands on the ribbon when the Relationships window is active:
Edit Relationships Opens the Edit Relationships dialog box. When you select a relationship line, you can click Edit Relationships to change the table relationship. You can also double-click the relationship line.
Clear Layout Removes all tables and relationships from display in the Relationships window. Note that this command only hides the tables and relationships it does not delete them.
Relationships Report Creates a report that displays the tables and relationships in your database. The report shows only the tables and relationships that are not hidden in the Relationships window.
Show Table Opens the Show Table dialog box so that you can select tables and queries for viewing in the Relationships window.
Direct Relationships Displays all relationships and related tables for the selected table in the Relationships window, if they are not already displayed.
All Relationships Displays all of the relationships and related tables in your database in the Relationships window. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options dialog box.
For more information about the Show Hidden Tables option, see the article Guide to the Navigation Pane.
Close Closes the Relationships window. If you made any changes to the layout of the Relationships window, you are asked whether to save those changes.
Top of Page
2.
3.
4.
If you have not yet defined any relationships, the Show Table dialog box automatically appears. If it does not appear, on the Design tab, in the Relationships group, click Show Table.
The Show Table dialog box displays all of the tables and queries in the database. To see only tables, click Tables. To see only queries, click Queries. To see both tables and queries, click Both.
5.
Select one or more tables or queries and then click Add. When you have finished adding tables and queries to the Relationships window, click Close.
6.
Drag a field (typically the primary key) from one table to the common field (the foreign key) in the other table. To drag multiple fields, press the CTRL key, click each field, and then drag them.
7.
Verify that the field names shown are the common fields for the relationship. If a field name is incorrect, click the field name and select a new field from the list.
To enforce referential integrity for this relationship, select the Enforce Referential Integrity check box. For more information about referential integrity, see the Understanding Referential Integrity and the Enforce Referential Integrity sections.
8.
Click Create.
The relationship line is drawn between the two tables. If you selected the Enforce Referential Integrity check box, the line appears thicker at each end. In addition, again only if you selected the Enforce Referential Integrity check box, the number 1 appears over the thick portion of the line on one side of the relationship, and the infinity symbol () appears over the thick portion of the line on the other side.
NOTES
To create a one-to-one relationship Both of the common fields (usually the primary key and foreign key fields) must have a unique index. This means the Indexed property for these fields should be set to Yes (No Duplicates). If both fields have a unique index, Access creates a one-to-one relationship.
To create a one-to-many relationship The field on the "one" side (typically the primary key) of the relationship must have a unique index. This means the Indexed property for this field should be set to Yes (No Duplicates). The field on the "many" side should not have a unique index. It can have an index, but it must allow duplicates. This means the Indexed property for this field should be set to either No, or Yes (Duplicates OK). When one field has a unique index and the other does not, Access creates a one-tomany relationship.
1.
2.
3.
In the Navigation pane, right-click the table to which you want to add the field and create the relationship, and click Datasheet View on the shortcut menu.
The Field List pane shows all of the other tables in your database, grouped into categories. When you work with a table in Datasheet view, Access displays fields in either of two categories in the Field List pane: Fields available in related tables and Fields available in other tables. The first category lists all of the tables that have a relationship with the table you are currently working with. The second category lists all of the tables with which your table does not have a relationship.
In the Field List pane, when you click the plus sign (+) next to a table name, you see a list of all the fields available in that table. To add a field to your table, drag the field that you want from the Field List pane to the table in Datasheet view.
Add a field and create a relationship from the Field List pane
1. On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
2.
Under Fields available in other tables, click the plus sign (+) next to a table name to display the list of fields in that table.
3.
Drag the field that you want from the Field List pane to the table that is open in Datasheet view.
4.
5.
When you drag a field from an "other" (unrelated) table and then complete the Lookup Wizard, a new one-to-many relationship is automatically created between the table in the Field List and the table to which you dragged the field.
This relationship, created by Access, does not enforce referential integrity by default. To enforce referential integrity, you must edit the relationship. See the section Change a table relationship for more information.
Top of Page
1.
2.
3.
If you have not yet defined any relationships and this is the first time you are opening the Relationships window, the Show Table dialog box appears. If the dialog box appears, click Close.
4.
All tables that have relationships are displayed, showing relationship lines.
5.
Click the relationship line for the relationship that you want to delete. The relationship line appears thicker when it is selected.
6.
or
7.
Access might display the message Are you sure you want to permanently delete the selected relationship from your database?. If this confirmation message appears, click Yes.
NOTE
If either of the tables employed in the table relationship are in use, perhaps by another person or process, or
in an open database object (such as a form), you will not be able to delete the relationship. You must first close any open objects that use these tables before you can remove the relationship.
Top of Page
1.
2.
3.
If you have not yet defined any relationships and this is the first time you are opening the Relationships window, the Show Table dialog box appears. If the dialog box appears, click Close.
4.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation Pane.
5.
Click the relationship line for the relationship that you want to change. The relationship line appears thicker when it is selected.
6.
or
7.
The Edit Relationships dialog box allows you to change a table relationship. Specifically, you can change the tables or queries on either side of the relationship, or the fields on either side. You can also set the join type, or enforce referential integrity and choose a cascade option. For more information about the join type
and how to set it, see the section Set the join type. For more information about how to enforce referential integrity and choose a cascade option, see the section Enforce referential integrity.
A multiple table query combines information from more than one table by matching the values in common fields. The operation that does the matching and combining is called a join. For instance, suppose you want to display customer orders. You create a query that joins the Customers table and the Orders table on the Customer ID field. The query result contains customer information and order information for only those rows where a corresponding match was found.
One of the values you can specify for each relationship is the join type. The join type tells Access which records to include in a query result. For example, consider again a query that joins the Customers table and the Orders table on the common fields that represent the Customer ID. Using the default join type (called an inner join), the query returns only the Customer rows and the Order rows where the common fields (also called the joined fields) are equal.
However, suppose you want to include all Customers even those who have not yet placed any orders. To accomplish this, you must change the join type from an inner join to what is called a left outer join. A left outer join returns all of the rows from the table on the left side of the relationship and only those that match from the table on the right. A right outer join returns all of the rows on the right and only those that match on the left.
NOTE
In this case, "left" and "right" refer to the position of the tables in the Edit Relationships dialog box, not the
Relationships window.
You should think about the result you will most often want from a query that joins the tables in this relationship, and then set the join type accordingly.
2.
The following table (using the Customers and Orders tables) shows the three choices that are displayed in the Join Properties dialog box, the type of join they use, and whether all rows or matching rows are included for each table.
Choice 1. Only include rows where the joined fields from both tables are equal. 2. Include ALL records from 'Customers' and only those records from 'Orders' where the joined fields are equal. 3. Include ALL records from 'Orders' and only those records from 'Customers' where the joined fields are equal. Relational join Inner join Left table Matching rows Right table Matching rows
All rows
Matching rows
Matching rows
All rows
When you choose option 2 or option 3, an arrow is shown on the relationship line. This arrow points to the side of the relationship that shows only matching rows.
2.
3.
If you have not yet defined any relationships and this is the first time you are opening the Relationships window, the Show Table dialog box appears. If the dialog box appears, click Close.
4.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation Pane.
5.
Click the relationship line for the relationship that you want to change. The relationship line appears thicker when it is selected.
6.
or
7.
8.
In the Join Properties dialog box, click an option, and then click OK.
9.
Make any additional changes to the relationship, and then click OK.
Top of Page
The purpose of using referential integrity is to to prevent orphan records and to keep references synchronized so that you don't have any records that reference other records that no longer exist. You enforce referential integrity by enabling it for a table relationship. Once enforced, Access rejects any operation that would violate referential integrity for that table relationship. Access rejects updates that change the target of a reference, and also deletions that remove the target of a reference. To have Access propagate referential updates and deletions so that all related rows are changed accordingly, see the section Set the cascade options.
2.
3.
If you have not yet defined any relationships and this is the first time you are opening the Relationships window, the Show Table dialog box appears. If the dialog box appears, click Close.
4.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options dialog box.
For more information about the Show Hidden Objects option, see the article Guide to the Navigation Pane.
5.
Click the relationship line for the relationship that you want to change. The relationship line appears thicker when it is selected.
6.
or
7.
8.
Make any additional changes to the relationship, and then click OK.
After you have enforced referential integrity, the following rules apply:
You cannot enter a value in the foreign key field of a related table if that value doesn't exist in the primary key field of the primary table doing so creates orphan records.
You cannot delete a record from a primary table if matching records exist in a related table. For example, you cannot delete an employee record from the Employees table if there are orders assigned to that employee in the Orders table. You can, however, choose to delete a primary record and all related records in one operation by selecting the Cascade Delete Related Records check box.
You cannot change a primary key value in the primary table if doing so would create orphan records. For example, you cannot change an order number in the Orders table if there are line items assigned to that Order in the Order Details table. You can, however, choose to update a primary record and all related records in one operation by selecting the Cascade Update Related Fields check box.
NOTES
If you have difficulty enabling referential integrity, note that the following conditions are required in order to enforce referential integrity:
The common field from the primary table must be a primary key or have a unique index.
The common fields must have the same data type. The one exception is that an AutoNumber field can be related to a Number field that has a FieldSize property setting of Long Integer.
Both tables must exist in the same Access database. Referential integrity cannot be enforced on linked tables. However, if the source tables are in Access format, you can open the database in which they are stored and enable referential integrity in that database.
You might also need to delete a row and all related records for instance, a shipper record and all related orders for that shipper. For this reason, Access supports the Cascade Delete Related Records option. When you enforce referential integrity and choose the Cascade Delete Related Records option, Access automatically deletes all records that reference the primary key when you delete the record that contains the primary key.
2.
3.
If you have not yet defined any relationships and this is the first time you are opening the Relationships window, the Show Table dialog box appears. If the dialog box appears, click Close.
4.
All tables that have relationships are displayed, showing relationship lines. Note that hidden tables (tables for which the Hidden check box in the table's Properties dialog box is selected) and their relationships will not be shown unless Show Hidden Objects is selected in the Navigation Options dialog box.
For more information about the Show Hidden Objects option, see Guide to the Navigation Pane.
5.
Click the relationship line for the relationship that you want to change. The relationship line appears thicker when it is selected.
6.
or
7.
8.
Select either the Cascade Update Related Fields or Cascade Delete Related Records check box, or select both.
9.
Make any additional changes to the relationship, and then click OK.
You can create a lookup column in either Datasheet View or in Design View.
Top of Page
1.
2.
3.
In the Navigation Pane, double-click the table in which you want to create the lookup column this opens the table in Datasheet view.
4.
On the Datasheet tab, in the Fields & Columns group, click Lookup Column.
5.
On the first page of the Lookup Wizard, indicate whether you want to base the lookup column on the values in a table or a query, or on a list of values that you type.
The most common type of lookup column is one that displays values looked up from a related table or query.
6.
Click Next, and then follow the instructions to complete the wizard. For more information about completing the wizard, see the section Using the Lookup Wizard.
When you click Finish, a lookup column is created whose field properties are set based on the choices you made in the Lookup Wizard.
Top of Page
1.
2.
3.
In the Navigation Pane, double-click the table in which you want to create the lookup column this opens the table in Datasheet view.
4.
On the Datasheet tab, in the Fields & Columns group, click Add Existing Fields.
5.
Click the plus sign (+) next to a table to display the list of fields in that table.
6.
Drag the field that you want from the Field List pane to the table in Datasheet view.
7.
8.
Follow the instructions to complete the wizard. For more information about completing the wizard, see the section Using the Lookup Wizard.
When you have completed the wizard, the lookup column appears in the table in Datasheet view.
Top of Page
1.
2.
3.
In the Navigation Pane, right-click the table in which you want to add the lookup column, and then click Design View on the shortcut menu.
4.
Locate the first available empty row in the table design grid.
5.
In the first available empty row, click a cell in the Field Name column, and then type a field name for the lookup column.
6.
Next, click a cell in the Data Type column for that row, click the drop-down arrow, and then select Lookup Wizard.
7.
On the first page of the Lookup Wizard, indicate whether you want to base the lookup column on the values in a table or a query, or on a list of values that you type.
The most common type of lookup column is one that displays values looked up from a related table or query.
8.
Click Next, and then follow the instructions to complete the wizard. For more information about completing the wizard, see the section Using the Lookup Wizard.
When you click Finish, a lookup column is created whose field properties are set based on the choices you made in the Lookup Wizard. You can view the field properties in the bottom pane of Design view under Field Properties. To see the properties that apply specifically to the lookup column, click the Lookup tab.
Understanding the bound value and the display value in a lookup column
The purpose of using a lookup column is to replace the display of a number ,such as an ID (or other foreign key value), with something more meaningful, such as a name. For example, instead of displaying a contact ID number, Access can display a contact name. The contact ID number is the bound value. It is automatically looked up in a source table or query to find the contact name. The contact name is the display value.
Display value
Bound value
A lookup column has a display value that appears in the user interface, and a bound value that is stored in the control. The display value is "looked up," based on the bound value. This means that Access often displays a lookedup display value that is not the same as the bound value that is stored in the field. For example, in the example of an Orders table, a customer ID value from the Customers table is stored in the Customer field in the Orders table this is the bound value. However, because the Customer field is a lookup field, Access displays the looked-up value in this case, the customer name. The customer name is the display value.
It is important to understand the distinction between a lookup field's display value and its bound value. The display value is automatically shown in Datasheet view, by default. However, the bound value is what is stored, what you use in query criteria, and what Access uses by default in joins with other tables.
Top of Page
You can view the Lookup field properties in the bottom pane of Design view under Field Properties. To see the properties specifically related to the lookup column, click the Lookup tab.
1.
2.
3.
In the Navigation Pane, right-click the table in which you want to add the lookup column, and then click Design View on the shortcut menu.
4.
Click a cell in the Field Name column for the lookup column.
5.
When you set the first property (Display Control), the list of available properties changes to reflect your choice. You can set the Lookup field properties to change the behavior of a lookup column. Note than when you create the lookup column by using the Lookup Wizard, the Lookup field properties are set for you by the wizard.
Row Source
Bound Column
Column Count
Specify the number of columns in the row source that can be displayed in the lookup column. To select which columns to display, you provide a column width in the Column Widths property. Specify whether to display column headings.
Column Heads
Column Widths
Enter the column width for each column. If you don't want to display a column, such as an ID number, specify 0 for the width. Specify the number of rows that appear when you display the lookup column. Specify the width of the control that appears when you display the lookup column. Choose whether a user can enter a value that isn't found in the list. Specify whether the lookup column employs a multivalued field and allows multiple values to be selected. For more information about multivalued fields, see the article Guide to multivalued fields.
Specify whether you can edit the items in a lookup column that is based on a value list. When this property is set to Yes, and you right-click a lookup field that is based on a single column value list, you will see the Edit List Items menu option. If the lookup field has more than one column, this property is ignored. Specify an existing form to use with which you can edit the list items in a lookup column that is based on a table or query. Show only values that match the current row source when Allow Multiples Values is set to Yes.
The bound value in a lookup column is determined by the Bound Column property. The display value in a lookup column is the column or columns that are represented in the Column Widths property as having a non-zero width.
Top of Page
When the wizard starts, you must decide whether to base the lookup column on a table or query, or on a list of values that you enter. Most of the time, if your database is properly designed and your information is divided into subjectbased tables, you should choose a table or query as the source of data for the lookup column.
The Lookup Wizard lists the available fields from your table or query. For each field that you want to include in your lookup column, click the field and then click the greater than button (>) to move it into the Selected Fields list. Note that you should select the fields that you want to be visible in addition to the field that you want to supply the value that is stored when you make a selection in the lookup column. When you are finished, click Next.
The Lookup Wizard displays a page that allows you to specify a field or fields that you can use to sort the lookup column. This sorting is optional. When you are finished, click Next.
You can adjust the width of the columns that will appear in the lookup column. If you reduce the width of a field so that it is no longer visible, it will not appear in the lookup column. For example, you can use this feature to prevent an ID column from being displayed. When you are finished, click Next.
When you select a row in the lookup column, you can store a value from that row in your database or use the value later to perform an action. This page of the wizard, shown in the following figure, allows you to choose the field that supplies that value. You should choose a field that uniquely identifies the row. Usually, the primary key field of the source table makes a good choice. When you are finished, click Next.
On the final page of the Lookup Wizard, you should type a name for your lookup column this becomes the name of the field in your table.
If you want to allow selection of more than one value when the lookup column appears, and then store the multiple values, select the Allow Multiple Values check box. Note that selecting this check box changes the lookup column to a multivalued field.
For more information about multivalued fields, see the articles Guide to multivalued fields and Add or change a lookup column that lets you store multiple values.
First, enter the number of columns that you want to include in the lookup column. Then, type your values in the grid. You can adjust the width of the columns that will appear in the lookup column. If you reduce the width of a field so that it is no longer visible, it will not appear in the lookup column. When you are finished, click Next.
When you select a row in the lookup column, you can store a value from that row in your database or use the value later to perform an action. This page in the wizard, shown in the following figure, allows you to choose the field that supplies that value. You should choose a field that uniquely identifies the row. When you are finished, click Next.
On the final page of the Lookup Wizard, you should enter a name for your lookup column this becomes the name of the field in your table. If you want to allow selection of more than one value when the lookup column appears, and then store the multiple values, select the Allow Multiple Values check box. Note that selecting this check box changes the lookup column to a multivalued field.
For more information about multivalued fields, see the articles Guide to multivalued fields or Add or change a lookup column that lets you store multiple values.
Top of Page
1.
2.
3.
In the Navigation pane, double-click the table or form that contains the multivalued field.
The table opens in Datasheet view or the form opens in Form view.
4.
Right-click the lookup column, and then click Edit List Items on the shortcut menu.
5.
Top of Page
1.
2.
3.
In the Navigation Pane, right-click the table in which you want to add the lookup column, and then click Design View on the shortcut menu.
4.
5.
Next, click the cell in the Data Type column for that row, click the drop-down arrow, and then select Lookup Wizard....
6.
On the first page of the Lookup Wizard, indicate whether you want to base the lookup column on the values in a table or query, or on a list of values that you enter.
The most common type of lookup column is one that displays values looked up from a related table or query.
7.
Click Next, and then follow the instructions to complete the wizard. For more information about completing the wizard, see the section Using the Lookup Wizard.
When you click Finish, a lookup column is created whose field properties are set based on the choices you made in the Lookup Wizard. You can view the field properties in the bottom pane of Design view under Field Properties. To see the properties that apply specifically to the lookup column, click the Lookup tab.
About expressions
In Office Access 2007, an expression is the equivalent of a formula in Office Excel 2007. An expression consists of a number of elements that you use, alone or in combination, to produce a result. Those elements can include:
Identifiers the names of table fields or controls on forms or reports, or the properties of those fields or controls.
Functions, such as SUM or AVG, and the arguments that are used with them.
Constants values that do not change such as strings of text, or numbers that are not calculated by an expression.
You use an expression to perform a calculation, retrieve the value of a field or control, supply criteria to a query, define rules, create calculated controls and calculated fields, and define a grouping level for a report.
You use an expression when you need to create values that do not reside directly in your data. For example, you might need to calculate sales tax on an order, or calculate the total value of the order itself. At other times, you'll need to add criteria to a query or filter information that determines which records the query returns or that appear when a filter is applied. In other cases, you might want to set a default value or a validation rule for a field or control. In all of these cases, you use an expression.
The following table shows some sample expressions and how they are typically used:
Expression =[RequiredDate]-[ShippedDate]
Purpose Calculates the difference between the date values in two text box controls (called RequiredDate and ShippedDate) on a report. Sets the default value for a Date/Time table field to the current date. Creates a calculated field in a query.
Date() ExtendedPrice: CCur([Order Details].Unit Price*[Quantity]*(1[Discount])/100)*100 Between #1/1/2005# And #12/31/2005# =[Orders Subform].Form!OrderSubtotal
Used to enter criteria for a Date/Time field in a query. Returns the value of the OrderSubtotal control on the Orders subform that is on the Orders form. Sets a validation rule for a numeric field in a table users must
>0
As you can see from the preceding examples, an expression in Access is not just a mathematical calculation. Instead, expressions serve a variety of purposes. You will also notice that the sample expressions differ from each other in some ways. For example, some expressions start with the = (equal) operator. When calculating a value for a control on a form or report, you use the = operator to start the expression. In other instances, you don't use the = operator. For example, when you type an expression in a query or in the DefaultValue or ValidationRule property of a field or control, you don't use the = operator unless you're adding the expression to a Text field in a table. In some cases, such as adding expressions to queries, Access removes the = operator automatically. For more information about expression syntax, see the article A guide to expression syntax.
The following sections describe the various parts of an expression in more detail. The examples in the sections also provide brief descriptions of the syntax that expressions use.
Identifiers
An identifier is the name of a field, property, or control. You use an identifier in an expression to refer to the value that is associated with a field, property, or control. For example, consider the expression =[RequiredDate][ShippedDate]. This expression subtracts the value of the ShippedDate field or control from the value of the RequiredDate field or control. In this expression, both RequiredDate and ShippedDate serve as identifiers.
Operators
Access supports a variety of operators, including the expected arithmetic operators such as +, -, * (multiply), / (divide). You can also use comparison operators for comparing values, text operators for concatenating (combining) text, logical operators for determining true or false values, and other operators specific to Access. For details about operators, see the section Table of operators.
Some functions require arguments. An argument is a value that provides input to the function. If a function requires more than one argument, you separate the arguments with a comma. For example, consider the Date function in the following example expression:
=Format(Date(),"mmmm d, yyyy")
This example uses two arguments. First, the Date function supplies the current date. The second argument, separated from the first by a comma, is a text string that tells the Format function how to format the date value. Note that the text string is enclosed in quotation marks. As a general rule, when you need to supply text, you place it inside quotation marks. This expression also illustrates a principle that you should remember as you proceed: You can often use the value returned by one function as an argument to yet another function.
For more information about how to use quotation marks and expression syntax in general, see the article A guide to expression syntax.
Finally, Access supports a large number of built-in functions. For links to information about the functions, see the article Functions (arranged by category).
Constants
A constant is a named item whose value remains constant while Access is running. Typically, you use the True, False, and Null constants most often in your expressions. You can also define your own constants in Visual Basic for Applications (VBA) code that you can use in VBA procedures. VBA is the programming language that Access uses.
NOTE
You cannot use Microsoft Visual Basic constants in custom functions that you use in your expressions. For
example, Visual Basic has constants for the days of the week: vbSunday represents Sunday, vbMonday represents Monday, and so on. Each of these constants has a corresponding numeric value: The numeric value for vbSunday is 1, vbMonday is 2, and so on. You cannot use these constants in a custom function that is called from within an expression. You must instead use the numeric values.
Values
You can employ literal values in your expressions, such as the number 1,254 or the string "Enter a number between 1 and 10." Numeric values can be a series of digits, including a sign and a decimal point, if needed. In the absence of a
sign, Access assumes a positive value. To make a value negative, include the minus sign (-). You can also use scientific notation. To do so, include "E" or "e" and the sign of the exponent (for example, 1.0E-6).
When you use text strings as constants, place them within quotation marks. In some circumstances, Access will supply the quotation marks for you. For example, when you type text in an expression for a validation rule or for query criteria, Access surrounds your text strings with quotation marks automatically.
For example, if you type the text Paris, Access displays "Paris" in the expression. If you want an expression to produce a string that is actually enclosed in quotation marks, you can enclose the nested string either in single (') quotation marks or within three sets of double (") quotation marks. For example, the following expressions are equivalent:
To use date/time values, you enclose them in pound signs (#). For example, #3-7-07#, #7-Mar-07#, and #Mar-72007# are all valid date/time values. When Access sees a valid date/time value enclosed by # characters, it automatically treats the value as a Date/Time data type.
Top of Page
Calculate values that do not exist directly in your data. You can calculate values for table fields, for queries, and for controls on forms and reports.
Set a default value for a table field or a control on a form or report. Your default values then appear whenever you open a table, form, or report for use.
Create a validation rule. Validation rules control what values users can and cannot enter into a field or control.
The following figure illustrates some typical expressions used in the scenarios described here:
For example, suppose that you need to calculate the total dollar amount for a line item in an invoice. Typically, you do not store the line item total in the database. Instead, you calculate it as needed from two items that you should store in the database quantity and price. You then use an expression such as this one to calculate the value:
=CCur([Quantity]*[Price])
This expression multiplies quantity times price and then uses the CCur function (convert to currency) to convert the result to the Currency data type. You can also calculate a discount for each order.
You can also create a field in a query that calculates a line item total, and then use that value in a form or report. A column in a query that results from such a calculation is called a calculated field. For example, the following expression in a query calculates the line item totals with an applied discount:
The expression gives the resulting column the name ExtendedPrice. You create a calculated field whenever you need to calculate or perform operations on the data in two or more table fields. For example, many tables store first and last names in separate fields. If you want to combine those first and last names and display them in a single field, you create a calculated field in a query. Some users try to create those types of calculated fields directly in tables, but
by default, tables do not support that type of operation they do not provide a field or property in which you can add the necessary expression.
A calculated field that combines first and last names would look like this: [FirstName] & " " & [LastName]. In this case, the ampersands combine the values in the FirstName and LastName fields with a space the double quotes with a space between them.
You can also use expressions to provide a default value for a field in a table or for a control. For example, if you have a date field that you want to default to the current date, you can type Date() in the Default Value property box for that field.
You can also use an expression to set a validation rule. For example, you might use a validation rule that requires the date that is entered to be greater than or equal to the current date. In that case, you set the value in the Validation Rule property box to >= Date().
Finally, you can also use an expression to set criteria for a query. For example, suppose you want to see product sales for the orders that were shipped within a certain time frame. You can enter criteria to define a date range, and Access returns only the rows that match the criteria:
When you add criteria to the query and then run the query, it returns only those values that match the specified dates.
Top of Page
Expressions often use the data in your tables and queries and also data stored in controls on forms and reports. To use those data, expressions reference the names of the fields in your tables and queries, and the names of your controls. To use field and control names in expressions, you enclose them in brackets ([ ]). For example, if you want to use a table field called Unit Price in an expression, you enter it as [Unit Price]. If you enter a name that doesn't include spaces or special characters, Access automatically encloses it in brackets. If a name includes spaces or special characters, you must type the brackets yourself.
For more information about expression syntax, see the article A guide to expression syntax.
The most common places where you use expressions include the following:
In a text box control on a form or report This creates a calculated control. For example, suppose you want to create a subtotal that sums all of the line items on an order form. The subtotal might look something like this on your form:
To calculate the subtotal, you place a text box control on the form and set the ControlSource property of the text box to the following expression:
=Sum([table_field])
In this case, table_field is the name of the field that contains your subtotal values. That field can reside in a table or a query. The Sum function calculates the total for a set of values from your record source.
The following steps explain how to enter an expression in a text box control.
2.
Right-click the text box that you want to change, and click Properties to display the property sheet for the control.
-or-
3.
On the Data tab or the All tab of the property sheet, click the ControlSource property of the text box, and then enter = and the rest of your expression. For example, to calculate the subtotal shown above, you type =Sum([table_field]), being sure to substitute the name of your field with table_field.
-or-
Your property sheet will look something like the following illustration:
4.
You use an expression to define criteria in a query. Access then returns only those rows that match the criteria. For example, suppose you want to see all orders whose shipped date occurs in the year 2004. To enter the criteria, you enter the following expression in the Criteria cell for the Date/Time column in your query. This example uses a Date/Time column called ShippedDate. To define a date range, enter the following criteria:
The ShippedDate column will look something like the following illustration.
The expression determines whether the values in the ShippedDate column fall in the date range that you specify. Note that you surround the dates with pound signs (#). Access treats a value within the pound signs as a Date/Time data type. If you are new to Access, treating those values as date/time data enables you to perform calculations on those values.
For more information about using date/time data, see the articles Enter a date or time value and Insert, create, or delete a field that stores date values.
2.
Click in the Criteria cell in the column for which you want to enter your criteria.
3.
-or-
On the Design tab, in the Query Setup group, click Builder to start the Expression Builder and build your criteria.
NOTE
If you want a larger area in which to enter an expression, press SHIFT+F2 to display the Zoom dialog box.
In this case, the expression uses the Format function to extract the year from the values in a field called ShippedDate. The Format function then formats the year as four digits. Prefacing the expression with Year Shipped: names the resulting column Year Shipped.
1.
In the Navigation Pane, right-click the query that you want to change, and then click Design View on the shortcut menu.
2.
Click the Field cell in the column where you want to create the calculated field.
3.
-or-
On the Design tab, in the Query Setup group, click Builder to start the Expression Builder and build your criteria.
NOTE
Do not precede the criteria expression with the = operator, but do start the expression with
a name followed by a colon. For example, you type ExtendedPrice: to start an expression that creates a calculated field called ExtendedPrice.
2.
In the Field Name column, click the field that you want to change.
3.
4.
-or-
to the right of the property box to start the Expression Builder and create
-or-
On the Design tab, in the Tools group, click Builder to start the Expression Builder.
NOTE
Do not precede the expression with the = operator when you create a validation rule.
The key point to remember when you work with validation rule expressions is that they must resolve to True for the value to be accepted. So, in this example, the value for [Units On Hand] must be >=0. If it isn't, Access displays the text shown in the Validation Text property box. If you haven't entered any text in the Validation Text property box, Access displays its own message to indicate that the value you entered is prohibited by the validation rule for the field.
For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
Property ValidationRule
Setting >=#1/1/2004#
ValidationText
If you try to enter a date earlier than 1/1/2004, a message appears. After you click OK, Access returns you to the text box.
-or-
If you already have the form or report open, right-click the document tab and click Design View on the shortcut menu.
-or-
On the Home tab, in the View group, click the View button to toggle between available views. Alternatively, you can click the arrow under View, and then select one of the available views from the menu.
2.
Right-click the control that you want to change and click Properties.
-or-
3.
Click the All tab, and then click the Validation Rule property box.
4.
Type the expression, or click the Build button expression by using the Expression Builder.
NOTE
Do not precede the expression with the = operator when you create a validation rule.
5.
6.
When you enter a value that the validation rule prohibits, you can press ESC while the cursor is in the control to restore the original or default value. You can then enter a value that satisfies the validation rule.
If the Control Source property for your control is a field in a table, it's usually best to set the field's Validation Rule property, in addition to that of the control. That way, the rule is enforced all the time, no matter which form or query is used to update the field.
For more information about creating validation rules, see the article Create a validation rule to validate data in a field.
The expression uses the Now function to insert the date and time into the OrderDate field.
2.
In the Field Name column, click the field that you want to change.
3.
4.
Type your expression, or click the Build button expression by using the Expression Builder.
If you bind a control to a table field, and the control and field have a default value, the control's default value takes precedence.
For more information about setting default values, see the article Set default values for fields or controls.
This expression uses the Date function to return the current date, but not the time. If you bind the text box to a table field, and the field has a default value, the control's default value takes precedence. It often makes better sense to set the Default Value property for the field in the table, because the default value is always applied to the control unless the control overrides it.
-or-
If you already have the form or report open, right-click the document tab and click Design View on the shortcut menu.
-or-
On the Home tab, in the View group, click the View button to toggle between available views. Alternatively, you can click the arrow under View, and then select one of the available views from the menu.
2.
Right-click the control that you want to change, and then click Properties.
-or-
3.
Click the All tab, and then click the Default Value property box.
4.
Type the expression, or click the Build button expression by using the Expression Builder.
5.
For more information about setting default values, see the article Set default values for fields or controls.
2.
If you do not see the Condition column in the macro designer, on the Design tab, in the Show/Hide group, click Conditions.
3.
In the Condition column, click the blank cell next to the macro action that you want to change, and then type your conditional expression.
4.
As with the Validation Rule property, the expression in the Condition column must resolve to either True or False. The macro action runs only when the condition is True.
For more information about creating macros, see the articles Macro basics in Access 2007 and Create a macro.
The following figure illustrates the pane as it appears when it first opens:
If you are new to Access, grouping is the process of combining columns that contain duplicate values. For example, suppose your database contains sales information for offices in different cities. One of the most common reports in that type of database is "Sales by City," and the query that provides the data for the report groups the data by your city values. Grouping can make your information easier to read and understand.
In contrast, sorting is the process of imposing an order on the rows (the records) in your query results. For example, you can sort records by their primary key values (or another set of values in another field) in either ascending or descending order, or you can sort them by one or more characters in (for example) alphabetical order. As you proceed, remember that, by default, queries in Access return records by the fastest means possible. When you first create a query, Access might return your data in a way that makes sense, such as by the sequence of primary key values. However, as users change data and add or remove rows, Access might return your data in a different sequence because that new sequence is faster. You
impose a sort order when you need your queries to return data in the same sequence, regardless of changes to that data.
For more information about combining text values, see the Combining text values section.
-or-
If you already have the report open, right-click the document tab and click Design View on the shortcut menu.
-or-
On the Home tab, in the View group, click the View button to toggle between available views. Alternatively, you can click the arrow under View, and then select one of the available views from the menu.
2.
On the Design tab, in the Grouping & Totals group, click Group & Sort.
The Group, Sort, and Total pane appears at the bottom of the working area.
3.
-or-
A new group or sort order appears in the pane, plus a list of the fields that provide data for the report. This figure illustrates a typical new group and sort order, plus a window that contains the available fields:
4.
In the window that contains the available fields, click expression to start the Expression Builder.
5.
Enter your expression in the expression box (the upper box) of the Expression Builder. Make sure you start the expression with the equal (=) operator.
2.
3.
Click the down arrow next to Group on (for grouping levels) or Sort by (for sort orders).
4.
At the bottom of the window that contains the fields, click expression to start the Expression Builder.
5.
Type your expression in the expression box of the Expression Builder. Be sure to preface your expression with the equal (=) operator.
For more information about using the Expression Builder, see the next section.
For more information about grouping and sorting the data in reports, see the article Create a grouped or summary report.
Top of Page
You can use the Expression Builder to create an expression from scratch, or you can select from some prebuilt expressions for displaying page numbers, the current date, and the current date and time.
You can start the Expression Builder from most of the places where you would write expressions manually, such as the Control Source property of a control or the Validation Rule property of a table field. As a rule, if you see the Build button ( ), you can click it to start the Expression Builder.
This figure and the text that follows illustrate the Expression Builder:
Expression box
The upper section of the builder contains an expression box where you construct your expression. You can type your expression in the box manually, or you can select elements from the three columns in the lower section of the Expression Builder and add them to your expression box. To add an element, double-click it or select it from one of the columns and then click Paste.
Operator buttons
The middle section of the Expression Builder displays buttons for inserting common arithmetical and logical operators into your expression. To insert an operator in the expression box, click the appropriate button. To display a longer list of operators that you can use in expressions, click the Operators folder in the lower-left column, and then click the category that you want in the middle column. The right column then lists all of the operators in the selected category. To insert an operator, double-click the operator, or select it and then click Paste.
Expression elements
The left column displays folders that list the tables, queries, forms, and reports in your database, as well as the available built-in functions and user-defined functions, constants, operators, and common expressions.
The middle column lists specific elements or categories of elements for the folder that is selected in the left column. For example, if you click Built-In Functions in the left column, the middle column lists function categories.
The right column lists the values, if any, for the elements that you selected in the left and middle columns. For example, if you click Built-In Functions in the left column and then click a function category in the middle column, the right column lists all of the built-in functions in the selected category.
You construct your expression by typing text in the expression box and pasting elements from the other areas in the Expression Builder. For example, you can click in the lower-left column to see any of the objects in your database, and also the functions, constants, operators, and common expressions. When you click an item in the left column, the other columns change accordingly. For example, when you click the name of a table in the left column, the middle column lists the fields in that table. When you double-click Functions and then click Built-In Functions, the middle column lists all of the function categories, and the right column lists the functions in those categories. When you double-click a function to insert it into your expression, the function and the text that indicates the needed arguments
for that function appear as placeholder text in the expression box. You can then replace that text with the argument values.
When you paste an identifier (the name of a table field or control) into your expression, the Expression Builder inserts only the parts of the identifier that are required in the current context. For example, if you start the Expression Builder from the property sheet of a form called Customers, and then paste an identifier for the Visible property of the form in your expression, the Expression Builder pastes only the property name Visible. If you use this expression outside of the context of the form, you must include the full identifier: Forms![Customers].Visible.
2.
If you open a table, in the Field Name column, click the field that you want to change, and then on the General tab, click the property that will contain the expression and click the Build button property. next to the
-or-
If you open a form or report, right-click the control that you want to change, click Properties, locate the property that will contain the expression, and then click the Build button next to the property.
-or-
If you have the query open, right-click the document tab for the query and click Design View on the shortcut menu.
2.
Click the cell in the design grid that will contain the expression. For example, click the Criteria cell for the column where you want to supply criteria, or click the Field cell for the column where you want to create a calculated field.
3.
For more information about creating expressions, including sample expressions and expression syntax, see the article A guide to expression syntax.
Top of Page
The following steps explain how to add a new field to a table, set the data type for the field to Date/Time, and then add the Now or Date functions to the field.
2.
Click the first blank column, located at the far side of the table. If you can't find the blank column, look for the words Add New Field in the column header.
3.
Double-click in the column header and type a name for the field, such as Date Added, and then press ENTER.
-or-
Right-click the column, click Rename, type a name for the field, and then press ENTER.
4.
On the Datasheet tab, in the Data Type & Formatting group, click the down arrow next to the Data Type list and select Date/Time.
5.
Save your changes, keep the table open, and go to the next set of steps.
2.
3.
4.
5.
Click the Show Date Picker property box and set the value to Never.
6.
Now, when you add a new record to the table, Access automatically inserts the date or the date and time into the Date Added field.
The expression uses the & operator to combine the values in the FirstName and LastName fields. The expression also uses a pair of double quotation marks separated by a space character to insert a space between the first and last names. Remember that the spaces between the field names and the ampersand operators do not affect the appearance of your data (they only make the expression easier to read). When you want to insert something between fields, such as a space, punctuation, or literal text, you must enclose that additional value in quotation marks.
As another example, you can use this expression to display last names and first names, separated by a comma:
In this case, the values surround by quotation marks insert a comma and a space between the names.
The steps in this section assume you have a form, and they assume you have a table with fields called FirstName and LastName. If not, you can alter the expression in these steps to suit your own data.
2.
3.
Drag the pointer on the form or report to create the text box.
4.
-or-
5.
6.
Change the value in the ControlSource property box to =[FirstName] & " " & [LastName], and then press TAB.
7.
At times, you may try to combine records that do not have a value entered in a field. The absent value is called a null value. When you use the & operator, and a field has no value, Access returns a zero-length string for that field. For example, if an employee's record has only a last name, the expression in the previous example returns a zero-length string for the First Name field, a space character, and the value in the Last Name field.
When you combine values, you might want to include a value, such as a comma, only when data exists in a particular field. To do that, you use the + operator instead of the & operator.
For example, suppose you have a table called Customer, and the table contains fields called City, Region, and Postal Code. You want to combine those fields for a report, and some records might not have a value in the Region field. In that case, you end up with an unwanted comma before the postal code value if you use the & operator.
To eliminate the unwanted comma, you can use the plus (+) operator, as shown in the following sample expression:
=([City] & (", " + [Region]) & " " & [PostalCode])
The + operator combines text in the same way as the & operator. However, the + operator also supports what is called Null propagation. This means that if any component of an expression is null, the entire expression is also null. In the previous example, consider the section that reads (", " + [Region]). Because the + operator is used, the expression within the inner parentheses includes a comma only if a value exists in the Region field. If a value does not exist, Null propagation goes into effect, and the entire expression within the inner parentheses evaluates to a null value, thus "hiding" the comma.
The result of a date calculation is called an interval. This value contains a days component on the left side of the decimal point, and a time component on the right side. If the value returned is a positive number, you know how many days early the order was shipped. If the value is negative, you know how many days late it was shipped. If the value is 0, you know the order was shipped on time.
The steps in this section assume that you have a form, and that form is bound to a table of data containing orders. In turn, the Orders table contains fields called RequiredDate and ShippedDate. You can alter the expression in the following steps to work with your database.
Add a text box that contains an expression to calculate the number of days early or late
1. In the Navigation Pane, right-click the form or report that you want to change and click Design View on the shortcut menu.
2.
3.
Drag the pointer on the form or report to create the text box.
4.
-or-
5.
6.
In the ControlSource property box, type =[RequiredDate]-[ShippedDate], and then press TAB.
NOTE
Remember to replace the RequiredDate and ShippedDate identifiers with the names of your own
table fields.
7.
When you use the +, , *, /, or \ operators to perform a calculation on two values, and one of the values is null (that is, no value has been entered), the value of the expression evaluates to a null value. For example, if one of the dates in the previous expression is null, the value of the entire expression is also null. On a report, that results in blank space. If you want to replace the null value with 0, you can use the Nz function to convert the null value to zero. For example:
=Nz([RequiredDate]-[ShippedDate],0)
NOTE
You can also set the fields in your table so that users can't enter null values. When you design the table, set
the Required property for that field to Yes. You should also set the DefaultValue property for that field to a non-null value.
The following steps assume you have a form with two controls that contain numeric data. In this case, the controls are called Subtotal and Freight. You can alter the control names in the following expression to work with your own data.
2.
3.
Drag the pointer on the form or report to create the text box.
4.
-or-
5.
6.
7.
NOTE
Remember to change the identifiers in the expression (Subtotal and Freight) to match the control
8.
For this exercise, assume that you have two table fields, SalesTaxRate and Subtotal. You could also store these values in other controls on a form or report, but for this exercise, assume they reside in a table.
2.
3.
Drag the pointer on the form or report to create the text box.
4.
-or-
5.
6.
7.
NOTE
Remember to change the field identifiers (Subtotal and SalesTaxRate) to match the field names
8.
For example, to count the number of orders in a report that shows orders grouped by customer, you can use the following expression:
=Count([OrderID])
You can use field names in the argument expression for the Sum and Count functions, but not control names. The field names can come from a table or a query. You can even use the name of a calculated field from a query. However, when you want to total the values in a calculated control, you must repeat the expression that is used in the calculated control in the function.
When you want to refer to the same expression more than once on a form, or if you are going to use a function, such as Sum, you should consider whether you can include the expression in the form's underlying query. That way, the calculation can be performed in the query instead of on the form. It is often faster to perform a calculation in a query.
For more information about summing and counting, see the following articles:
Counting in reports
Summing in reports
Count Function
DCount Function
Sum Function
DSum Function
The following sections explain some of the ways you can use these functions.
Create a calculated control on one form and reference that control from another form
At times, you may need to create a calculated control a control that uses an expression as its data source and then reference the values in that control from a separate control located on another form. The steps in this section explain how to use the SUM function in a calculated control, and then reference that control from another form.
The steps assume the use of an orders database and an order-entry form made up of two components a main form and a subform. The main form contains data about the entire order such as such as "bill to" and "ship to" information. The subform contains details about the line items in the order, such as products, quantities of each product, and the unit prices of each product.
Separate queries supply data to each component, and the query for the subform has a calculated field called ExtendedPrice. In this example, the "extended price" is the quantity of product in each line item multiplied by the number of items, any discounts, and so on.
To calculate the subtotal amounts for each order, you need to sum the values in the ExtendedPrice field. You do that by adding the following expression to a text box. In this example, the text box is located in the footer of the subform:
The following steps explain how to add the calculated control to the subform. Information after these steps explains how to reference the control from another control.
2.
If you cannot see the form footer section of the form, click the Form Footer bar, and then drag the lower edge of the bar downward.
3.
4.
In the form footer section, drag the pointer on the form to create the text box.
5.
-or-
6.
Click the All tab, and then set the property values as shown in the following table.
7.
NOTE
If you are adapting these steps to work with your own data, remember to change the field name
8.
Click the box in the upper left or right corner of the subform the box next to the ruler to display the properties for the entire subform.
9.
Locate the Default View property box and change its value to Datasheet.
10. Save your changes, close the property sheet, and go to the next steps.
Although the text box on the subform calculates the order subtotal, you might not want to display the resulting values in the subform because subforms often appear as datasheets. Adding a subtotal would, at the least, mean that users see the same value many times. For example, you could see this type of result:
Quantity 4 5 6
As you can see, a piece of summary data belongs in a single field, and it often makes sense to put that field on a main form. To do that, you add a control to the main form that references the control on the subform. The following illustration shows how you can do this:
The Form property, which provides access to the subform's controls and properties
The following steps explain how to create a text box that references the values in another control.
2.
3.
Locate the area on the form to which you want to add the control, and then drag the pointer on the form to create the text box.
4.
-or-
5.
6.
7.
NOTE
If you are adapting these steps to work with your own data, remember to change the identifiers
(the form and control names between the square brackets) to match the names in your own database.
8.
Access provides two ways to do that type of task. You can use the Lookup Wizard to create a lookup field (the most common technique), or you can create an expression. A discussion of the Lookup Wizard is beyond the scope of this topic, so for more information, see the article Add or change a field to look up a value in another table.
To create an expression that looks up values in another table, you use the DLookup function. You supply three arguments to the DLookup function:
To add the supplier contact, open the Products form in Design view and then add a text box with the label Contact Name. The expression to use for this text box is:
2.
3.
Locate the area in the form to which you want to add the control, and then drag the pointer on the form to create the text box.
4.
-or-
5.
6.
7.
This expression searches in the Suppliers table and returns the contact name of the supplier whose supplier ID matches the value in the SupplierID control on the Products form. Note how the & operator is used to construct the third argument. A common error that you should avoid is placing quotation marks around the entire argument instead of around only the text before the & operator.
NOTE
As an alternative to using the DLookup function, you can alter the underlying query to include only the
2.
If you cannot see the footer section of the report, click the Report Footer bar, and then drag the lower edge of the bar downward to expand the report.
3.
4.
In the report footer section, drag the pointer to create the text box.
5.
-or-
6.
Click the All tab, and then set the property values as shown in the following table.
7.
This is the same procedure that you follow when using a function such as Now or Date, except that you don't include parentheses after the Page property.
This figure shows how you can add the Page property directly to a text box control:
In addition, you can also construct an expression that uses the Page and Pages properties. The Pages property returns the total number of pages in the report. For example, the following expression produces page numbering in the format Page 1 of 10.
The following steps explain how to add an expression that uses both properties to the footer of a report. The steps explain how to add page numbers in Design view, and by using Layout view.
2.
If you cannot see the footer section of the report, click the Report Footer bar, and then drag the lower edge of the bar downward to expand the report.
3.
4.
In the report footer section, drag the pointer to create the text box.
5.
-or-
6.
Click the Data tab, and then change the value in the Control Source property box to: ="Page " & [Page] &" of " & [Pages].
7.
2.
3.
4.
5.
6.
Select or clear the Show Number on First Page check box, and then click OK.
NOTE
The Expression Builder includes some common expressions that you can use for page numbering. For
more information about using the Expression Builder, see the section Using the Expression Builder to create expressions.
You use the Left function to extract the first n characters of a value in a Text field and the Right function to extract the last n characters. In both cases, the first argument is the field name or text expression, and the second argument is the number of characters that you want to extract.
The following table shows expressions that employ these functions. The functions assume that the data resides in a table field called PartID.
Returns AA 105
For more information about the Left and Right functions, see the articles Left Function and Right Function.
To start a new group each time the first letter of the product name changes, and then sort the products within each group alphabetically, you create two groups in the Group, Sort, and Total pane and then set each group as shown in the following tables.
Group on ProductName
with A on top
by first character
with no totals
Sort on ProductName
with A on top
by entire value
with no totals
2.
On the Design tab, in the Grouping & Totals group, click Group & Sort.
To print only the first letter of the name at the beginning of a new group, use this expression in the text box in the ProductName header:
=Left([ProductName],1)
To find a portion of a numeric date value, such as just the month or year, you use the DatePart function. The function uses the following syntax:
The interval argument is the abbreviation for the part of the date that you want returned. Examples of valid abbreviations are "yyyy" for a four-digit year, "q" for a calendar quarter, and "m" for a month. The date argument is a field name or a literal date, such as "1-Jul-07."
The firstdayofweek and firstweekofyear arguments are optional. The firstdayofweek argument returns Sunday, unless you specify otherwise. To specify a different day, enter a value between 2 and 7 (1 is the default value). The
firstweekofyear returns the week in which January 1 occurs. To specify a different week, enter 2 or 3. Use 2 to specify the first week that has at least four days in the new year; use 3 to specify the first full week of the year.
The following table lists examples of the results that are returned for a field named "Holiday." The Holiday field can store the holidays that are celebrated in the countries or regions where your company does business.
To learn more about creating grouped reports, see the article Create a grouped or summary report.
To create the group headers and footers and specify the sort order for this report, you create two groups, each with its own sort order, and you set the properties in the Group, Sort, and Total pane for each group and sort order as shown in the following tables. Note that you use an expression to group by the quarter when the orders were shipped.
ascending
by entire value
with no totals
Group on ShippedDate
by year
with no totals
2.
On the Design tab, in the Grouping & Totals group, click Group & Sort.
To print the quarter number at the beginning of a new group, you place a text box in the group header by using the same expression that you used in the Sorting and Grouping box:
=DatePart("q", [ShippedDate])
Order Details table, and the Customers table. You can then create a calculated field in the query design grid that calculates the extended price for each product on the invoice.
2.
Click the Field row of an empty column in the query design grid.
3.
Type a name, a colon (:), and an expression in the Field cell. The name and colon define a user-friendly name for you calculated field. To calculate an extended price, you can use an expression like this:
Note that when you create a calculated field in the query design grid, do not precede your expression with the = operator.
The expression for this report compares the value in the Shipped Date field to the value in the Required Date field. If the value in the Shipped Date field is greater (that is, a later date) than the value in the Required Date field, the expression returns the value True, and the report shows a check mark in the check box. If the value is False, the report leaves the check box empty.
2.
3.
Drag the pointer in the detail section of the report to create the check box.
4.
Right-click the check box, click Properties on the shortcut menu, and then click the All tab in the property sheet.
5.
Set the properties for the check box as shown in the following table.
6.
NOTE
If you are adapting these steps to work with your own data, remember to change the field names
7.
Top of Page
Table of operators
Access supports a variety of operators, including arithmetic operators such as +, -, * (multiply), and / (divide), in addition to comparison operators for comparing values, text operators for concatenating text, logical operators for determining true or false values, and other operators specific to Access. For details about using these operators, see the following tables:
Arithmetic operators
You use the arithmetic operators to calculate a value from two or more numbers or to change the sign of a number from positive to negative.
Operator + -
Purpose Sum two numbers. Find the difference between two numbers or indicate the
negative value of a number. * / Multiply two numbers. Divide the first number by the second number. Round both numbers to integers, then divide the first number by the second number. Then, truncate the result to an integer. Divide the first number by the second number and return only the remainder. Raise a number to the power of an exponent. [Quantity]*[Price] [Total]/[ItemCount]
[Registered]\[Rooms]
Mod
Number ^ Exponent
Comparison operators
You use the comparison operators to compare values and return a result that is true, false, or null.
Operator <
Purpose Determine if the first value is less than the second value. Determine if the first value is less than or equal to the second value. Determine if the first value is greater than the second value. Determine if the first value is greater than or equal to the second value. Determine if the first value is equal to the second value. Determine if the first value is not equal to the second value.
<=
>
>=
<>
In all cases, if either the first value or the second value is null, the result is then also null. Because null represents an unknown value, the result of any comparison with null is also unknown.
Logical operators
You use the logical operators to combine two values and return a true, false, or null result. You might also see the logical operators referred to as Boolean operators.
Operator And
Description True when Expr1 and Expr2 are true. True when either Expr1 or Expr2 is true. True when both Expr1 and Expr2 are true or both Expr1 and Expr2 are false. True when Expr is not true. True when either Expr1 is true, or Expr2 is true, but not both.
Or
Expr1 Or Expr2
Eqv
Not Xor
Concatenation operators
You use the concatenation operators to combine two text values into one.
Operator &
Description Combines two strings to form one string. Combines two strings to form one string and propagates null values.
string1 + string2
Special operators
Description Determines whether a value is Null or Not Null. Matches string values by using wildcard operators ? and *. Determines whether a numeric or date value falls within a range. Determines whether a string value is found within a set of string values.
Like "pattern"
Like Operator
Between...And Operator
In(string1,string2...)
In Operator
Introduction to filters
A filter changes the data that a form or report displays in a view without altering the design of the form or report. You can think of a filter as a criterion or a rule that you specify for a field. The criterion identifies the field values that you are interested in viewing. When you apply the filter, only records that contain the values that you are interested in are included in the view. The rest are hidden until you remove the filter.
NOTE
Filters are easy to apply and remove. In Microsoft Office Access 2007, common filters are built into every view that displays data, including Layout view. The availability of filter commands depends on the type and values of the field.
For example, you can view the records of only those people whose birthdays fall during a specific month by clicking the appropriate menu commands.
The filters that are available to you depend on the type of data that is in the selected column.
All Dates in Period filters ignore the day and year portion of the date values.
When a filter is applied, the view is updated to show only the records that match your criteria. In this case, you see only those customer records in which the month portion of the BirthDate field is set to April. All other records are hidden.
Icons in the column header and the record navigator bar indicate that the current view is filtered on the BirthDate column.
Hovering the mouse over the column heading displays a tip showing the current filter criterion.
When you apply a filter to a column that is already filtered, the previous filter is removed before the new filter is applied. For example, if the BirthDate field is already filtered to show birthdays that fall in April, when you apply a filter to see birthdays that fall in February, the result will include only birthdays that fall in February. Access automatically removes the filter that returned only birthdays in April before applying the second filter.
Though only a single filter will be in effect for any one field at any one time, you can specify a different filter for each field that is present in the view. For example, to see the names of those contacts who live in the UK whose birthdays fall in April, you can filter the Contacts table on the CountryRegion field and also on the BirthDate field.
When you filter multiple fields in a single view, the filters are combined by using the AND operator, like this:
You can work with the filtered results in the same way that you work with the initial view for example, you can edit the data, and you can navigate to other records.
You can revert to the unfiltered view by removing the filters. Removing a filter temporarily removes it from the view, so that you can switch back to the original, unfiltered view. In the Sort & Filter group on the Home tab, you can click Toggle filter to switch between filtered and unfiltered views.
You can also permanently remove a filter from a view by clearing the filter. To learn how to clear filters, see the section Clear or save a filter.
Filter settings will be in effect until you close the object, even if you switch to another view of the object. In other words, if you filter a form in Datasheet view, the filter settings will still be in effect if you switch to Form view or Layout view, and will remain in effect until you close the form. If you save the object while the filter is applied, it will be available the next time that you open the object.
Whether the filter settings will be in effect when you open the object the next time depends on the FilterOnLoad property setting for the object. If you set the FilterOnLoad property of a table, query, form, or report to Yes, the filter settings that were last applied will be applied when you reopen the object.
NOTE
The FilterOnLoad property setting is only applied when the object loads. Setting this property for an object in
Design view and then switching to another view will not cause the setting to be applied. You must close and reopen the object for changes to the FilterOnLoad property setting to take effect.
Top of Page
Types of filters
Office Access 2007 offers several ready-to-use filters for each data type. These filters are available as menu commands in the following views: Datasheet, Form, Report, and Layout. In addition to these filters, you can also filter a form or datasheet by completing a form (called Filter by Form).
If you want more flexibility, and if you are comfortable writing expressions, you can create your own filters by using the options on the Filter document tab.
Following is a little more information about each type of filter that is available to you in Access.
Common filters
Several popular filters are available as context menu commands, so that you don't have to spend time constructing the correct filter criteria. To access these commands, right-click the field you want to filter.
NOTE
If you select two or more columns or controls, the filter options will not be available. If you want to filter the
view on multiple columns or controls, you must either select and filter each column or control separately, or use an advanced filter option. See the Filter by form and Advanced filters sections in this article for more information.
Except for OLE Object fields and fields that display calculated values, all field types offer common filters. The list of filters that are available depends on the selected field's data type and values.
For example, to see the filters available for the BirthDate field:
On the Home tab, in the Sort & Filter group, click Filter.
To filter for specific values, use the check box list. The list displays all the values that are currently displayed in the field.
To filter for a range of values, click one of these filters, and specify the required values.
For example, to see birthdays that fall between the current date and the end of the year, click Between, and then specify the appropriate start and end dates in the Between dialog box.
To see all birthdays that fall on a specific date, use the value list. In an unfiltered view, the value list for each field presents all of the unique values that are stored in that field.
NOTE
When a view is filtered, the value list for each field shows only the unique values that are visible in the view.
For example, if the CountryRegion field is filtered to show only records that have the value USA, the value list of the Full Name field will show only the names of those who live in the USA. To see more values in the value list, remove some or all filters from the view.
It is important to note that the values in a date field have an impact on the list of type-specific filters. If the most recent date value in a date field falls within the past two years, you see a longer, more detailed filter list. If none of the dates in a field is less than two years old, you see the shorter filter list.
NOTE
Type-specific filters are not available for Yes/No, OLE object, and attachments fields. The values list is not
available for memo fields, or for fields that contain rich text.
For example, if the value 2/21/1967 is currently selected in the BirthDate field, on the Home tab, in the Sort & Filter group, click Selection to display the filter by selection commands.
The command list automatically includes the current value, so that you don't have to type it.
The list of commands also depends on how much of the value is selected. For example, if you select only some of the characters in the value, you see a different list of commands, depending on which part of the field you selected.
NOTE
Filter by form
This technique is useful when you want to filter on several fields in a form or datasheet, or if you are trying to find a specific record. Access creates a blank form or datasheet that is similar to the original form or datasheet, and then
allows you to complete as many of the fields as you want to. When you are done, Access finds the records that contain the specified values.
NOTE
You cannot specify field values for multivalued fields using filter by form, nor for fields with Memo, Hyperlink,
Yes/No, or OLE Object data type, although you can specify values for other fields in the recordset.
For example, if you want to find all Customer records where the contact person's title is Owner, and that person is located either in Portland or in Eugene, open the Customers form and, on the Home tab, in the Sort & Filter group, click Advanced Filter/Sort, and then click Filter by Form.
Enter the first set of values, then click the Or tab, and then enter the next set of values. Note that if you want a field value to operate as a filter independently of other field values, you must enter that value on the Look for tab and each Or tab. Each Or tab represents an alternate set of filter values.
On the Home tab, in the Sort & Filter group, click Toggle Filter.
Advanced filters
On occasion, you might want to apply a filter that is not in the common filters list. For example, if you want to find records that contain dates that occur during the past seven days or the past six months, you might have to write the filter criterion yourself.
Using this feature requires that you are familiar with writing expressions. Expressions are similar to formulas that you write in Excel, and to the criteria that you specify when designing a query.
For example, if you want to find the names of those contacts whose birthdays occurred during the past seven days, you can use an advanced filter.
On the Home tab, in the Sort & Filter group, click Advanced and then click Advanced Filter/Sort on the shortcut menu.
You add the filter fields to the design grid, and specify the filter criteria in the Criteria row.
When you click Toggle Filter in the Sort & Filter group on the Home tab, Access displays the filtered records.
Continuing with the same example, if you want to further limit the results to those whose country/region is USA, switch back to the Filter object tab, add the CountryRegion field to the grid, and then specify a criterion.
Top of Page
Apply a filter
Apply a common filter Apply a filter based on selection Apply a filter by filling out a form Apply an advanced filter
NOTE
If you do not see the filter commands in any of the views, the designer of the form or database might have
2.
Make sure that the view is not already filtered. On the record selector bar, verify that either the Unfiltered or the dimmed No Filter icon is present.
TIP
To remove all the filters for a particular object, on the Home tab, in the Sort & Filter group, click
3.
Click anywhere in the column or control that corresponds to the first field that you want to filter.
4.
On the Home tab, in the Sort & Filter group, click Filter.
5.
To apply a common filter, point to Text (or Number or Date) Filters, and then click the filter that you want. Filters such as Equals and Between prompt you to enter the necessary values.
TIP
Certain characters, such as *, %, and ?, have a special meaning when specified in a filter text
box. For example, * represents a string of characters, so the string a* will match any string that begins with a, and not only the literal string a*. To disregard the special meaning of a character, enclose it in square brackets [], like this: a[*]. Databases that use the ANSI-89 standard treat *, ?, [, ], !, -, and # as special characters. Databases that use the ANSI-92 standard treat %, _, [, ], ^, and - as special characters. You can use either standard with Access, but you cannot mix the two standards (e.g., ?a*) in a particular expression.
To apply a filter based on field values, clear the check boxes next to the values on which you do not want to filter, and then click OK.
Hint If you have a large list of values, and if you want to filter on one or only a few of those values, first clear the (Select All) check box and then select the values you want.
To filter for null values (a null value indicates the absence of data) in text, number, and date fields, in the check box list, clear the (Select All) check box, and then select the check box next to (Blanks).
6.
Repeat the previous three steps for each field that you want to filter.
2.
Make sure that the view is not already filtered. On the record selector bar, verify that either the Unfiltered or the dimmed No Filter icon is present.
3.
Move to the record that contains the value that you want to use as part of the filter, and then click inside the column (in Datasheet view) or control (in Form, Report, or Layout view). To filter based a partial selection, select the characters that you want.
4.
On the Home tab, in the Sort & Filter group, click Selection, and then click the filter you want to apply.
5.
To filter other fields based on a selection, repeat the preceding two steps.
2.
Make sure the view is not already filtered. On the record selector bar, verify that either the Unfiltered or the dimmed No Filter icon is present.
3.
On the Home tab, in the Sort & Filter group, click Advanced, and then click Filter by Form on the shortcut menu.
4.
Depending on whether you are working in Datasheet view or in Form view, do one of the following:
In Datasheet view, click the first row in the column on which you want to filter. Click the arrow that appears, and select a value. You can add additional values by clicking the Or tab at the bottom of the datasheet and selecting another value.
In Form view, click the arrow that appears in the control, and select a value on which to filter. You can add additional values by clicking the Or tab at the bottom of the form and selecting another value. Click the Or tab to add even more values.
NOTE
You cannot specify field values for multivalued fields using filter by form, although you can specify
If you do not see a list of field values when you click the drop-down arrow for a field
Verify that the data type for the field is not Memo, Hyperlink, Yes/No, or OLE Object. Fields of these data types cannot be made to display field values on the Filter By Form object tab. Multivalued fields similarly cannot display values on the Filter By Form object tab.
If the number of records read is more than the number specified in the Default max records box in the Filter lookup options for Database section in the Access Options dialog box, Access doesn't display values for that field on the list. To open the Access Options dialog box, click the Microsoft Office Button , and then click Access Options. Click Editing, then change the Default max
In the Access Options dialog box, click Editing. In the Filter lookup options for Database section, select the Local indexed fields and Local nonindexed fields check boxes.
To specify a list of possible values for a field, use the or operator. For example, you can specify "Portland" or "Oregon" in the City field to filter for records containing either value.
To filter based on the status of a control, such as a check box or button, click the control so that it is in the state that you want. To return the control to a neutral position, so that it won't be used as a criterion for filtering records, ensure that it is unavailable (appears dimmed).
To filter for records that have null (missing), non-null, blank (empty or ""), or nonblank values, type Is Null, Is Not Null, "", or Not "" in the field.
5.
Sometimes, you might want to specify two alternate sets of criteria. For example, you might want to see the names of only those contacts whose CountryRegion value is USA and whose birthdays fall in April, or the names of only those contacts whose CountryRegion value is Asia and whose birthdays fall in May.
To retrieve all records that meet any one of multiple sets of criteria, you need to specify the criteria somewhat differently.
Enter the first set of criteria, then click the Or tab, and then enter the next set of criteria. Note that if you want a field value to operate as a filter independently of other field values, you must enter that value on the Look for tab and each Or tab. In other words, the Look for tab and each Or tab represents an alternate set of filter values.
Note that each time you add a field criterion to the Or tab, Access creates another Or tab. This enables you to specify several "or" criteria. The filter returns any record that contains all of the values specified on the Look for tab, or all of the values specified on the first Or tab, or all of the values specified on the second Or tab, and so on.
6.
To remove the filter and show all records, click Toggle Filter again.
7.
2.
Make sure that the view is not already filtered. On the record navigator bar, verify that No Filter appears dimmed (is unavailable). If the record navigator bar is not visible, click Advanced in the Sort & Filter group on the Home tab, and then click Clear All Filters (if Clear All Filters appears dimmed, there are no filters in effect).
3.
On the Home tab, in the Sort & Filter group, click Advanced and then click Advanced Filter/Sort on the shortcut menu.
4.
5.
In the Criteria row of each field, specify a criterion. The criteria are applied as a set, and only records that match all of the criteria in the Criteria row are displayed. To specify alternate criteria for a single field, type the first criterion in the Criteria row and the second criterion in the Or row, and so on.
NOTE
The entire set of criteria in the Or row is applied as an alternative to the set of criteria in the
Criteria row. Any criterion that you want to be applied for both sets of criteria must be typed in both the Criteria row and the Or row.
6.
TIP
A good way to learn to write criteria is to apply a common filter or a filter based on selection that produces a
result that is close to what you are looking for. Then, with the filter applied to the view, display the Filter object tab:
On the Home tab, in the Sort & Filter group, click Advanced and then click Advanced Filter/Sort on the shortcut menu.
Review the result, and then revise the criteria displayed in the Criteria row to produce the desired result.
NOTE
Two special commands are available to you on the Filter document tab. When you right-click anywhere
above the design grid on the tab, the Load from Query and Save As Query commands are available on the shortcut menu.
The Load from Query command loads the design of a selected query into the grid. This lets you use the query critieria as filter criteria. The Save As Query command lets you save the filter settings as a new query.
Top of Page
Click Filtered on the record navigator bar to revert to the full view.
When you remove the current filters, the filters are temporarily removed from all of the fields in the view. For example, if you first apply filters on the CountryRegion and BirthDate fields, and then remove the filters, you see all of the records again.
Click Unfiltered on the record navigator bar to reapply the most recent filters.
The most recent filter settings are reapplied to the view. To continue the previous example, the previously applied filters on the CountryRegion and BirthDate fields are reapplied.
Top of Page
You can clear a single filter from a single field, or clear all filters from all fields in the view.
To clear a single filter from a single field, right-click the filtered column or control, and then click Clear filter from field name.
On the Home tab, in the Sort & Filter group, click Advanced, and then click Clear All Filters on the shortcut menu.
It is easy to save filters for future use. The filter settings that are in effect at the time when you close a table, query, form, or report are automatically saved along with the object, and they are available to you for reapplying. However, by default, the filter settings are not automatically applied for you when you next open the object.
To ensure that the current filters are automatically applied when you next open a table, query, form, or report, set the object's FilterOnLoad property to Yes. You set this property in the object's property sheet. The FilterOnLoad property is applied when you open the object; when you change this setting, you must close the object and reopen it in order to apply the new setting.
Introduction
A select query is a type of database object that shows information in Datasheet view (Datasheet view: A window that displays data from a table, form, query, view, or stored procedure in a row-and-column format. In Datasheet view, you can edit fields, add and delete data, and search for data.). A query can get its data from one or more tables, from existing queries, or from a combination of the two. The tables or queries from which a query gets its data are referred to as its recordsource.
Whether you create simple select queries by using a wizard or by working in Design view, the steps are essentially the same. You choose the recordsource that you want to use and the fields that you want to include in the query and, optionally, you specify criteria to refine the results.
After you have created a select query, you run it to see the results. Running a select query is simple you just open it in Datasheet view. You can then reuse it whenever you need, for example, as a recordsource for a form, report, or another query.
NOTE
For more information about using a query as a recordsource for a form or report, see the article Use a query
There are several types of query, each serving a different purpose. For example, a select query displays data. An action query changes the data in its datasource, or creates a new table. A parameter query prompts you to supply criteria when you run it. This topic only covers select queries.
NOTE
This topic describes how to create select queries that return data from a single table. If you want to create
queries that return data from two or more tables, see the article Create a query based on multiple tables.
Top of Page
Create a query
In this exercise, you will create the London Contacts select query. You can create this query either in Design view or by using a wizard. In addition, if you are familiar with writing SQL statements (SQL string/statement: An expression that defines an SQL command, such as SELECT, UPDATE, or DELETE, and includes clauses such as WHERE and ORDER BY. SQL strings/statements are typically used in queries and in aggregate functions.), you can create a query while working in SQL view by writing a simple SELECT statement.
Before you begin, you need to have a table that contains data. Sample data is provided below in HTML table form.
Custom erID 1 Addre ss 1 Main St. StateOrPro vince NY PostalC ode 12345 CountryOrR egion USA Pho ne (202 ) 555012 2 (201 ) 555012 3 (206 ) 555004 2 (171 ) 555012 5 (171 ) 555016 5 (206 ) 555000 7 (171 ) 555017 8 (503 ) 555008 6 Cont act Steve Riley BirthD ate 03Dec-45
52 1st St.
Bosto n
MA
01234
USA
Walee d Heloo
21Mar-59
Coho Winery
Seattl e
WA
98100
USA
Guido Pica
01-Apr73
1 Contos o Blvd.
Lond on
NS1 EW2
UK
16-Jun67
Fourth Coffee
Lond on
W1J 8QB
UK
Julian Price
09Aug-71
Consolidate d Messenger
Seattl e
WA
98100
USA
27May-48
151 Strand
Lond on
WC2R 0ZA
UK
Dana Birkb y
12Aug-61
Litware, Inc.
Portla nd
OR
97200
USA
Jespe r Aaber g
01Sep-75
Tailspin Toys
Lond on
WC1 0AC
UK
Phil Gibbi ns
15-Feb53
10
Woodgrove Bank
Lond on
EC2R 7ED
UK
(171 ) 555010 1
Tom Perha m
25Sep-38
You can either enter the data in this sample table manually, or you can copy this table to a spreadsheet program, such as Microsoft Office Excel 2007, and then import the resulting worksheet into a table in Microsoft Office Access 2007.
1.
NOTE
You do not need to follow this step if you open a new, blank database, but you will need to follow it
2.
Double-click the first cell in the header row and type the name of the field in the sample table.
By default, Access denotes blank fields in the header row with the text Add New Field, like so:
3.
Use the arrow keys to move to the next blank header cell and then type the second field name (you can also press TAB or double-click the new cell). Repeat this step until you enter all field names.
4.
As you enter the data, Access infers a data type for each field. Each field in a table has a specific data type, such as Number, Text, or Date/Time. Data types help ensure accurate data entry and help to prevent mistakes, such as using a telephone number in a calculation. You can specify the data type for each field in a table, and can change a field's data type under certain circumstances. For this sample table, you should let Access infer the data type.
5.
6.
In the Table Name box, enter Customers, and then click OK.
Copy the table to a spreadsheet program and then import it into Access
1.
Start your spreadsheet program and create a new, blank file. If you use Excel, a new, blank workbook is created by default.
2.
Copy the sample table provided in the previous section and paste it into the first cell of the first worksheet.
3.
Using the technique provided by your spreadsheet program, name the worksheet Customers.
4.
Save the spreadsheet file to a convenient location and go to the next steps.
1.
-or-
Click More, and then select a spreadsheet program from the list.
The Get External Data - Program Name Spreadsheet dialog box appears.
2.
Click Browse, open the spreadsheet file that you created in the previous steps, and then click OK.
3.
By default, the wizard selects the first worksheet in the workbook (Customers, if you followed the steps in the previous section), and data from the worksheet appears in the lower section of the wizard page. Click Next.
4.
On the next page of the wizard, select First row contains column headings, and then click Next.
5.
The next page of the wizard offers you an opportunity to change field names and data types or to omit fields from the import operation, by using the text boxes and lists under Field Options. You should not do this for this example. Click Next.
6.
On the next page of the wizard, in the Field Options box, select Yes (No Duplicates) from the Indexed list, and select Long Integer from the Data Type list. Click Next to continue.
7.
On the next page of the wizard, select the Choose my own primary key option, choose CustomerID from the list, and then click Next.
8.
By default, Access applies the name of the worksheet to your new table. Make sure that the table is named Customers, and then click Finish.
9.
On the last page of the wizard, you have the option of saving the import steps for later reuse. Because you are importing a sample table, it is not recommended that you save the import steps.
1.
2.
In the New Query dialog box, click Simple Query Wizard, and then click OK.
3.
Under Tables/Queries, click the table that has the data that you want to use. In this case, click Table: Customers. Note that a query can also use another query as a recordsource.
4.
Under Available Fields, double-click the Contact, Address, Phone, and City fields. This adds them to the Selected Fields list. When you have added all four fields, click Next.
5.
Access displays all of the contact records in Datasheet view. The results show all of the records, but show only the four fields that you specified in the query wizard.
6.
Close the query, and note that your query is automatically saved.
Top of Page
To restrict the records that are returned in the query results, you can specify one or more criteria.
You can think of a query criterion as a condition that you specify for a field. The criterion specifies a condition, based on field values, that expresses what you want to include in the query, such as "show only those records where the value of City is London".
Open the query in Design view. You will add a criterion to the City field so that you see only those contacts who are from London in the query results. You will also add criteria to the Address field and the Phone field, to further refine your query results.
1.
Now, add two more criteria to make the results even more meaningful. Suppose that you only want to see the records in which both the address and the phone number are present.
2.
In the Criteria row of the Address field, type Is Not Null AND <>"". Do the same in the Criteria row of the Phone field.
NOTE
The criterion, Is Not Null AND <>"", is true whenever there is any known, non-empty value for the
field for which it is a criterion. It is false whenever there is no known value (Null), or when the value is known to be empty (""). You can use this expression to check a field for a known, non-empty value.
3.
What if you don't want the conditions to get combined by using the AND operator? In other words, how do you specify two or more criteria but include the records that satisfy one or both of them?
To specify alternate criteria, use both the Criteria and Or rows in the design grid. All records that meet the criteria defined either in the Criteria row or in the Or row are included in the result.
Now you will modify the query by entering alternate criteria in the Criteria and Or rows.
1.
2.
Remove the Is Not Null AND <>"" string from the Criteria row of the Phone field.
3.
In the Or row of the Phone field, type Is Not Null AND <>"".
4.
5.
Switch to Datasheet view to see the results. All records that include either an address, a phone number, or both, and where City is London, are displayed in the query results.
NOTE
To specify more than two alternate criteria sets, use the rows below the Or row. Each row
To learn more about how to specify criteria for various types of fields, see Examples of query criteria.
Top of Page
In this exercise, you will modify the London Contacts query so that it displays each contact's date of birth and current age.
1.
2.
From the Customers table window, drag the BirthDate field to the first blank column in the design grid. You can also double-click the field name to automatically add it in the first blank column.
3.
In the next column, in the Field row, type the expression that will calculate the age for each record. Type Age: DateDiff ("yyyy", [BirthDate], Date()).
Age is the name you are using for the calculated field. If you do not supply a name, Access will use a generic name for the field, for example, EXPR1. The string following the colon (:) is the expression that supplies the values for each record. The DateDiff function calculates the difference between any two dates, and returns that difference in the specified format. The format, yyyy, returns the difference in years, and the [BirthDate] and Date() elements of the expression supply the two date values. Date is a function that returns the current date, and [BirthDate] refers to the BirthDate field in the underlying table.
NOTE
The calculation used for Age in this example is an approximation that may be slightly inaccurate,
Switch to Datasheet view. You see two additional fields, BirthDate and Age, in the result.
For more information about how to write expressions that calculate values in a query, see the article Create an expression.
Top of Page
You can use a different aggregate function for each column. You can also choose not to summarize a column.
In this exercise, you will modify the London Contacts query so that it displays the Total row.
1.
2.
3.
In the drop-down list, you can choose between None and Count. Because the Contact column displays text values, other functions, such as Sum and Average, are not relevant, and are therefore not available.
4.
Select Count to count the number of contacts that are displayed in the result.
5.
In the Age field, select Average. Because the Age field evaluates to a number, it supports the Sum,Average, Count, Maximum, Minimum, Standard Deviation and Variance functions.
To clear the total for a column, click in the Total row under that column, then select None from the drop-down list. To hide the Total row, on the Home tab, in the Data Type & Formatting group, click Totals.
Standard Deviation , for measuring how widely values are dispersed from an average value (a mean).
Variance, for measuring the statistical variance of all values in the column.
Office Access 2007 provides two ways to add Count and other aggregate functions to a query. You can:
Open your query in Datasheet view and add a Total row. The Total Row, a new feature in Office Access 2007, allows you to use an aggregate function in one or more columns of a query result set without having to change the design of your query.
Create a totals query. A totals query calculates subtotals across groups of records. For example, if you want to subtotal all sales by city or by quarter, you use a totals query to group your records by the category you want and then sum the sales figures. In contrast, a Total row calculates grand totals for one or more columns (fields) of data.
NOTE
The how-to sections in this document emphasize using the Count function, but remember that you can use
other aggregate functions in your Total rows and queries. For more information about using the other aggregate functions, see Aggregate function reference later in this article.
For more information about ways to use the other aggregate functions, see the article Display column totals in a datasheet.
The steps in the following sections explain how to add a Total row and how to use a totals query to count data. As you proceed, remember that the Count function works on a larger number of data types than do the other aggregate functions. For example, you can run a Count function against any type of field except one containing complex, repeating scalar data, such as a field of multivalued lists.
In contrast, many of the aggregate functions work only on data in fields set to a specific data type. For example, the Sum function works only with fields set to the Number, Decimal, or Currency data types. For more information about the data types that each function requires, see Aggregate function reference, later in this article.
For general information about data types, see the article Modify or change the data type set for a field.
Top of Page
2.
In the Show Table dialog box, double-click the table or tables that you want to use in your query, and then click Close.
The selected table or tables appear as windows in the upper section of the query designer. This figure shows a typical table in the query designer:
3.
Double-click the table fields that you want to use in your query.
You can include fields that contain descriptive data, such as names and descriptions, but you must include the field that contains the values that you want to count.
4.
5.
Optionally, go back to Design view and adjust your query. To do so, right-click the document tab for the query and click Design View. You can then adjust the query as needed by adding or removing table fields. To remove a field, select the column in the design grid and press DELETE.
6.
-or-
For a database created with an older version of Access, on the Home tab, in the Views group, click the arrow below View and click Datasheet View.
-or-
In the Navigation Pane, double-click the query. Doing this runs the query and loads the results into a datasheet.
2.
A new Total row appears below the last row of data in your datasheet.
3.
In the Total row, click the field that you want to sum, and then select Count from the list.
For more information about using a Total row, see the article Display column totals in a datasheet.
Top of Page
Typically, you use a totals query instead of a Total row when you need to use the resulting value in another part of your database, such as a report.
1.
2.
In the Show Table dialog box, double-click the table that you want to use in your query, and then click Close.
The table appears in a window in the upper section of the query designer.
3.
Double-click the fields that you want to use in the query, and make sure you include the field that you want to count. You can count fields of most data types, the exception being fields that contain complex, repeating scalar data, such as a field of multivalued lists.
4.
The Total row appears in the design grid and Group By appears in the row for each field in the query.
5.
In the Total row, click the field that you want to count and select Count from the resulting list.
6.
7.
2.
In the Show Table dialog box, double-click the table or tables that you want to use in your query, and then click Close.
The table or tables appear in a window in the upper section of the query designer.
3.
Double-click the field that contains your category data, and also the field that contains the values that you want to count. Your query cannot contain other descriptive fields.
4.
The Total row appears in the design grid and Group By appears in the row for each field in the query.
5.
In the Total row, click the field that you want to count and select Count from the resulting list.
6.
7.
Top of Page
Average
Count
All data types except those containing complex repeating scalar data, such as a column of multivalued lists. For more information about multivalued lists, see the articles Guide to multivalued fields and Add or change a lookup field that lets you store multiple
values.
Maximum
Returns the item with the highest value. For text data, the highest value is the last alphabetic value and Access ignores case. The function ignores null values. Returns the item with the lowest value. For text data, the lowest value is the first alphabetic value and Access ignores case. The function ignores null values. Measures how widely the values are dispersed from an average value (a mean). For more information about using this function, see the article Display column totals in a datasheet.
Minimum
Standard Deviation
Variance
Measures the statistical variance of all values in the column. You can use this function only on numeric and currency data. If the table contains less than two rows, Access returns a null value. For more information about variance functions, see the article Display column totals in a datasheet.
2.
Click the query you want to run, and then press ENTER.
If the query you want to run is currently open in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.), you can also run it by clicking Run in the Results group on the Design tab of the ribbon.
Top of Page
specify.), and make-table queries (make-table query: A query (SQL statement) that creates a new table and then creates records (rows) in it by copying records from an existing table.). Except for make-table queries (which create new tables), action queries make changes to the data in tables they are based on. These changes cannot be easily undone, for example, by pressing CTRL+Z. If you make changes using an action query that you later decide you didn't want to make, usually you will have to restore the data from a backup copy. For this reason, you should always make sure you have a fresh backup of the underlying data before running an action query.
You can mitigate the risk of running an action query by first previewing the data that will be acted upon. There are two ways to do this:
View the action query in Datasheet view before you run it. To do this, open the query in Design view, click View on the Access status bar (status bar: A horizontal bar at the bottom of the screen that displays information about the current condition of the program, such as the status of items in the window, the progress of the current task, or information about the selected item.), and then click Datasheet View on the shortcut menu. To switch back to Design view, click View again, and then click Design View on the shortcut menu.
NOTE
Make sure to note what type of action query (append, update, make-table, or delete) you are
starting with, so you can change the query back to that type after you preview the data with this method.
2.
3.
Top of Page
A parameter query is always also another type of query. Most parameter queries are select queries or crosstab queries, but append, make-table, and update queries can also be parameter queries.
You run a parameter query according to its other query type, but, in general, use the following procedure.
2.
3.
Top of Page
contains data definition language (DDL) statements. These statements allow you to create or alter objects in the database.).
Union queries combine data from two or more tables, but not in the same manner as other queries. Whereas most queries combine data by concatenating rows, union queries combine data by appending rows. Union queries differ from append queries in that union queries do not change the underlying tables. Union queries append the rows in a recordset that does not persist after the query is closed.
Pass-through queries are not processed by the database engine that comes with Access; rather, they are passed directly to a remote database server that does the processing and then passes the results back to Access.
Data-definition queries are a special type of query that does not process data; instead, data-definition queries create, delete or modify other database objects (database objects: An Access database contains objects such as tables, queries, forms, reports, pages, macros, and modules. An Access project contains objects such as forms, reports, pages, macros, and modules.).
SQL-specific queries cannot be opened in Design view. They can only be opened in SQL view, or run. Except for data-definition queries, running a SQL-specific query opens it in Datasheet view.
2.
Click the query you want to run, and then press ENTER.
Top of Page
The following table shows some common error messages you may encounter. These errors can appear either as a message in a cell (instead of an expected value), or as an error message. The sections that follow the list include procedures you can use to resolve these errors.
NOTE
This content of this table is not exhaustive. If it does not include the error message you received, you can
submit feedback by using the form at the end of this article and including specific information about the error message in the comment box provided.
Problem The query may be joining fields that have different data types.
Solution Check the query design and ensure that the joined fields have the same data type. For instructions, see the section Check the joined fields in your query. Compact and repair the database. For instructions, see the section Compact and repair your database. Change the alias. For instructions, see the section Change a field alias.
Record is Deleted
The alias assigned to a field is the same as a component of the expression for that field. An alias is a name that is given to any expression in the Field row of the query design grid that is not an actual field. Access assigns the alias for you if you do not do so yourself; for example, EXPR1. An alias is immediately followed by a colon (:) and then by the expression. When you run the query, the alias becomes the column name in the datasheet.
#Error
This error can occur when the value of a calculated field is greater than the value allowed by the field's FieldSize property setting. This also occurs when the denominator of a calculated field is or evaluates to zero (0). The record being referred to has been deleted.
Ensure that the calculated field's denominator does not evaluate to zero (0). If appropriate, change the FieldSize property. If the record was deleted accidentally, it must be restored from a backup. If the deletion was intentional, you can dismiss this error message by pressing SHIFT+F9 to refresh the query.
#Deleted
1.
Open the query in Design view. Joins appear as lines that connect fields in the source tables. Note the table and field names for each join.
2.
In the Navigation Pane, right-click each table that has one or more fields joined in your query, and then click Design View.
3.
For each join, compare the values in the Data Type column of the table design grid for the fields involved in that join.
Check the data type of the joined fields in table Design view.
4.
To switch to a table so that you can see its fields, click the tab with that table's name.
Top of Page
Running the Compact and Repair Database utility within Access can improve the performance of your database. This utility makes a copy of the database file and, if it is fragmented, rearranges how the database file is stored on disk. After the compact and repair process has completed, the compacted database will have reclaimed wasted space, and is usually smaller than the original. By compacting the database frequently, you can help ensure optimal performance of the database application, and also resolve errors that arise from hardware problems, power failures or surges, and similar causes.
After the compact operation has completed, query speed is enhanced because the underlying data has been rewritten to the tables in contiguous pages. Scanning contiguous pages is much faster than scanning fragmented pages. Queries are also optimized after each database compaction.
During the compact operation, you can use the original name for the compacted database file, or you can use a different name to create a separate file. If you use the same name and the database is compacted successfully, Access automatically replaces the original file with the compacted version.
2.
Click Current Database and, under Application Options, select the Compact on Close check box.
This causes Access to automatically compact and repair the database every time it is closed.
NOTE
For the compact operation to succeed, you must have enough storage space on your hard disk for both the
Top of Page
1.
2.
In the query design grid, look for fields that have aliases. These will have a colon at the end of the field name, as in Name:.
3.
Check each alias to ensure that the alias does not match the name of any field that is part of the alias' expression. If it does, change the alias.
Append fields that are based on criteria. For example, you might want to append only the names and addresses of customers who have outstanding orders.
Append records when some of the fields in one table don't exist in the other table. For example, suppose that your Customers table has 11 fields, and the fields in the Clients table in another database match 9 of your 11 fields. You can use an append query to add only the data in the matching fields and ignore the others.
Remember that you cannot use append queries to change the data in individual fields in existing records. To do that type of task, you use an update query you can only use append queries to add rows of data.
For more information about update queries, see the article Create an update query. For general information about other ways to add records to a database or change existing data, see the article Add one or more records to a database.
Top of Page
Choose the destination fields for each column in the append query.
NOTE
Remember that you cannot undo the results of an append query, so proceed carefully. Also remember that
the data types that you set for the fields in the source table must be compatible with the data types that you set for the table fields in the destination table. For example, you can append numbers to a text field, but you cannot append text into a number field unless you use an expression, such as (Val(TextField)), to first convert the data to the Number data type.
For more information about data types and how to use them, see the article Modify or change the data type set for a field.
2.
The query designer opens, and the Show Table dialog box appears.
3.
Select any combination of tables or queries that contain the records that you want to append, click Add, and then click Close.
The tables or or queries appear as one or more windows in the upper section of the query design grid. These windows list all the fields in each table or query. This figure shows a typical table in the query designer.
4.
Double-click the fields that you want to append. The selected fields appear in the Field row in the design grid (the lower section of the query designer).
You can add an expression such as =Date() to automatically return today's date, or you can add table or query fields to the cells in the design grid. You can add one table or query field per cell.
To quickly add all the fields in a table, double-click the asterisk (*) at the top of the list of table fields. This figure shows the design grid with all fields added.
5.
Optionally, you can enter one or more criteria in the Criteria row of the design grid. The following table shows some example criteria and explains the effect they have on a query.
Criteria > 234 >= "Callahan" Between #2/2/2007# And #12/1/2007# Effect Returns all numbers greater than 234. To find all numbers less than 234, use < 234. Returns all records from Callahan through the end of the alphabet. Returns dates from 2-Feb-07 through 1-Dec-07 (ANSI-89). If your database uses the ANSI-92 wildcard characters, use single quotation marks (') instead of pound signs. Example: Between '2/2/2007' And '12/1/2007'. Finds all records where the exact contents of the field are not exactly equal to "Germany." The criterion will return records that contain characters in addition to "Germany," such as "Germany (euro)" or "Europe (Germany)". Finds all records except those beginning with T. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Finds all records that do not end with t. If your database uses the ANSI-92 wildcard character set, use the percent sign instead of the asterisk. In a list, finds all records containing Canada or UK. In a Text field, finds all records that start with the letters A through D. If your database uses the ANSI-92 wildcard character set, use the percent sign instead of the asterisk. Finds all records that include the letter sequence "ar". If your database uses the ANSI-92 wildcard character set, use the percent sign instead of the asterisk. Finds all records that begin with "Maison" and that also contain a 5-letter second string in which the first 4 letters are "Dewe" and the last letter is unknown (indicated by a question mark). If your database uses the ANSI-92 wildcard character set, use the underscore (_) instead of the question mark. Finds all records for February 2, 2007. If your database uses the ANSI-92 wildcard character set, surround the date with single quotation marks instead of pound signs (#). Example: '2/2/2007'. Returns all dates more than 30 days old. Returns all records containing today's date. Returns all records between today's date and three months from today's date.
Not "Germany"
Not "T*"
Not "*t"
Like "*ar*"
#2/2/2007#
< Date() - 30 Date() Between Date() And DateAdd("M", 3, Date()) Is Null Is Not Null ""
Returns all records that contain a null (blank or undefined) value. Returns all records that contain a value. Returns all records that contain a zero-length string. You use zero-length strings when you need to add a value to a required field, but you don't yet know what that value is. For example, a field may require a fax number, but some of your customers may not have fax machines. In that case, you enter a pair of double quotation marks with no space between them ("") instead of a number.
6.
7.
Verify that the query returned the records that you want to update. If you need to add or remove fields from the query, switch back to Design view and add fields as described in the preceding step, or select the fields that you don't want and press DELETE to remove them from the query.
8.
Continue to the next procedure, in which you will convert the select query to an append query.
-or-
In the Navigation Pane, right-click the query and then click Design View on the shortcut menu.
2.
3.
At this point, you can choose whether to append records from one table to an existing table in the same database, or to an existing table in a different database.
NOTE
If you want to copy records to a new table, you must use a make-table query.
1.
Follow the steps in this section to create a select query. Modify the select query as needed until it returns the records that you want to place in the new table.
2.
Switch to query Design view. Right-click the document tab for the query, and then click Design View.
-or-
Right-click the query in the Navigation Pane, and then click Design View.
3.
On the Design tab, in the Query Type group, click Make Table.
4.
In the Table Name combo box, enter a name for the new table.
5.
1.
2.
Enter the file path and name of the other database, or click Browse to locate the database, and then click OK after you locate the database.
3.
In the Table Name combo box, enter a name for the new table.
4.
Click OK.
Now that you have converted the query, you need to decide whether you want to append the records to a table in the same database or to a table in a different database. Depending on your choice, use the steps in one of the two following procedures:
2.
Click OK.
What you see depends on how you created your select query. For example, if you added all the fields from your source table or query, Access now adds all the fields in the destination table to the Append to row in the design grid.
-or-
If you added individual fields to the query, and the field names in the source and destination tables match, Access automatically adds the names of the destination fields to the Append to row in the query.
-or-
If you added individual fields, and any of the names in the source and destination tables don't match, Access leaves those fields blank. You can click a cell in the Append to row and select a destination field.
This figure illustrates how you click a cell in the Append to row and select a destination field.
NOTE
If you leave the destination field blank, the query will not append data to that field.
3.
To preview your changes, switch to Datasheet view. To do so, right-click the document tab for the query, and then click Datasheet View.
-or-
In the Navigation Pane, right-click the query and then click Datasheet View.
4.
Reminder You cannot undo the results of an append query, so make very sure that you want to append the records.
2.
In the File Name box, enter the location and name of the destination database.
3.
In the Table Name combo box, enter the name of the destination table, and then click OK.
or Click Browse and use the subsequent Append dialog box to locate the destination database. Click OK after you locate and select the destination database. This closes the subsequent Append dialog box. In the first Append dialog box, in the Table Name combo box, enter the name of the destination table, and then click OK.
What you see depends on how you created your select query. For example, if you added all the fields from your source table or query, Access now adds all the fields in the destination table to the Append to row in the design grid.
-or-
If you added individual fields to the query, and the field names in the source and destination tables match, Access automatically adds the names of the destination fields to the Append to row in the query.
-or-
If you added individual fields, and any of the names in the source and destination tables don't match, Access leaves those fields blank. You can click a cell in the Append to row and select a destination field.
This figure illustrates how you click a cell in the Append To row and select a destination field.
NOTE
If you leave the destination field blank, the query will not append data to that field.
4.
Return to Design view (right-click the tab at the top of the query, and then click Design View), and then click Run Yes. to append the records. When you are prompted to confirm the operation, click
You cannot use an update query to add new records to a table, but you can change existing null values to non-null values. To add new records to one or more tables, you use an append query.
For more information about append queries, see the article Create an append query.
You cannot use an update query to delete entire records (rows) from a table, but you can change existing non-null values to null. To delete entire records (a process that also deletes the primary key value), you must use a delete query.
For more information about delete queries, see the article Use a delete query to delete one or more records from a database.
You can use an update query to change all the data in a set of records.
In addition, you cannot run an update query against several types of table fields:
Fields that result from calculations. The values in calculated fields do not permanently reside in tables. They only exist in your computer's temporary memory after Access calculates them. Because calculated fields do not have a permanent storage location, you cannot update them.
Fields that use totals queries or crosstab queries as their record source.
AutoNumber fields. By design, the values in AutoNumber fields change only when you add a record to a table.
Fields in unique-values queries and unique-records queries queries that return non-duplicate values or records. This rule applies when you use an update query and also when you try to update data manually by entering values in a form or a datasheet.
Primary keys that participate in table relationships, unless you set the relationships to automatically cascade updates through the key field and any related fields. When you cascade updates, Access automatically updates any foreign key values in a child table (the table on the many side of a one-to-many relationship) when you change a primary key value in a parent table (the table on the one side of a one-tomany relationship).
NOTE
You cannot cascade updates for records that use an AutoNumber field to generate primary key
values.
For information about turning on and off cascading updates, see Enable cascading updates, later in this article.
For general information about other ways to add records to a database or change existing data, see the article Add one or more records to a database.
Top of Page
1.
2.
In the Save Backup As dialog box, specify a name and location for the backup copy, and then click Save.
Access closes the original file, creates a backup, and then reopens the original file.
To revert to a backup, close and rename the original file so that the backup copy can use the name of the original version. Assign the name of the original version to the backup copy, and then open the renamed backup copy in Access.
Top of Page
If you try to run an action query and it seems like nothing happens, check the Access status bar for the following message:
For more information about Disabled mode and Access security, see the article Secure an Access 2007 database.
Top of Page
2.
The query designer opens, and the Show Table dialog box opens.
3.
Select the table or tables that contain the records you want to update, click Add, and then click Close.
The table or tables appear as one or more windows in the query designer, and the windows list all the fields in each table. This figure shows the query designer with a typical table.
4.
Double-click the fields that you want to update. The selected fields appear in the Field row in the query design grid.
You can add one table field per column in the query design grid.
To add all the fields in a table quickly, double-click the asterisk (*) at the top of the list of table fields. This figure shows the query design grid with all fields added.
5.
Optionally, you can enter one or more criteria in the Criteria row of the query design grid. The following table shows some example criteria and explains the effect they have on the results of a query.
NOTE
Many of the examples in this table use wildcard characters to make the query more flexible or
powerful.
For more information about using wildcards in your queries, see the article Access wildcard character reference.
Criteria >234 >="Cajhen" Between #2/2/2007# And #12/1/2007# Effect Returns all numbers greater than 234. To find all numbers less than 234, use < 234. Returns all records from Cajhen through the end of the alphabet. Returns dates from 2-Feb-07 through 1-Dec-07 (ANSI-89). If your database uses the ANSI-92 wildcard characters, use single quotation marks (') instead of pound signs (#). Example: Between '2/2/2007' And '12/1/2007' . Finds all records where the exact contents of the field are not exactly equal to "Germany." The criterion will return records that contain characters in addition to "Germany," such as "Germany (euro)" or "Europe (Germany)". Finds all records except those beginning with T. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Finds all records that do not end with t. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). In a list, finds all records containing Canada or UK.
Not "Germany"
Not "T*"
Not "*t"
In(Canada,UK)
Like "[A-D]*"
In a text field, finds all records that start with the letters A through D. If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Finds all records that include the letter sequence "ar". If your database uses the ANSI-92 wildcard character set, use the percent sign (%) instead of the asterisk (*). Finds all records that begin with "Maison" and contain a 5-letter second string in which the first 4 letters are "Dewe" and the last letter is unknown. If your database uses the ANSI-92 wildcard character set, use the underscore (_) instead of the question mark (?). Finds all records for February 2, 2007. If your database uses the ANSI-92 wildcard character set, surround the date with single quotation marks (') instead of pound signs (#); for example, ('2/2/2007'). Uses the Date function to return all dates more than 30 days old. Uses the Date function to return all records containing today's date. Uses the Date and DateAdd functions to return all records between today's date and three months from today's date.
Like "*ar*"
#2/2/2007#
< Date() - 30 Date() Between Date() And DateAdd("M", 3, Date()) Is Null Is Not Null ""
Returns all records that contain a null (blank or undefined) value. Returns all records that contain a value. Returns all records that contain a zero-length string. You use zero-length strings when you need to add a value to a required field, but you don't yet know what that value is. For example, a field might require a fax number, but some of your customers might not have fax machines. In that case, you enter a pair of double quotation marks with no space between them ("") instead of a number.
6.
Verify that the query returns the records that you want to update. As needed, you can select fields you don't want included in the query design and press DELETE to remove them. In addition, you can drag additional fields to the query design grid.
7.
Update records
1. On the Design tab, in the Query Type group, click Update.
This procedure shows how to change the select query to an update query. When you do so, Access adds the Update to row in the query design grid. The following illustration shows an update query that returns all assets purchased after January 5, 2005 and changes the location to "Warehouse 3" for all records that meet that criterion.
2.
Locate the field that contains the data you want to change, and type your expression (your change criteria) in the Update to row for that field.
You can use any valid expression in the Update to row. This table shows some example expressions and explains how they change data.
Expression "Salesperson" #8/10/07# Yes "PN" & [PartNumber] [UnitPrice] * [Quantity] [Freight] * 1.5 DSum("[Quantity] * [UnitPrice]", "Order Details", "[ProductID]=" & [ProductID]) Right([ShipPostalCode], 5) Result In a Text field, changes a text value to Salesperson. In a Date/Time field, changes a date value to 10-Aug-07. In a Yes/No field, changes a No value to Yes. Adds "PN" to the beginning of each specified part number. Multiplies the values in fields named UnitPrice and Quantity. Increases the values in a field named Freight by 50 percent. Where the ProductID values in the current table match the ProductID values in table named Order Details, this expression updates sales totals by multiplying the values in a field named Quantity by the values in a field named UnitPrice. The expression uses the DSum function because it can operate against more than one table and table field.
Truncates (removes) the leftmost characters in a text or numeric string and leaves the 5 rightmost characters. Changes a null (unknown or undefined) value to a zero (0) value in a field named UnitPrice.
IIf(IsNull([UnitPrice]), 0, [UnitPrice])
3.
4.
5.
NOTE
When you run the query, you might notice that some fields are missing from your result set. If your
query contains fields that you don't update, Access does not display those fields in the results, by default. For example, you might include ID fields from two tables to help ensure that your query returns and
operates on the correct records. If you don't update those ID fields, Access does not display them in the results.
Top of Page
Also, when you update data from one table to another and use compatible data types instead of matching data types, Access converts the data types of those fields in the destination table. As a result, some of the data in the destination fields might be truncated (deleted). The section Restrictions on data type conversions lists the ways in which you can and cannot convert data types. The table also explains when converting a data type can change or eliminate some or all of the data in a field and what data might be eliminated.
The process of updating data from one table to another follows these broad steps:
Create an update query and add both the source and destination tables to the query.
Join those tables on the fields that contain the related information.
Add the names of your destination fields to the Field row of the query design grid.
Add the names of your source fields to the Update To row of the query design grid by using the following syntax: [source_table].[source_field].
The steps in this section assume the use of two similar tables. In this example, the Clients table resides in a database that you just inherited, and it contains more recent data than the Customers table. You can see that some of the manager names have changed and, in addition, some of the addresses. For that reason, you decide to update the Customers table with the data from the Clients table.
Name
City
Posta l
Code 1 Baldwin Museum of Science Blue Yonder Airlines 1 Main St. New York NY 12345 USA (505) 5552122 (104) 5552123 (206) 5552124 Josh Barnhill
52 1st St.
Boston
MA
23456
USA
Waleed Heloo
Coho Winery
Seattle
WA
34567
USA
Pica Guido
London
Bucks
NS1 EW2
England
(171) 5552125 (7) 5552126 (206) 5552125 (916) 5552128 (503) 5552129 (503) 5552233
Mexico City
56789
Mexico
Consolidated Messenger
3123 75th St. S. 1587 Office Pkwy 3 Microsof t Way 4 Microsof t Way
Seattle
WA
34567
USA
Miles Reid
Tampa
FL
87654
USA
Tzipi Butnaru
Litware, Inc.
Portlan d
OR
31415
USA
Brian Smith
Tailspin Toys
Portlan d
OR
31415
USA
Phil Gibbins
Customer ID 1
State/Province NY
52 1st St.
Boston
MA
23456
USA
Waleed Heloo
Coho Winery
Seattle
WA
34567
USA
Pica Guido
Contoso Pharmaceuticals
London
Bucks
NS1 EW2
England
(171) 5552125
Zoltan Harmuth
Fourth Coffee
Mexico City
56789
Mexico
(7) 5552126 (206) 5552125 (916) 5552128 (503) 5552129 (503) 5552233
Julian Price
Consolidated Messenger
Seattle
WA
34567
USA
Christine Hughes
Tampa
FL
87654
USA
Dana Birkby
Litware, Inc.
Portland
OR
31415
USA
Jesper Aaberg
Tailspin Toys
Portland
OR
31415
USA
Phil Gibbins
As you proceed, remember that although the data types for each table field do not have to match, they must be compatible, mean that Access must be able to convert the data in the source table into a type that the destination table can use. In some cases, the conversion process might delete some data. For more information about restrictions on converting data types, see the section Restrictions on data type conversions.
The following steps assume the use of the two preceding sample tables. You can adapt the steps to fit your data.
2.
In the Show Table dialog box, double click your source and destination tables to add them to the query. Each table appears in a window in the query designer. When you have finished adding tables, click Close to close the Show Table dialog box.
3.
Join the tables on the fields that contain the related information. To do so, drag the related field from one table and drop it on the equivalent field in the other table.
For example, if you use the sample tables shown earlier, you drag the Client ID field to the Customer ID field. When you do so, Access creates a relationship between those fields in the two tables and uses that relationship to join any related records.
4.
5.
In the destination table, double-click the fields that you want to update. Each field appears in the Field row in the query design grid.
If you use the sample tables, you add all fields except the Customer ID field. Notice that the name of the destination table appears in the Table row of the design grid.
6.
In the Update To row of the query, in each of the columns that contains a destination field, add the name of the source table and the field in the source table that corresponds to the field in the destination table, and be sure to use this syntax: [Table].[Field], where you surround table and field names with square brackets, and you separate table and field names with a period.
This figure shows part of the design grid, using the sample tables. Note the syntax for the table and field names in the Update To row.
As you proceed, remember that you must spell the table and field names in the Update To row correctly, and you must match any punctuation in the original table and field names. However, you do not need to match capitalization.
7.
8.
Changes or restrictions Access deletes all but the first 255 characters. No restrictions. No restrictions. No restrictions. No restrictions. The value -1 (Yes in a Yes/No field) converts to Yes. The value 0 (No in a Yes/No fields) converts to No. Access truncates links longer than 255 characters. No restrictions. No restrictions. No restrictions. No restrictions. No restrictions. The value -1 (Yes in a Yes/No field) converts to Yes. The value 0 (No in a Yes/No fields) converts to No. No restrictions. Text must consist of numbers and valid currency and decimal separators. The number of characters in the Text field must fall within the size set for the Number field. For more information about the sizes of number fields, see the article Insert, create, or delete a field to store numeric values.
Memo
The Memo field must contain only text and valid currency and decimal separators. The number of characters in the Memo field must fall within the size set for the Number field. For more information about the sizes of number fields, see the article Insert, create, or delete a field to store numeric values.
Values must not be larger or smaller than what the new field size can store. Changing precision might cause Access to round some values.
The dates that you can convert depend on the size of the number field. Remember that Access stores all dates as serial dates, and it stores the date values as double-precision floating integers. Access uses December 30, 1899 as date 0. Dates outside of the range April 18, 1899 and September 11, 1900 exceed the size of a Byte field. Dates outside the range April 13, 1810 and September 16, 1989 exceed the size of an Integer field. To accommodate all possible dates, set the Field Size property of your Number field to Long Integer or greater.
For more information about serial dates, and how Access uses and stores date values, see the article Enter a date or time value.
Currency
Values must not exceed (or fall below) the size limit set for the field. For example, you can convert a Currency field to an Integer field only when those values are greater than 255 and do not exceed 32,767. Values must fall within the size limit set for the field. "Yes" values convert to -1. "No" values convert to 0. N/A Original text must be a recognizable date or date/time combination. For example, 18-Jan2007. Original text must be a recognizable date or date/time combination. For example, 18-Jan2007. Value must fall between -657,434 and 2,958,465.99998843. Value must fall between -$657,434 and $2,958,465.9999. Value must exceed -657,434 and be less than 2,958,466. The value -1 (Yes) converts to December 29, 1899. The value 0 (No) converts to midnight (12:00 AM). N/A Text must consist of numbers and valid separators. Text must consist of numbers and valid separators. No restrictions. No restrictions, but Access might round the value No restrictions. The value -1 (Yes) converts to $1, and the value 0 (No) converts to 0$. N/A Not allowed if the AutoNumber field serves as a primary key. Not allowed if the AutoNumber field serves as a primary key. Not allowed if the AutoNumber field serves as a primary key. Not allowed if the AutoNumber field serves as a primary key. Not allowed if the AutoNumber field serves as a primary key. Not allowed if the AutoNumber field serves as a primary key. N/A Original text must consist only of Yes, No, True, False, On, or Off.
Memo
Hyperlink Currency Text Memo Number Date/Time AutoNumber Yes/No Hyperlink AutoNumber Text Memo Number Date/Time Currency Yes/No Hyperlink Yes/No Text
Original text must consist only of Yes, No, True, False, On, or Off. Zero or Null converts to No, all other values convert to Yes. Null or 12:00:00 AM converts to No, all other values convert to Yes. Zeroes and Nulls convert to No, all other values to Yes. Access coverts all values to Yes. N/A If the original text contains a valid Web address, such as adatum.com, www.adatum.com, or http://www.adatum.com , Access converts the text to a hyperlink. Access tries to convert other values, meaning that you see underlined text, and the cursor changes when you point at the link, but the links don't work. The text can contain any valid Web protocol: http://, gopher://, telnet://, ftp://, wais://, and so on. See the previous entry. The same restrictions apply. Not allowed when a Number field is part of a relationship. If the original value is in the form of a valid Internet Protocol (IP) address (four number triplets separated by a period: nnn.nnn.nnn.nnn) and the numbers happen to coincide with a Web address, the conversion results in a valid link. Otherwise, Access appends http:// to the beginning of each value, and the resulting links are not valid. Access appends http:// to the beginning of each address, but the resulting links will almost never work. Access appends http:// to the beginning of each value, but like dates, the resulting links will almost never work. Not allowed when the AutoNumber field is part of a relationship. Access appends http:// to the beginning of each value, but the resulting links will almost never work. Access converts all Yes values to -1 and all No values to 0, and appends http:// to the beginning of each value. The resulting links do not work.
Memo Number
Date/Time
Currency
AutoNumber
Yes/No
Typically, you create make table queries when you need to copy or archive data. For example, suppose you have a table (or tables) of past sales data, and you use that data in reports. The sales figures cannot change because the transactions are at least one day old, and constantly running a query to retrieve the data can take time especially if you run a complex query against a large data store. Loading the data into a separate table and using that table as a data source can reduce workload and provide a convenient data archive. As you proceed, remember that the data in your new table is strictly a snapshot; it has no relationship or connection to its source table or tables.
The process of creating a make table query follows these broad steps:
Enable the database, if it is not signed or if it does not reside in a trusted location. You cannot run action queries (append, update, and make table queries) otherwise.
In query Design view, create a select query and then modify that query until it returns the records you want. You can select data from more than one table and, in a real sense, you can de-normalize your data. For example, you can place customer, shipper, and supplier data in a single table, something you would not do in a production database with properly normalized tables. You can also use criteria in the query to further customize or narrow your result set.
For more information about normalizing your data, see the article Database design basics.
Convert the select query to a make table query, choose a location for the new table, and then run the query to create the table.
Do not confuse a make table query with an update or append query. You use an update query when you need to add or change data in individual fields. You use an append query when you need to add records (rows) to an existing set of records in an existing table.
For more information about update queries, see the article Create an update query. For more information about append queries, see the article Create an append query.
Top of Page
Follow these steps only when your database does not reside in a trusted location or is not signed. Access
displays the Message Bar whenever you open an untrusted or unsigned database.
1.
2.
In the Microsoft Office Security Options dialog box, click Enable this content, and then click OK.
If you already have a select query that produces the data that you need, go to the next steps.
1.
2.
In the Show Table dialog box, double-click the tables from which you want to retrieve data. Each table appears as a window in the upper section of the query designer. Click Close when have finished adding the tables.
3.
In each table, double-click the field or fields that you want to use in your query. Each field appears in a blank cell in the Field row of the design grid. This figure shows the design grid with several table fields added.
6.
Optionally, add any criteria to the Criteria row of the design grid.
7.
Click Run
8.
Optionally, change your fields, expressions, or criteria and rerun the query until it returns the data that you want to place in your new table.
If you have the query open in a datasheet, right-click the document tab for your query and click Design View.
If the query is closed, in the Navigation Pane, right-click the query and click Design View on the shortcut menu.
2.
On the Design tab, in the Query Type group, click Make Table.
3.
In the Table Name box, enter a name for the new table.
-or-
4.
1.
If it isn't already selected, click Current Database, and then click OK.
2.
Click Run
NOTE
If you are replacing an existing table, Access first deletes that table and asks you to
confirm the deletion. Click Yes, and then click Yes again to create the new table.
1.
2.
In the File Name box, enter the location and file name of the other database.
-or-
Click Browse, use the new Make Table dialog box to locate the other database, and click OK.
3.
4.
Click Run
NOTE
If you replace an existing table, Access first deletes that table and asks you to confirm
the deletion. Click Yes, and then click Yes again to create the new table.
Top of Page
For more information about using criteria, see the article Examples of query criteria.
An expression is a combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. You use an expression when you need data that does not reside directly in a table. For example, the expression [UnitPrice]*[Quantity] multiplies the value in the UnitPrice field by the value in the Quantity field. You can use expressions in a wide variety of ways, and the process of creating and using them can become quite complex.
For more information about creating and using expressions, see the article Create an expression.
Top of Page
If you try to run an action query and it seems like nothing happens, check the Access status bar for the following message:
Typically, you create make table queries when you need to copy or archive data. For example, suppose you have a table (or tables) of past sales data, and you use that data in reports. The sales figures cannot change because the transactions are at least one day old, and constantly running a query to retrieve the data can take time especially if you run a complex query against a large data store. Loading the data into a separate table and using that table as a data source can reduce workload and provide a convenient data archive. As you proceed, remember that the data in your new table is strictly a snapshot; it has no relationship or connection to its source table or tables.
The process of creating a make table query follows these broad steps:
Enable the database, if it is not signed or if it does not reside in a trusted location. You cannot run action queries (append, update, and make table queries) otherwise.
In query Design view, create a select query and then modify that query until it returns the records you want. You can select data from more than one table and, in a real sense, you can de-normalize your data. For example, you can place customer, shipper, and supplier data in a single table, something you would not do in a production database with properly normalized tables. You can also use criteria in the query to further customize or narrow your result set.
For more information about normalizing your data, see the article Database design basics.
Convert the select query to a make table query, choose a location for the new table, and then run the query to create the table.
Do not confuse a make table query with an update or append query. You use an update query when you need to add or change data in individual fields. You use an append query when you need to add records (rows) to an existing set of records in an existing table.
For more information about update queries, see the article Create an update query. For more information about append queries, see the article Create an append query.
Top of Page
Follow these steps only when your database does not reside in a trusted location or is not signed. Access
displays the Message Bar whenever you open an untrusted or unsigned database.
1.
2.
In the Microsoft Office Security Options dialog box, click Enable this content, and then click OK.
If you already have a select query that produces the data that you need, go to the next steps.
1.
2.
In the Show Table dialog box, double-click the tables from which you want to retrieve data. Each table appears as a window in the upper section of the query designer. Click Close when have finished adding the tables.
3.
In each table, double-click the field or fields that you want to use in your query. Each field appears in a blank cell in the Field row of the design grid. This figure shows the design grid with several table fields added.
4.
5.
6.
Optionally, add any criteria to the Criteria row of the design grid.
7.
Click Run
8.
Optionally, change your fields, expressions, or criteria and rerun the query until it returns the data that you want to place in your new table.
If you have the query open in a datasheet, right-click the document tab for your query and click Design View.
If the query is closed, in the Navigation Pane, right-click the query and click Design View on the shortcut menu.
2.
On the Design tab, in the Query Type group, click Make Table.
3.
In the Table Name box, enter a name for the new table.
-or-
4.
1.
If it isn't already selected, click Current Database, and then click OK.
2.
Click Run
NOTE
If you are replacing an existing table, Access first deletes that table and asks you to
confirm the deletion. Click Yes, and then click Yes again to create the new table.
1.
2.
In the File Name box, enter the location and file name of the other database.
-or-
Click Browse, use the new Make Table dialog box to locate the other database, and click OK.
3.
4.
Click Run
NOTE
If you replace an existing table, Access first deletes that table and asks you to confirm
the deletion. Click Yes, and then click Yes again to create the new table.
Top of Page
For more information about using criteria, see the article Examples of query criteria.
An expression is a combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. You use an expression when you need data that does not reside directly in a table. For example, the expression [UnitPrice]*[Quantity] multiplies the value in the UnitPrice field by the value in the Quantity field. You can use expressions in a wide variety of ways, and the process of creating and using them can become quite complex.
For more information about creating and using expressions, see the article Create an expression.
Top of Page
If you try to run an action query and it seems like nothing happens, check the Access status bar for the following message:
Count
All data types except complex repeating scalar data, such as a column of multivalued lists. For more information about multivalued lists, see the articles Guide to multivalued fields and Add or change a lookup field that lets you store multiple values.
Maximum
Returns the item with the highest value. For text data, the highest value is the last alphabetic value Access ignores case. The function ignores null values. Returns the item with the lowest value. For text data, the lowest value is the first alphabetic value Access ignores case. The function ignores null values. Measures how widely values are dispersed from an average value (a mean). For more information about using this function, see the article Display column totals in a datasheet.
Minimum
Standard Deviation
Number, Currency
Sum
Adds the items in a column. Works only on numeric and currency data. Measures the statistical variance of all values in the column. You can use this function only on numeric and currency data. If the table contains less than two rows, Access returns a null value. For more information about variance functions, see the article
Number, Currency
Variance
Number, Currency
1.
On the Create tab, in the Forms group, click More Forms, and then click Form Wizard.
2.
NOTE
If you want to include fields from multiple tables and queries on your form, do not click Next or
Finish after you select the fields from the first table or query on the first page of the Form Wizard. Instead, repeat the steps to select a table or query, and click any additional fields that you want to include on the form. Then click Next or Finish to continue.
3.
Top of Page
1.
Access opens a blank form in Layout view, and displays the Field List pane.
2.
In the Field List pane, click the plus sign (+) next to the table or tables that contain the fields that you want to see on the form.
3.
To add a field to the form, double-click it or drag it onto the form. To add several fields at once, hold down CTRL and click several fields, and then drag them onto the form at the same time.
NOTE
The order of the tables in the Field List pane can change, depending on which part of the form is
currently selected. If you are not able to add a field to the form, try selecting a different part of the form and then try adding the field again. For more information about using the Field List pane, see the article Add a field to a form or report.
4.
Use the tools in the Controls group on the Formatting tab to add a logo, title, page numbers, or the date and time to the form.
5.
If you want to add a wider variety of controls to the form, switch to Design view by right-clicking the form and then clicking Design View . You can then use the tools in the Controls group on the Design tab.
Top of Page
Understand controls
Controls are objects that display data, perform actions, and let you view and work with information that enhances the user interface, such as labels and images. The most commonly used control is the text box, but other controls include labels, check boxes, and subform/subreport controls.
Bound control A control whose source of data is a field in a table or query is called a bound control. You use bound controls to display values that come from fields in your database. The values can be text, dates, numbers, Yes/No values, pictures, or graphs. For example, a text box on a form that displays an employee's last name might get this information from the Last Name field in the Employees table.
Unbound control A control that doesn't have a source of data (such as a field or expression) is called an unbound control. You use unbound controls to display information, lines, rectangles, and pictures. For example, a label that displays the title of a form is an unbound control.
Calculated control A control whose source of data is an expression, rather than a field, is called a calculated control. You specify the value that you want to use as the source of data in the control by
defining an expression. An expression can be a combination of operators (such as = and + ), control names, field names, functions that return a single value, and constant values. For example, the following expression calculates the price of an item with a 25 percent discount by multiplying the value in the Unit Price field by a constant value (0.75).
An expression can use data from a field in the form's underlying table or query, or data from another control on the form.
For more information about expressions, see the links in the See Also section.
When you create a form, it is probably most efficient to add and arrange all the bound controls first, especially if they make up the majority of the controls on the form. You can then add the unbound and calculated controls that complete the design by using the tools in the Controls group on the Design tab in Design view.
You bind a control to a field by identifying the field from which the control gets its data. You can create a control that is bound to the selected field by dragging the field from the Field List pane to the form. The Field List pane displays the fields of the form's underlying table or query. To display the Field List pane, press ALT+F8, or on the Design tab, in the Tools group, click Add Existing Field. When you double-click a field in the Field List pane, Access adds the appropriate type of control for that field to the form.
Alternatively, you can bind a field to a control by typing the field name in the control itself or in the box for the Control Source value in the control's property sheet. The property sheet defines the characteristics of the control, such as its name, the source of its data, and its format. To open the property sheet, press F4.
Using the Field List pane is the best way to create a bound control for two reasons:
Access automatically fills in the control's attached label with the name of the field (or the caption defined for that field in the underlying table or query), so you don't have to type the control's label yourself.
Access automatically sets many of the control's properties to the appropriate values according to the properties of the field in the underlying table or query (such as the Format, Decimal Places, and Input Mask properties).
If you already created an unbound control and want to bind it to a field, set the value in the control's Control Source property box to the name of the field. For details about the Control Source property, press F1 while the cursor is in the property's drop-down list.
Top of Page
In tabular control layouts, controls are arranged in rows and columns like a spreadsheet, with labels across the top. Tabular control layouts always span two sections of a form; whichever section the controls are in, the labels are in the section above.
In stacked layouts, controls are arranged vertically like you might see on a paper form, with a label to the left of each control. Stacked layouts are always contained within a single form section.
You can have multiple control layouts of either type on a form. For example, you might have a tabular layout to create a row of data for each record, and then one or more stacked layouts underneath, containing more data from the same record.
You create a new form by clicking Form in the Forms group on the Create tab.
You create a new form by clicking Blank Form in the Forms group on the Create tab, and then dragging a field from the Field List pane to the form.
On an existing form, you can create a new control layout by doing the following:
1.
2.
If you want to add other controls to the same layout, hold down the SHIFT key and also select those controls.
3.
or Stacked
Right-click the selected control or controls, point to Layout, and then click Tabular .
or Stacked
Access creates the control layout and adds the selected controls to it.
Select the control layout by clicking the orange layout selector at the top left corner of the layout. All of the cells in the layout are selected.
On the Arrange tab, in the Control Layout group, click the layout type you want (Tabular Stacked ).
or
Right-click the control layout, point to Layout, and then click the layout type you want.
Access rearranges the controls into the layout type you want.
1.
Hold down the SHIFT key and click the controls you want to move to the new control layout.
2.
On the Arrange tab, in the Control Layout group, click the layout type you want for the new layout (Tabular or Stacked ).
Right-click the selected controls, point to Layout, and then click the layout type you want for the new layout.
Access creates a new control layout and adds the selected controls to it.
You can move a control from one control layout to another control layout of the same type. For example, you can drag a control from one stacked layout to another stacked layout, but not to a tabular layout.
Drag the field from the Field List pane to the layout. A horizontal or vertical bar indicates where the field will be placed when you release the mouse button.
1.
Select the first control you want to add to the control layout.
2.
If you want to add other controls to the same layout, hold down the SHIFT key and also select those controls. You can select controls in other control layouts.
3.
If the form is open in Design view, drag the selected fields to the layout. A horizontal or vertical bar indicates where the fields will be placed when you release the mouse button.
1.
On the Arrange tab, in the Control Layout group, click the type of the layout to which you are adding the controls. If you are adding controls to a tabular layout, clickTabular adding controls to a stacked layout, click Stacked . . If you are
Access creates a new layout and adds the selected controls to it.
2.
Drag the new layout to the existing layout. A horizontal or vertical bar indicates where the fields will be placed when you release the mouse button.
Select the control you want to remove from the layout. To select multiple controls, hold down the SHIFT key and then click the controls you want to remove. To select all of the controls in the layout, click the layout selector box at the top left corner of the layout.
Right-click one of the selected controls, point to Layout, and then click Remove
Top of Page
Certain tasks cannot be performed in Layout view and require switching to Design view. In certain situations, Access displays a message telling you that you must switch to Design view to make a particular change.
Design view Design view gives you a more detailed view of the structure of your form. You can see the Header, Detail, and Footer sections for the form. The form is not actually running when it is shown in Design view, so you cannot see the underlying data while you are making design changes; however, there are certain tasks you can perform more easily in Design view than in Layout view. You can:
Add a wider variety of controls to your form, such as labels, images, lines, and rectangles.
Edit text box control sources in the text boxes themselves, without using the property sheet.
Resize form sections, such as the Form Header or the Detail section.
Change certain form properties that cannot be changed in Layout view (such as Default View or Allow Form View).
Top of Page
To switch to Layout view, right-click the form name in the Navigation Pane and then click Layout View
You can use the property sheet to modify the properties for the form and its controls and sections. To display the property sheet, press F4.
You can use the Field List pane to add fields from the underlying table or query to your form design. To display the Field List pane, do one of the following:
On the Formatting tab, in the Controls group, click Add Existing Fields.
Press ALT+F8.
You can then drag fields directly from the Field List pane onto your form.
To add a single field, double-click it or drag it from the Field List pane to the section on the form where you want it displayed.
To add several fields at once, hold down CTRL and click the fields that you want to add. Then drag the selected fields onto the form.
Top of Page
You can also fine-tune your form's design by working in Design view. You can add new controls and fields to the form by adding them to the design grid. The property sheet gives you access to a large number of properties that you can set to customize your form.
To switch to Design view, right-click the form name in the Navigation Pane and then click Design View
You can use the property sheet to modify the properties for the form and its controls and sections. To display the property sheet, press F4.
You can use the Field List pane to add fields from the underlying table or query to your form design. To display the Field List pane, do one of the following:
On the Formatting tab, in the Controls group, click Add Existing Fields.
Press ALT+F8.
You can then drag fields directly from the Field List pane onto your form.
To add a single field, double-click it or drag it from the Field List pane to the section on the form where you want it displayed.
To add several fields at once, hold down CTRL and click the fields that you want to add. Then drag the selected fields onto the form.
To add a single field, double-click it or drag it from the Field List pane to the section on the form where you want it displayed.
To add several fields at once, hold down CTRL and click the fields that you want to add. Then drag the selected fields onto the form.
Top of Page
Some controls are created automatically, such as the bound control that is created when you add a field from the Field List pane to your form. Many other controls can be created in Design view by using the tools in the Controls group on the Design tab.
NOTE
Many of the tools in the Controls group are accessible only while your form is open in Design view. To .
switch to Design view, right-click the form name in the Navigation Pane and then click Design View
If you prefer to create controls without the help of the wizard, click Use Control Wizards so that it is not selected.
2.
Click in the form design grid where you want to position the upper-left corner of the control. Click once to create a default-sized control, or click the tool and then drag the mouse pointer in the form design grid to create a control of the size that you want.
3.
If you selected Use Control Wizards and the control that you are placing has a wizard associated with it, the wizard starts and guides you through the settings for the control.
4.
If you don't position the control perfectly on the first try, you can move it by doing the following:
1.
2.
Position the mouse pointer over the control until the pointer turns into a four-headed arrow
3.
Click and drag the control to the location that you want.
If you use a Control Wizard, the wizard might contain steps to help you bind the control to a field. Otherwise, this procedure creates an unbound control. If the control is of the type that can display data (a text box or check box, for example), you must enter a field name or expression in the Control Source property box for the control before it will display any data. To display the properties for a control, select the control and then press F4. For more information, see the Understand controls section.
Top of Page
1.
2.
If the form is untitled, type a name in the Form Name box, and then click OK.
1.
2.
In the Save As dialog box, type a name in the Save Form To box, select Form in the As list, and then click OK.
On the Formatting tab, in the Controls group, click Add Existing Fields.
2.
Press ALT+F8.
In the Field List pane, find the table containing the field you want to add. To show or hide the list of fields in each table, click the plus (+) or minus sign (-) next to the table name.
NOTE
If the database does not contain any tables, the Field List pane is empty.
3.
When you find the field you want to add, do one of the following to add it to the form or report:
Drag the field from the Field List pane to the form or report.
Hold the CTRL key and click several fields, and then drag them all to the form or report at the same time.
NOTE
This technique can be used only on fields in the Fields available for this view section of
Add a range of fields from the Field List pane to the form or report by doing the following:
1.
2.
Press and hold the SHIFT key, and then click the last field in the range.
Access selects the fields you clicked, as well as all the fields in between.
3.
NOTE
This technique can only be used on fields in the Fields available for this view section of
4.
Office Access 2007 creates the appropriate control to display each field, and also binds the control to the field. In addition, Access creates an attached label for the control. You can edit the label by clicking it once to select it, and then clicking it again to place the insertion point in the label. Then, you can edit the label in the same way that you would edit text in a document.
5.
If you want a field displayed in a different type of control other than the one that Access creates automatically, you can change the control to another type. However, you can only change it to a control type that is appropriate for that field. For example, you can change a combo box to a text box or a list box, but you can't change a combo box to a command button.
2.
Right-click the control you want to change, and then click Change To.
If the Change To menu item is unavailable, there are no other control types that are appropriate for this field. Otherwise, Access displays a list of control types.
3.
Click one of the available control types to change the control to that type.
The control remains bound to the field, but you might have to set some properties to make the new control type work the way you want. To display the property sheet for a control, click the control to select it, and then press F4.
Top of Page
1.
Open the form or report in Design view by right-clicking it in the Navigation Pane and then clicking Design View.
Control Wizards You can use the Control Wizards to help you create command buttons, list boxes, subforms, combo boxes, and option groups. A Control Wizard asks you a series of questions about how you want the control to look and operate, and then it creates the control and sets the control's properties based on your answers. On the Design tab, in the Controls group, if Use Control Wizards is not highlighted, click it to highlight it.
If you would rather create controls without the help of the wizards, click Use Control Wizards so that it is not selected.
2.
On the Design tab, in the Controls group, click the tool for the type of control you want to add.
To determine the name of a tool, position the pointer over it. Access displays the name of the tool.
3.
Click in the form or report design grid where you want to position the upper-left corner of the control. Click once to create a default-sized control, or click the tool and then drag in the form design grid to create a control of the size that you want.
4.
If you have selected Use Control Wizards and the control you are placing has a wizard associated with it, the wizard starts and guides you through the settings for the control.
5.
If you don't position the control perfectly on the first try, you can move it by doing the following:
1.
2.
Position the pointer over the control until it turns into a move pointer
3.
Click and drag the control to the location that you want.
If you use a control wizard, the wizard might contain steps to help you bind the control to a field. If the wizard does not bind the control to a field, and control is of the type that can display data (a text box or combo box, for example), you must enter a field name or expression in the Control Source property for the control before it will display any data. Use the following procedure to bind a control to a field.
1.
Display the property sheet for the control by clicking the control, and then pressing F4.
2.
On the Data tab of the property sheet, click the drop-down arrow next to the Control Source property and select the field you want displayed in the control. You can also type an expression in the Control Source box.
For more information about expressions, see the article Create an expression.
Top of Page
If the form or report's Record Source property is empty, and you drag a field from the Field List pane to the form or report, Access automatically fills in the form or report's Record Source property for you.
If the form or report's Record Source property is a SELECT statement or a table name, you can toggle the Field List pane display between the following two states:
All database fields Displays the Fields available for this view section, the Fields available in related tables section (if such tables exist), and the Fields available in other tables section (if such tables exist).
Record source fields only Displays only the Fields available for this view section.
To switch between the two modes, click either Show only fields in the current record source or Show all tables at the bottom of the Field List pane.
NOTE
If you have set the form or report's Record Source property to a saved query, the Field List
pane displays only the Fields available for this view section (there is no Show all tables option at the bottom of the Field List pane). To edit the record source, right-click any one of the fields, and then click Edit Record Source.
If you have set the form or report's Record Source property to a table, and you then drag a field from the Fields available in related tables section of the Field List pane to the form or report, Access changes the Record Source of the form or report to a SELECT statement that includes the field you are adding. If Access cannot determine how to relate the tables, it displays the Choose Relationship dialog box so you can choose the appropriate relationship.
If you drag a field from the Fields available in other tables section of the Field List pane to the form or report, Access displays the Specify Relationship dialog box. You must use this dialog box to specify a relationship between the other table and the form or report's record source. If you are not sure which fields to enter in this dialog box, you might want to click Cancel and then examine your table relationships.
For more information about relationships, see Guide to table relationships or Create, edit, or delete a relationship.
It is possible that a field in the Fields available in other tables section of the Field List pane is indirectly related to the record source of the form or report through one of the tables in the Fields available in related tables section. If this is the case, dragging a field from one of the related tables to the form or report may cause one or more tables to move from the Fields available in other tables section to the Fields available related tables section.
If the record source of the form or report is a SELECT statement or a saved query, you can view and edit the record source in the Query Builder by right-clicking any field in the Field List pane and then clicking Edit Record Source. If the record source is a table, this command invokes the Query Builder on the table. Access asks you if you want to create a query based on the table; click Yes to change the record source to a query, or No to leave the record source unchanged.
You can open a table in Datasheet view by clicking Edit Table next to the table name, or by right-clicking the table name in the Field List pane and then clicking Open Table in Datasheet View.
You can use the Field List pane to add a Lookup field (Lookup field: A field, used on a form or report in an Access database, that either displays a list of values retrieved from a table or query, or stores a static set of values.) to a table by doing the following:
1.
Click Edit Table next to the table in which you want to add the Lookup field.
2.
3.
The Lookup Wizard starts. Follow the instructions in the wizard. On the last page, click Finish.
You can undock the Field List pane from the right side of the Access work area by positioning the pointer in the title bar of the Field List pane until it turns into a move pointer , and then dragging the
Field List pane to the left. You can position the list anywhere in the work area, or you can dock it to the left side of the work area by dragging it all the way to the left.
1.
How?
2.
A new label is added to the form or report header, and the form or report name is displayed as the title.
3.
When the label is created, the text in the label is automatically selected so that you can change the text by typing the title you want.
4.
2.
Type the text you want to use as the title, and then press ENTER when you have finished.
How?
2.
3.
Choose the format, position, and alignment that you want for the page numbers.
4.
Clear the Show Number on First Page check box if you do not want a number on the first page.
5.
Click OK.
The page numbers will be added to the Page Header section of the form, but they will be visible only when the form is printed (or when you click the Microsoft Office Button Print Preview ). , point to Print, and then click
How?
2.
3.
Choose the format, position, and alignment that you want for the page numbers.
4.
Clear the Show Number on First Page check box if you do not want a number on the first page.
5.
Click OK.
The page numbers will be added to the report. To see how the page numbers will look when the report is run, switch to Print Preview .
1.
How?
2.
On the Formatting tab, in the Controls group, click Date and Time.
3.
Clear the Include Date check box if you do not want to include the date.
4.
If you want to include the date, click the date format that you want to use.
5.
Clear the Include Time check box if you do not want to include the time.
6.
If you want to include the time, click the time format that you want to use.
A sample of the date and time information in the formats you have chosen appears in the Sample area of the dialog box.
7.
Click OK.
Information is often easier to understand when it is divided into groups. For example, a report that groups sales by region can highlight trends that otherwise might go unnoticed. In addition, placing totals at the end of each group in your report can replace a lot of manual interaction with a calculator.
Microsoft Office Access 2007 makes working with grouped reports easy. You can create a basic grouped report by using the Report Wizard, you can add grouping and sorting to an existing report, or you can revise grouping and sorting options that have already been defined.
To learn more about queries, follow the links in the See Also section of this article.
2.
Click the Tables/Queries drop-down list and choose the table or query that contains the fields you want on your report.
3.
Access moves them to the Selected Fields list. Alternatively, you can click the buttons located between the Available Fields box and the Selected Fields box to add or remove the selected field or to add all or remove all of the fields.
4.
If there are fields in another table or query that you also want to put on your report, click the Tables/Queries drop-down list again and choose the other table or query, and continue to add fields.
5.
When you include more than one table in a report, the wizard examines the relationships between the tables and determines how you might want to view the information.
1.
On the page of the Report Wizard that asks Do you want to add any grouping levels?, click one of the field names in the list, and then click Next.
2.
To add grouping levels, double-click any of the field names in the list to add them to your report.
You can also remove a grouping level by double-clicking it in the page display on the right side of the dialog box. Use the arrow buttons to add and remove grouping levels, and adjust the priority of a grouping level by selecting it and clicking the up or down priority buttons. Access adds each grouping level and shows it nested within its parent grouping level.
3.
4.
The grouping interval lets you customize how records are grouped. In the previous illustration, records are grouped on the ShippedDate field, which is a Date/Time data type. The Report Wizard offers choices appropriate to the field type in the Grouping intervals list. Thus, because ShippedDate is a Date/Time type, you can choose to group by actual value (Normal), Year, Quarter, Month, Week, Day, Hour and Minute. If the field were a Text data type, you could choose to group by the entire field (Normal), or perhaps by the first one to five characters. For a numeric data type, you can choose to group by value (Normal), or by range in selected increments.
5.
1.
Click the first drop-down list and choose a field on which to sort.
You can click the button to the right of the list to toggle between ascending and descending order (Ascending is the default). Optionally, click the second, third, and fourth drop-down lists to choose additional sort fields.
2.
Click Summary Options if you want to summarize any of the numeric fields.
Note that the Summary Options button will only be visible if you have one or more numeric fields in the Detail section your report. The wizard displays the available numeric fields.
3.
Select the check box under your choice of Sum, Avg, Min or Max to include those calculations in the group footer.
You can also choose to show the details and summary or the summary only. In the latter case, totals for each ShippedDate value are shown (if you selected the check box for Sum, for example), but the order detail is omitted. You can also choose to show percent of total calculations for sums.
4.
Click OK.
5.
Follow the directions on the remaining pages of the Report Wizard. On the last page, you can edit the title of the report. This title will be displayed on the first page of the report, and Access will also save the report, using the title as the document name. You can edit both the title and the document name later.
6.
Click Finish. Access automatically saves the report and displays it in Print Preview, which shows you the report as it will look when printed.
You can use the navigation buttons at the bottom of the preview pane to view the pages of the report sequentially or jump to any page in the report. Click one of the navigation buttons or type the page number that you want to see in the page number box, and then press ENTER.
In Print Preview, you can zoom in to see details or zoom out to see how well data is positioned on the page. With the mouse pointer positioned over the report, click once. To reverse the effect of the zoom, click again. You can also use the zoom control in the status bar.
Top of Page
To open a report in Layout view, right-click the report in the Navigation Pane, and then click Layout view
You can use the property sheet to modify the properties for the report and its controls and sections. To display the property sheet, press F4.
You can use the Field List pane to add fields from the underlying table or query to your report design. To show the Field List pane:
On the Formatting tab, in the Controls group, click Add Existing Fields.
To open a report in Design view, right-click the report in the Navigation Pane, then click Design View
Top of Page
To add several fields at once, click the first field that you want, and then hold down CTRL and click each additional field that you want. Then, drag the selected fields onto the report.
When you drop the fields, Access creates a bound text box control for each field and automatically places a label control beside each field.
NOTES
If you add a field from a related table, Access will add the appropriate grouping level for you.
If you add a field from another (non-related) table, Access will display a dialog box where you can specify how to relate the table to the existing data source for the report.
To see what table relationships have already been specified for your database, or to add new ones:
For more information, see the article Create, edit or delete a relationship.
Click in the report design where you want to position the upper-left corner of the control. Click once to create a default-sized control, or click and drag in the report to create a control of the size that you want.
If you don't position the control perfectly on the first try, you can move it by using the following procedure:
Position the pointer over the control until it turns into a four-headed arrow control to the desired location.
This process creates an "unbound" control. If the control is the type that can display data (a text box or check box, for example), you will need to enter a field name or expression in the Control Source property for the control before it will display any data.
NOTE
Top of Page
NOTE
Although the instructions in this section don't use the Group, Sort, and Total pane directly, it is a good idea
to open the pane and observe how it changes as you work. You will get a better idea of what Access is doing and, as you get more comfortable working with the Group, Sort, and Total pane, you can use it to make additional adjustments to your report. To display the Group, Sort, and Total pane:
On the Formatting tab, in the Grouping & Totals group, click Group & Sort.
On the shortcut menu, click the sort option you want. For example, to sort a text field in ascending order, click Sort A to Z . To sort a numeric field in descending order, click Sort Largest to Smallest .
Access sorts the report as you specified. If the Group, Sort, and Total pane is open, you can see that a new Sort by line for the field has been added.
When you apply sorting by right-clicking a field in Layout view, you can only sort one field at a time. Applying
sorting to another field removes the sorting on the first field. This differs from the sorting behavior in forms, where multiple sort orders can be established by right-clicking each field in turn and the choosing the sort order you want. To create multiple sorting levels, see the section Add grouping, sorting, and totals by using the Group, Sort, and Total pane.
Group on a field
Right-click any value in the field on which you want to group.
Access adds the grouping level and creates a group header for it. If the Group, Sort, and Total pane is open, you can see that a new Group on line for the field is added.
Click Total.
Click the operation you would like to perform: Sum, Average, Count Records (to count all records), Count Values (to count only the records with a value in this field), Max, Min, Standard Deviation, or Variance.
Access adds a calculated text box control to the report footer, which creates a grand total. Also, if your report has any grouping levels, Access adds group footers (if not already present) and places the total in each footer.
NOTE
You can also add totals by clicking the field that you want totaled and then, on the Formatting tab, in the .
Add grouping, sorting, and totals by using the Group, Sort, and Total pane
Working in the Group, Sort, and Total pane gives you the most flexibility when you want to add or modify groups, sort orders, or totals options on a report. Again, Layout view is the preferred view in which to work because it is much easier to see how your changes affect the display of the data.
On the Formatting tab, in the Grouping & Totals group, click Group & Sort.
In Design view:
On the Design tab, in the Grouping & Totals group, click Group & Sort.
To add a new sorting or grouping level, click Add a group or Add a sort.
A new line is added to the Group, Sort, and Total pane, and a list of available fields is displayed.
You can click one of these field names or you can click expression below the list of fields to enter an expression. Once you choose a field or enter an expression, Access adds the grouping level to the report. If you are in Layout view, the display changes immediately to show the grouping or sort order.
NOTES
If there are already several sorting or grouping levels defined, you may need to scroll down in the Group, Sort, and Total pane before you can see the Add a group and Add a sort buttons.
To display all the options for a grouping or sorting level, click More on the level that you want to change.
Sort order You can change the sort order by clicking the sort order drop-down list, then clicking the option you want.
Group interval This setting determines how the records are grouped together. For example, you can group on the first character of a text field so that all that start with "A" are grouped together, all that start with "B" are grouped together, and so on. For a date field, you can group by day, week, month, quarter, or you can enter a custom interval.
Totals To add totals, click this option. You can add totals on multiple fields, and you can do multiple types of totals on the same field.
Click the Total On drop-down arrow and select the field you want to have summarized.
Click the Type drop-down arrow and select the type of calculation to perform.
Select Show Grand Total to add a grand total to the end of the report (in the report footer).
Select Show group totals as % of Grand Total to add a control to the group footer that calculates the percentage of the grand total for each group.
Select Show in group header or Show in group footer to display the total in the desired location.
Once all the options have been chosen for a field, you can repeat the process and summarize another field by selecting the other field from the Total On drop-down list. Otherwise, click outside the Totals pop-up window to close it.
Title This allows you to change the title of the field being summarized. This is used for the column heading and for labeling summary fields in headers and footers.
Type the new title in the dialog box, and then click OK.
With/without a header section Use this setting to add or remove the header section that precedes each group. When adding a header section, Access moves the grouping field to the header for you. When you remove a header section that contains controls other than the grouping field, Access asks for confirmation to delete the controls.
With/without a footer section Use this setting to add or remove the footer section that follows each group. When you remove a footer section that contains controls, Access asks for confirmation to delete the controls.
Keep group together This setting determines how groups are laid out on the page when the report is printed. You may want to keep groups together as much as possible to reduce the amount of page turning that is needed to see the entire group. However, this usually increases the amount of paper needed to print the report, because most pages will have some blank space at the bottom.
Do not keep group together on one page Use this option if you are not concerned about groups being broken up by page breaks. For example, a group of 30 items may have 10 items on the bottom of one page and the remaining 20 items at the top of the next page.
Keep whole group together on one page This option helps minimize the number of page breaks in a group. If a group cannot fit in the remaining space on a page, Access leaves that space blank and begins the group on the next page instead. Large groups may still span multiple pages, but this option minimizes the number of page breaks within the group as much as possible.
Keep header and first record together on one page For groups with group headers, this ensures that the group header will not print by itself at the bottom of a page. If Access determines that there is not enough room for at least one row of data to be printed after the header, the group begins on the following page.
grouping field was in the group header or footer, Access moves it to the report's Detail section. Any other controls that were in the group header or group footer are deleted.
Top of Page
The general procedure involves removing the header for each group, which moves each grouping field into the Detail section of the report. To restore the visual grouping effect, you set the Hide Duplicates property of each grouping field to Yes.
Example
Consider this typical grouped report that uses group headers:
As you can see, each company name takes up an entire line, as does each order ID.
In this example, you will edit the report so that it looks like the following illustration:
1.
Open the report in Layout view by right-clicking it in the Navigation Pane, and then clicking Layout View .
2.
On the Formatting tab, in the Grouping & Totals group, click Group & Sort.
NOTE
It is a good idea to start with the lowest-level group and work your way up; otherwise, the display
3.
Click the lowest grouping level in the list, and then click More.
4.
From the header section drop-down list, select without a header section.
When you remove a header, Access preserves the text box for the grouping field by moving it to the Detail section. However, any other controls in the group header might be deleted. Access warns you if any controls are going to be deleted as a result of this action. If there are controls in the group header that you want to preserve, be sure to move them to another report section before performing this step. You will need to switch to Design view to move the controls to other sections.
The resulting report is shown in the following illustration. Notice that the first OrderID is on the same line as the first detail record, instead of on its own line.
Unfortunately, the OrderID repeats on every detail line, and this makes it hard to see exactly how many orders there are. At this point, setting the text box control's Hide Duplicates property is useful. Follow these steps to set this property:
On the Format tab of the property sheet, click the drop-down list for Hide Duplicates and then click Yes.
The duplicate order IDs are hidden. Note that you can see how many orders there are, and how many products there are per order.
5.
For this example, we repeat step 4 for the Company Name grouping level. The final report looks like the following illustration:
The Company Name value is now on the same line as the first detail record, and the Hide Duplicates property prevents the Company Name value from repeating on every line. For a long report that uses several grouping levels, this can result in a significant paper savings.
Top of Page
2.
If the report is untitled, type a name in the Report Name box and then click OK.
2.
In the Save As dialog box, type a name in the Save Report To box, click Report in the As box, and then click OK.
You can print a report from Print Preview, Layout view, Design view, Report view, or from the Navigation Pane. Before you print, you should double check page settings, such as margins and page orientation. Access saves the page settings with the report, so you need to set them only once. You can save the settings later, if your needs change.
2.
Size
allows you to select from a number of paper sizes, or to enter a custom paper size.
Portrait
Landscape
Margins
allows you to select from several predefined margin widths, or you can click Advanced
to enter custom margin widths by using the Page Setup dialog box.
Show Margins toggles the display of margins on and off (Layout view only).
Columns displays the Page Setup dialog box. Enter the number of columns you want, set your desired column size, and then click OK.
Print Data Only suppresses the printing of any labels you have placed on your report. Only the controls that are bound to data in the underlying table or query will be printed. This feature can be helpful on reports that you occasionally print on pre-printed forms. You can suppress the printing of labels in those situations, and then enable the printing of labels when you are printing the report on blank paper.
NOTE
To use more detailed page settings, click the Page Setup button at the lower right corner of the Page
Layout group to display the Page Setup dialog box. You can use the Page Setup dialog box to adjust all the settings that are available on the Page Layout tab, and also to select a specific printer for the report.
1.
Open the report in any view, or just select the report in the Navigation Pane.
2.
3.
In the Print dialog box, enter your choices for options such as printer, print range, and number of copies.
4.
Click OK.
Top of Page
1.
In the Navigation Pane, click the report to select it, click the Microsoft Office Button E-mail .
2.
In the Send Object As dialog box, click the file format that you want to use.
3.
4.
When your e-mail program appears, type the message details and send the message.
Top of Page
Remarks
A problem can arise if you have a report in an .accdb file that sorts or groups on a lookup field, and you want to import that report into an .mdb file and then open it with an earlier version of Access.
The internal method by which lookup fields are sorted and grouped in .accdb files is incompatible with .mdb files. If you create a report in an .accdb file that uses grouping or sorting on a lookup field, and you then export it into an .mdb file (or use the Save As command to save the database as an .mdb file) and then try to open the report with an earlier version of Access, the report will fail to load.
To revise the report so that you can import it into an .mdb file and open it in an earlier version of Access, do the following:
1.
2.
3.
4.
On the Formatting tab, in the Grouping & Totals group, click Group & Sort.
Delete all the lines in the Group, Sort, and Total pane by clicking the Delete button to the right of each line.
5.
6.
7.
8.
Browse to the .mdb file into which you want to import the report, and then click Open.
9.
How?
1.
2.
Click Browse.
3.
Browse to the .accdb file containing the report, and click Open.
4.
You are not importing any tables at this time, so it does not matter whether you choose to import or link to the source data. Click OK to continue.
5.
6.
Click the report you want to import, and then click OK.
7.
If the import operation is successful, Access asks if you want to save the import steps for later use. If you want to save the steps, select the Save import steps check box, enter the requested information, and click Save Import. If you do not want to save the steps, click Close.
On the Formatting tab, in the Controls group, click Add Existing Fields.
In the Fields available in related tables pane, find the table that contains the field you want displayed on the report. This field will contain the same values that you currently see displayed by the lookup field on the report.
Right-click the display field you just added, and click the sorting option you want to use.
Delete the display field that you just added and sorted.
On the Formatting tab, in the Grouping & Totals group, click Group & Sort.
In the Field/Expression pop-up window, click the name of the lookup field on the report.
The report is now sorted and grouped as it was in the .accdb file. Save and close the report.
Print a report
Follow the steps in this section when you need to print some of the pages in a report and when you need to select a printer or change options, such as margins or columns.
1.
In the Navigation Pane, select the report that you want to print. You do not need to open the report, although you can if you need to check for any issues, such as layout problems, or to ensure that you are printing current data.
2.
3.
Set or change the options in the dialog box as needed, and then click Print to print your report.
For help with an option, click the Help button, and then click the field or control for which you need help.
Top of Page
-or-
-or-
, point to the arrow next to Print, and then click Quick Print.
NOTE
You might need to add the Quick Print button to the Quick Access Toolbar. To do so, click the
Top of Page
Preview a report
You use Print Preview to ensure that your report will be printed correctly. You can use Print Preview to view reports that were created in Office Access 2007 and also in earlier versions of Access. If you preview a report that was created in an earlier version of Access, the report appears in a separate window. That window provides the record navigation buttons. If you preview a report that was created in Office Access 2007, the record navigation buttons appear in the default location, at the bottom of the Access window.
-or-
, point to the arrow next to Print, and then click Print Preview.
-or-
If the report is open, right-click the document tab for the report and click Print Preview.
2.
Click the record navigation buttons to move among the pages in the report.
For more information about using the navigation buttons, see the article Learn how to find records.
-or-
, point to the arrow next to Print, and then click Print Preview.
-or-
If the report is open, right-click the document tab for the report and click Print Preview.
2.
On the Print Preview tab, in the Preview group, click Two Pages to preview your report two pages at a time.
-or-
In the Preview group, click More Pages, and then select an option.
3.
Click the record navigation buttons to move among the pages in the report.
4.
To revert to previewing a single page, in the Preview group, click One Page.
For more information about using the record navigation buttons, see the article Learn how to find records.
NOTE
Refreshing the data in a preview switches the preview back to one page.
Top of Page
You use the Page Setup dialog box to change a variety of print options, including the top and bottom margins and whether Access prints just the data in your report. Access provides two ways to display the Page Setup dialog box. You can start it from within the Print dialog box, or you can start it from the Print Preview tab, which appears when you start Print Preview.
The steps in this section explain how to display the Page Setup dialog box. For help with the commands and options that the dialog box provides, click the Help button, and then click the command or option.
Start the Page Setup dialog box from the Print dialog box
1. In the Navigation Pane, select the report that you want to change. You do not need to open the report, although you can if you need to check for any issues, such as layout problems, or to ensure that the data you are about to print is current.
2.
3.
4.
For help with an option, click the Help button, and then click the field or control for which you need help.
Start the Page Setup dialog box from the Print Preview tab
1. In the Navigation Pane, right-click the report that you want to change and click Print Preview.
2.
On the Print Preview tab, in the Page Layout group, click the Page Setup button, located in the lower left or right corner of the group. The location of the button depends on your Windows Regional and Language settings.
3.