Copyright: Microsoft Access for Windows 95


What's new with macros, modules, and developing applications?

Microsoft Access for Windows 95 provides many new features to make it easier to use macros and Visual Basic for applications modules, and to create powerful database applications.

New macro action and custom menu features

•	Save action. You can automate saving a database object by carrying out the new Save action in a macro or Visual Basic procedure. For more information about the Save action, click  [image].

•	Custom shortcut menus. You can create your own custom shortcut menus by clicking the Build button next to the new ShortcutMenuBar property. For more information, click  [image].

•	Make custom menu commands appear dimmed or selected. You can dim (gray out) or select (check) the custom menu commands a user sees while working with a database by carrying out the SetMenuItem action in a macro or Visual Basic procedure. For more information, click  [image].

Improved development environment and tools

•	Improved Module window. The Module window is easier to use than ever before, and includes color-coded syntax to help make your code easier to read. For more information, see Chapter 2, "Introducing Visual Basic," in Building Applications with Microsoft Access for Windows 95.

•	Better debugging tools. The Debug window combines an Immediate pane, where you can type commands and send information, with a Watch pane, where you can view the value of variables and controls. For more information, click  [image]  or see Chapter 7, "Debugging Visual Basic Code," in Building Applications.

•	Object Browser. The Object Browser helps you navigate between the objects in your system and take advantage of all the objects, functions, and constants available to you. For more information, click  [image]  or see Chapter 5, "Working with Objects and Collections," in Building Applications.

•	References command. Use the References command to make Visual Basic procedures available in more than one database. You can store common procedures in separate databases and then make them available to the current database without restarting Microsoft Access. For more information, click  [image]  or see Chapter 12, "Using Library Databases and Dynamic-Link Libraries," in Building Applications.

•	Startup command. Using the Startup command, you can quickly specify your application's startup form, title-bar text, icon, menu, and toolbar. You use this same interface to make customization options unavailable to your users when you deliver your completed application. For more information, click  [image]  or see Chapter 1, "Creating an Application," and Chapter 14, "Securing and Delivering Your Application," in Building Applications.

Improved programming language features

•	Object-oriented language framework. You can now declare procedures and variables as Public in form and report modules, making them available to other modules in your application. For more information, see Chapter 2, "Introducing Visual Basic," and Chapter 4, "Variables, Constants, and Data Types," in Building Applications.

•	Object creation syntax. For creating new objects, such as forms or reports, Visual Basic adds the New keyword. Using New, you can open more than one instance of the same form at a time. For more information, click  [image]  or see Chapter 5, "Working with Objects and Collections," in Building Applications.

•	Flexible parameters for procedures. Using the Optional keyword, you can declare a procedure with optional parameters. Or, using the ParamArray keyword, you can work with a variable number of parameters. Also, when calling a procedure, you can specify parameters by name, making your code more readable and allowing you to pass parameters in any order you like. For more information, see Chapter 2, "Introducing Visual Basic," in Building Applications.

•	Conditional compilation. Using the #If...Then and #EndIf statements, you can specify code that you want Microsoft Access to include or ignore in your application. This is especially useful as a debugging technique. For more information, see Chapter 7, "Debugging Visual Basic Code," in Building Applications.

•	Faster performance. Because Visual Basic loads only the code you need and performs many operations more quickly than before, your applications load and run faster. For information on taking advantage of these improvements and increasing performance in other ways, click  [image]  or see Chapter 13, "Optimizing Your Application," in Building Applications.

•	New data types and statements. Visual Basic includes two new data types, Boolean and Byte. Visual Basic also has more powerful user-defined types, which can include objects and allow you to use the ReDim statement on arrays they contain. For simpler, more readable code, try the With and For Each statements. For more information, click  [image], see Chapter 4, "Variables, Constants, and Data Types," in Building Applications, or search the online index for these keywords.

New advanced features

•	OLE Automation. Microsoft Access can now act as an OLE Automation server, so that you can control it from another application such as Microsoft Excel or the Microsoft Visual Basic programming system. For more information, see Chapter 11, "Communicating with Other Applications," in Building Applications.

•	Report, keyboard, and filtering event improvements. Two new form events, the Filter event and the ApplyFilter event, allow more precise control over filtering on your forms. Two new report events, the Page event and the NoData event, help you respond to common report printing problems. The new KeyPreview property makes it easier to process keyboard events on a form. For more information, see Chapter 6, "Responding to Events," in Building Applications.

•	Object model improvements. For more control over your application and its environment, use the new methods of the Application object, and the Err and Error objects. For more information, see Chapter 5, "Working with Objects and Collections," and Chapter 8, "Handling Run-Time Errors," in Building Applications.

•	New Calendar custom control. The Calendar control helps you produce more functional applications. For more information, see Chapter 15, "Using OLE Custom Controls," in Building Applications.

•	Database replication. If users of your application need to share data but aren't always connected to the network, database replication may be useful for you. With database replication, Microsoft Access automatically synchronizes changes between databases. For more information, see Chapter 19, "Using Database Replication," in Building Applications.

For more information on what's new for developers, click  [image].


 Start Microsoft Access with command-line options

You can automatically open a database, run a macro, supply a user account name or password, and other options when you start Microsoft Access by specifying options on the command line.

You can specify command-line options either for Microsoft Access on the Windows Start menu or for a shortcut. If you specify command-line options for the Windows Start menu, Microsoft Access will always start with those options. If you prefer to use command-line options to create alternative ways to start Microsoft Access, you can create shortcuts and put them on your desktop or in a folder, or add them to the Windows Start menu. Search Windows Help for "shortcuts" for more information.

What do you want to do?

Specify command-line options for Microsoft Access on the Start menu

Specify command-line options for a shortcut


Start Microsoft Access with command-line options from the Windows Start menu

1	Click the Windows Start button, point to Settings, and then click Taskbar.

2	Click the Start Menu Programs tab, and then click Advanced.

3	Double-click the Programs folder, and then double-click the Microsoft Office folder (or the name of the Programs subfolder where Microsoft Access is installed).

4	Use the right mouse button to click the Microsoft Access program icon shortcut, click Properties, and then click the Shortcut tab.

5	Click to the right of the Microsoft Access startup command in the Target box, and then type the desired command-line options.

For example, the following command line starts Microsoft Access, opens the Northwind sample database for exclusive access, and runs the Add Products macro:

C:\MSOffice\Access\MSAccess.exe Northwind.mdb /Excl /X Add Products

To display the list of command-line options, click  [image].


Start Microsoft Access with command-line options using a shortcut

1	Open the folder where Microsoft Access is installed (typically the folder will be named Access in the MSOffice folder on your C drive).

2	Use the right mouse button to click the Microsoft Access program icon, and then click Create Shortcut.

3	Use the right mouse button to click the shortcut icon just created, click Properties, and then click the Shortcut tab.

4	Click to the right of the Microsoft Access startup command in the Target box, and then type the desired command-line options.

For example, the following command line starts Microsoft Access, opens the Northwind sample database for exclusive access, and runs the Add Products macro:

C:\MSOffice\Access\MSAccess.exe Northwind.mdb /Excl /X Add Products

To display the list of command-line options, click  [image].

Note   After you create a shortcut you can put it on your desktop or in a folder, or add it to the Start menu. Search Windows Help for "shortcuts" for more information.

You can also create a shortcut to open any Microsoft Access database object directly from Windows.

For information on creating shortcuts to open database objects, click  [image].


Startup command-line options

The following table lists the Microsoft Access command-line options.

Option	Effect
database	Opens the specified database. Include a path if necessary.
/Excl	Opens the specified database for exclusive access. To open the database for shared access in a multiuser environment, omit this option.
/Ro	Opens the specified database for read-only access.
/User user name	Starts Microsoft Access using the specified user name.
/Pwd password	Starts Microsoft Access using the specified password.
/Profile user profile	Starts Microsoft Access using the options in the specified user profile instead of the standard Windows Registry settings created when you installed Microsoft Access. This replaces the /ini option used in previous versions of Microsoft Access to specify an initialization file.  The Microsoft Access Developer’s Toolkit contains tools and information on creating user profiles. For more information, click  [image].
/Compact target database	Compacts the database specified before the /Compact option and then closes Microsoft Access. If you omit a target database name following the /Compact option, the database is compacted to the original database name. To compact to a different name, specify a target database.
/Repair	Repairs the specified database and then closes Microsoft Access.
/Convert target database	Converts a database in an earlier version (1.x or 2.0) to a Microsoft Access 95 database with a new name and then closes Microsoft Access. Specify the source database before the /Convert option.
/X macro	Starts Microsoft Access and runs the specified macro. Another way to run a macro when you open a database is to use an AutoExec macro.
/Cmd	Specifies that what follows on the command line is the value that will be returned by the Command function. This option must be the last option on the command line. You can use a semicolon (;) as an alternative to /Cmd. For information on the Command function, click  [image].
/Nostartup	Starts Microsoft Access without displaying the startup dialog box (the second dialog box you see when you start Microsoft Access).
/Runtime	Starts Microsoft Access in run-time mode, which prevents database objects from being opened in Design view.
/Wrkgrp workgroup  information file	Starts Microsoft Access using the specified workgroup information file.
Notes

•	To run a VBA procedure when you open a database, use the RunCode action in a command-line macro or the AutoExec macro. You can also run a VBA procedure when you open a database by creating a form with a VBA procedure defined for its OnOpen event. Designate this as the startup form by using the right mouse button to click the database window, then click Startup, and then enter that form in the Display Form box.

•	To specify a forward slash (/) or semicolon (;) on the command line, type the character twice. For example, to specify the password ;mjs/md on the command line, type ;;mjs//md following the /Pwd command-line option.


Log on to a Microsoft Access workgroup

The Logon box is displayed only if the logon procedure has been activated for your Microsoft Access workgroup. Once the logon procedure has been activated, you must identify yourself at startup by entering a valid user account name. If a password has been added to a user account, you must also enter the password. Passwords are case-sensitive.

1	If necessary, change to the workgroup that contains the user account you want to log on under using the Microsoft Access Workgroup Administrator.

  How?

2	Start Microsoft Access. If the logon procedure has been activated, the Logon box is displayed.

3	Type your user account name in the Name box. Your user account name isn't case-sensitive.

4	If your password has been defined, type your password in the Password box; otherwise, leave it blank.

For information about activating the logon procedure, click  [image].

For information about adding a password to your account, click  [image].


Quit Microsoft Access

Microsoft Access automatically saves changes to your data whenever you quit. However, if you have made changes to the design of a database object since you last saved it, Microsoft Access asks whether you want to save these changes before quitting.

•	Click  [image]  in the upper-right corner of the window.

Caution   If you exit Microsoft Access unexpectedly, for example, due to a power outage or a hardware failure, your database may become damaged. Whenever possible, exit Microsoft Access as described in this topic.


Repair a damaged database

In most cases, Microsoft Access will detect that a database is damaged when you try to open, compact, encrypt, or decrypt it and give you the option to repair the database at that time. In some situations, Microsoft Access may not detect that a database is damaged. If a database behaves unpredictably, perform the following procedure.

1	Close the database. If you are in a multiuser environment, confirm that all users have closed the database.

2	Make a backup copy of the database.

  How?

3	On the Tools menu, point to Database Utilities, and then click Repair Database.

4	Specify the name and location of the database you want to repair.


Back up a database

1	Close the database. If you are in a multiuser environment, confirm that all users have closed the database.

2	Using the Windows Explorer, My Computer, Microsoft Backup, the MS-DOS copy or backup commands, or other backup software, copy the database file (an .mdb file) to a backup medium of your choice.

Notes

•	If you are backing up to a floppy disk and your database file exceeds the size of the disk, you cannot use Windows Explorer or My Computer to back up your database; you must use Microsoft Backup, the MS-DOS backup command, or backup software so that you can copy the file over more than one disk.

•	You should also create a backup of the workgroup information file. Microsoft Access stores each user's preferences and security account information in this file. If this file is lost or damaged, you won't be able to start Microsoft Access until you restore or rebuild it.

•	You can back up individual database objects by creating a blank database and then importing the desired objects from the original database.


Restore a database from a backup copy

•	Depending on what method was used originally to produce the backup copy, use the Windows Explorer, My Computer, Microsoft Backup, MS-DOS copy or restore commands, or other backup software to copy the backup database file to your database folder.

Caution   If the existing database file in the database folder and the backup copy have the same name, restoring the backup copy may replace the existing database file. If you want to save the existing file, rename it before you copy the backup file.

For information on how to rename a database file, click  [image].


Compact a database to defragment and free disk space
Compact a database to defragment the file and free disk space

If you delete tables, your database can become fragmented and use disk space inefficiently. Compacting the database makes a copy of the database, rearranging how the database file is stored on disk.

1	Close the database. If you are in a multiuser environment, confirm that all users have closed the database.

2	On the Tools menu, point to Database Utilities, and then click Compact Database.

3	In the Database To Compact From dialog box, specify the database you want to compact.

4	In the Compact Database Into dialog box, specify a name, drive, and folder for the compacted database.

You can use the same name as the original for the compacted database file, or you can use a different name to create a separate file. If you use the same name, drive, and folder, and the database is compacted successfully, Microsoft Access automatically replaces the original file with the compacted version.

Notes

•	If you delete records from the end of a table that has an AutoNumber field, when you compact the database, Microsoft Access will reset the AutoNumber value for the next added record to a value of one more than the last undeleted AutoNumber value.

•	Compacting a version 1.x or 2.0 database won't convert it to Microsoft Access 95 format. To convert a version 1.x or 2.0 database, close the database; on the Tools menu, click Database Utilities, and then click Convert Database.


Troubleshoot compacting databases

A database will not compact for any of the following reasons:

•	You don't have enough storage space on your disk for both the original and compacted versions of the database. Delete any unneeded files and try again.

•	You don't have Modify Design or Administer permission for all tables in the database. If you don't own this database, contact its owner to find out whether you can be given either of these permissions on all tables. If you own this database, you need to update your permissions for all tables. For more information on assigning permissions, click  [image].

•	If an object in a version 1.x database includes the backquote character (`) in its name, you won't be able to compact the database. Use Microsoft Access version 1.x to rename the object, and then change any references to it in your queries, forms, reports, macros, and code.


Create a database

Microsoft Access provides two methods to create a database. You can create a blank database and then add the tables, forms, reports, and other objects later — this is the most flexible method, but it requires you to define each database element separately. Or you can use a Database Wizard to create in one operation the required tables, forms, and reports for the type of database you choose — this is the easiest way to start creating your database. Either way, you can modify and extend your database at any time after it has been created.

What do you want to do?

Create a database using a Database Wizard

Create a database without using a Database Wizard

Find out more about what a database is


Create a database using the Database Wizard
Create a database using a Database Wizard

1	When Microsoft Access first starts up, a box is automatically displayed with options to create a new database or open an existing one. If this box is displayed, click Database Wizard, and then click OK.

If you have already opened a database or closed the dialog box that displays when Microsoft Access starts up, click  [image]  on the toolbar.

2	Double-click the icon for the kind of database you want to create.

3	Specify a name and location for the database.

4	Click Create to start defining your new database.


Create a database without using a wizard

1	When Microsoft Access first starts up, a box is automatically displayed with options to create a new database or open an existing one. If this box is displayed, click Blank Database, and then click OK.

If you have already opened a database or closed the dialog box that displays when Microsoft Access starts up, click  [image]  on the toolbar, and then double-click the Blank Database icon.

2	Specify a name and location for the database.

After you create a blank database, you must perform additional steps to define the objects that will make up your database.

For more information on the objects that make up a database, click  [image].

If you prefer to have Microsoft Access create an entire database application with predefined tables, forms, and reports, use a Database Wizard instead of starting with a blank database.

For information on creating a new database using a Database Wizard, click  [image].


What's new about the Database window?

The redesigned Database window in Microsoft Access for Windows 95 provides a variety of options for viewing and manipulating database objects.

•	Quickly Switch Between Objects. You can switch between object types by using tabs across the top of the window.

•	Use Different List Types for Your Objects. You can list objects using large or small icons, or list them by name or by name and details. The details are the object's properties: object description, date modified, date created, object type, and owner. Each detail appears in a separate column that you can resize to hide or show more of that information. You can also display objects in a different order by sorting them. For more information, click  [image].

•	Easily Hide Objects. You can hide objects that you don’t want others to see; for example, you might want to hide subform objects. For more information, click  [image].

•	Drag Objects to Create Desktop Shortcuts. You can drag a table, query, form, report, or macro to the desktop to create a shortcut for opening that object. For more information, click  [image].

•	Drag and Drop Data Between Applications. You can drag and drop tables and queries from the Database window to other applications, such as Microsoft Excel or Microsoft Word.

•	Create New Tables by Using Drag and Drop. You can drag and drop Microsoft Excel spreadsheet cells to the Database window to create new tables.

•	Rename Objects in Place. You can rename an object by clicking on its name and then clicking again to edit it. For more information, click  [image].


What's new about working with data?

Microsoft Access for Windows 95 adds the following new features to make working with data even easier.

•	Create Tables in Datasheet View. You can create a table by entering data directly into a blank datasheet. After you save the new datasheet, Microsoft Access analyzes your data and automatically assigns the appropriate data type and format for each field. For more information, click  [image].

•	Drag and Drop or Output Data to Other Applications. You can select data in a form or datasheet and drag and drop to Microsoft Word or Microsoft Excel. You can also select data from a form or datasheet and save it as text, as Rich Text Format (which can be opened by Microsoft Word and most Windows word processors and desktop publishing programs), or as a Microsoft Excel worksheet. For more information, click  [image].

•	Check Spelling and Automatically Correct Typing Errors. You can check the spelling of all Text or Memo fields or selected entries in datasheets and forms. For more information, click  [image]. You can also have Microsoft Access automatically correct your common spelling and typing errors as you type, and automatically capitalize the names of the days of the week. For more information, click  [image].

•	Filter in Datasheets or Forms. You can filter records easily using Filter By Selection or Filter By Form. For information about these techniques and other new filter features, click  [image].

•	Sort subforms. You can now sort records in a subform. For more information, click  [image].

•	Redesign Tables in Datasheet View. You can insert or delete fields (columns) in Datasheet view. For information about inserting fields click  [image].  For information about deleting fields, click  [image].

•	Format Datasheets. You can change a datasheet's characteristics by:

•	Displaying cells that look raised or sunken, changing the color of grid lines, showing only horizontal or vertical grid lines, or both. For more information, click  [image].

•	Displaying data in a different font color and style. For more information, click  [image].

•	Animating rows so that you can watch them slide up and fill the slot of a deleted record. This is the default, although you can turn animation off if you want.

•	Inserting a Lookup field directly by using the Lookup Wizard. For more information, click  [image].

•	Renaming a field in Datasheet view. For more information, click  [image].

•	Use Briefcase Replication to Synchronize Multiple Copies of Your Database. Through replication, multiple users in different locations can work on their own copies of a database and then synchronize the common data in all the replicas. For more information, click  [image].


Considerations when opening a database from a previous version without converting it

In a multiuser environment, all users may not have upgraded to Microsoft Access 7.0 simultaneously. If this is the case, existing databases can't be converted to 7.0 format until all users have updated to version 7.0. In the meantime, users who have updated to the current version of Microsoft Access can open a database in the previous version format. When a user opens the database in the previous version format, Microsoft Access maintains the original format so that the database can be shared by users of different versions of Microsoft Access.

When a version 7.0 user opens a version 1.x or 2.0 database, the user can view objects in the database and add, delete, or modify records. However, the user can't modify the design of objects. For information on opening a prior version database, click  [image]. To modify the design of existing objects or to add new objects, the database must be opened with the version of Microsoft Access used to create it.

Note   If the database contains forms, reports, and modules, Microsoft Access 7.0 creates separate copies of these objects and their Access Basic code so that they can be run under Visual Basic for applications. This information is stored in a hidden table named MSysModules. Depending on the size of the forms, reports, and modules in the database, the addition of the MSysModules table can as much as double the size of the database file.

For information on the differences between running converted and unconverted version 2.0 and 1.x databases under version 7.0, click  [image].

For information on converting databases to Microsoft Access 7.0, click  [image].

For information on compatibility between Access Basic in previous versions of Microsoft Access and Visual Basic in Microsoft Access version 7.0, click  [image].


What's new about securing and administering a database?

Many new features make it easier to secure and administer databases using Microsoft Access for Windows 95.

•	Use One Password to Protect Your Database. You can assign a single password to control who can open a database instead of or in addition to implementing user-level security. For more information, click  [image].

•	New User-Level Security Wizard Makes It Easier to Secure Your Database. For information on running the wizard, click  [image].

•	Hide Objects in the Database Window. You can hide database objects that you don't want other users to see or open in the Database window. For more information, click  [image].

•	Easily Change Workgroup Information on Startup. You can change to a different workgroup information file when starting Microsoft Access by using the new command-line option /Wrkgrp workgroup information file. You can use this parameter with the Run command on the Windows Start menu or in the Target box of a shortcut. For more information, click  [image].


Creating an application

After you become familiar with Microsoft Access and learn how to create tables, queries, forms, reports, custom toolbars, and so on, you can add macros and Visual Basic for applications code to tie these objects together in an application. An application organizes related tasks so that the user can focus on the job at hand, not on how the application works or on the program used to develop the application. For comprehensive information on creating an application, see Building Applications with Microsoft Access for Windows 95. You can also ask the Answer Wizard about specific topics.

You can control how your application looks and behaves when it starts by setting options in the Startup dialog box, available by clicking Startup on the Tools menu. For example, you can indicate which menu bar and which form your application displays when it starts, or you can specify the text that appears in the title bar while your application is running. For more information, see Building Applications, Chapter 1, "Creating an Application," or click  [image].

If you plan to distribute your application to other users, you may want to establish security so that the objects you have created, as well as the data in your tables, are protected from improper access. For more information on security, see Building Applications, Chapter 14, "Securing and Delivering Your Application," or click  [image].

After your application has been distributed, use the maintenance tools provided by Microsoft Access to periodically compact and repair the database. Be sure to provide a way for users at remote locations to do this as well. For more information, see Building Applications, Chapter 14. For information on compacting a database, click  [image]. For information on repairing a database, click  [image].

Tip   In addition to the tools and information provided by Microsoft Access to assist you with application development, the Microsoft Access Developer’s Toolkit provides tools to help you develop Microsoft Windows- and Office-compatible applications. For information on what the toolkit includes, click  [image].


Linking tables from a password-protected database

To link a table from a Microsoft Access database that is password-protected, you must supply the correct password. If you supply the correct password, Microsoft Access stores the database password with the information that defines the link to the table. After the link has been defined, any user who can open the database that the table is linked to can open the linked table. When a user opens the linked table, Microsoft Access uses the stored password to open the database where the table is stored. If the password is changed for the database where the table is stored, the next time the linked table is opened, the new password must be supplied before Microsoft Access will open it.

Microsoft Access stores the database password in an unencrypted form. If this will compromise the security of the password-protected database, you should not use a database password to protect the database. Instead, you should define user-level security to control access to sensitive data in that database. For more information on user-level security, click  [image].


Customize ODBC driver settings

The ODBC driver controls how Microsoft Access interacts with linked ODBC data sources. The default settings for the ODBC driver are built-in. The Setup program doesn't create an \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\ODBC key or write default values for ODBC driver settings to the Windows Registry. To override a default setting, you must add the ODBC key, add a value of the appropriate name and type (String, Binary, or DWORD), and then specify the setting.

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Double-click the Engines key.

3	To create the Engines\ODBC key, on the Edit menu, point to New, and then click Key.

4	To name the new key, type ODBC, and then press ENTER.

5	To add, name, and specify a value:

•	On the Edit menu, point to New, and then click the appropriate type of value. For information on the names, types, and default values of ODBC drivers settings, click  [image].

•	Type the name of the value, and then press ENTER.

•	Double-click the new value, and then specify its setting in the Value Data box.

For example, the setting that controls the number of seconds a cached connection can remain idle before timing out is named ConnectionTimeout, and its type is DWORD.

Note   The online reference information refers to the names of types used in the Windows NT Registry Editor. When using the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.

6	Repeat Step 5 for each value you want to specify.

7	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the ODBC driver settings you specified in Step 5 to override the corresponding default settings. If you don't specify a setting, Microsoft Access uses the default setting. After you've created the ODBC key and added values for the settings you want to override, if you want to change those values, you don't need to re-create them; you just edit their settings. To revert to a default setting, delete the value you specified using this procedure.

Important   Changes to settings in the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\ODBC key will affect all programs installed on the computer that use the Microsoft Jet database engine to access ODBC databases. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 4.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines key, add an ODBC key, and then add and specify values there.


Customize Microsoft Jet version 3.0 database engine settings

The Microsoft Jet 3.0 database engine performs data access for all databases stored in Microsoft Access version 7.0 file format (.mdb). The default settings for the Jet 3.0 database engine are built into the engine. The Setup program doesn't create an \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\Jet key or write default values for Jet 3.0 database engine settings to the Windows Registry. To override a default setting, you must add the Jet key, add a value of the appropriate name and type (String, Binary, or DWORD), and then specify the setting.

1	Start the Registry Editor, and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Double-click the Engines key.

3	To create the Engines\Jet key, on the Edit menu, point to New, and then click Key.

4	To name the new key, type Jet, and then press ENTER.

5	To add, name, and specify a value:

•	On the Edit menu, point to New, and then click the appropriate type of value. For information on the names, types, and default values of Microsoft Jet 3.0 database engine settings, click  [image].

•	Type the name of the value, and then press ENTER.

•	Double-click the new value, and then specify its setting in the Value Data box.

For example, the setting that controls the size of the database engine internal cache is named MaxBufferSize, and its type is DWORD.

Note   The online reference information refers to the names of types used in the Windows NT Registry Editor. When using the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.

6	Repeat Step 5 for each value you want to specify.

7	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Microsoft Jet 3.0 database engine driver settings you specified in Step 5 to override the corresponding default settings. If you don't specify a setting, Microsoft Access uses the default setting. After you've created the Jet key and added values for the settings you want to override, if you want to change those values, you don't need to re-create them; you just edit their settings. To revert to a default setting, delete the value you specified using this procedure.

Important   Changes to settings in the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\Jet key will affect all programs installed on the computer that use the Microsoft Jet database engine to access Microsoft Access 7.0 databases. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 4.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines\Jet key, and then add and specify values there.


Customize Microsoft Jet version 2.x database engine settings

The Microsoft Jet 2.x database engine performs data access for all databases stored in Microsoft Access version 1.x and 2.0 file formats (.mdb). The default settings for the Jet 2.x database engine are built into the engine. The Setup program creates an \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\Jet 2.x key, but it doesn't write default values for Jet 2.x database engine settings to the Windows Registry. To override a default setting, you must add an ISAM key below Jet 2.x, add a value of the appropriate name and type (String, Binary, or DWORD), and then specify the setting.

1	Start the Registry Editor, and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Double-click the Engines key, and then double-click the Jet 2.x key.

3	To create the Jet 2.x\ISAM key, on the Edit menu, point to New, and then click Key.

4	To name the new key, type ISAM, and then press ENTER.

5	To add, name, and specify a value:

•	On the Edit menu, point to New, and then click the appropriate type of value. For information on the names, types, and default values of Microsoft Jet 2.x database engine settings, click  [image].

•	Type the name of the value, and then press ENTER.

•	Double-click the new value, and then specify its setting in the Value Data box.

For example, the setting that controls the size of the database engine internal cache is named MaxBufferSize, and its type is DWORD.

Note   The online reference information refers to the names of types used in the Windows NT Registry Editor. When using the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.

4	Repeat Step 5 for each value you want to specify.

5	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Microsoft Jet 2.x database engine driver settings you specified in Step 5 to override the corresponding default settings. If you don't specify a setting, Microsoft Access uses the default setting. After you've created the ISAM key and added values for the settings you want to override, if you want to change those values, you don't need to re-create them; you just edit their settings. To revert to a default setting, delete the value you specified using this procedure.

Important   Changes to settings in the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0\Engines\Jet 2.x\ISAM key will affect all programs installed on the computer that use the Microsoft Jet database engine to access Microsoft Access 1.x and 2.0 databases. In addition to Microsoft Access 7.0, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 4.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines key, add a Jet 2.x and ISAM key below that, and then add and specify values there.


Change the starting value of an incrementing AutoNumber field

For a new table that contains no records, you can change the starting value of an AutoNumber field that has its NewValues property set to Increment to a number other than 1. For a table that contains records, you can also use this procedure to change the next value assigned in an AutoNumber field to a new number.

1	Create a temporary table with just one field, a Number field; set its FieldSize property to Long Integer and give it the same name as the AutoNumber field in the table whose value you want to change.

How?

2	In Datasheet view, enter a value in the Number field of the temporary table that is 1 less than the starting value you want for the AutoNumber field. For example, if you want the AutoNumber field to start at 100, enter 99 in the Number field.

3	Create and run an append query to append the temporary table to the table whose AutoNumber value you want to change.

How?

Note   If your original table has a primary key, you must temporarily remove the primary key before running the append query. Also, if your original table contains fields that have the Required property set to Yes, the Indexed property set to Yes (No Duplicates), or field and/or record ValidationRule property settings that prevent Null entries in fields, you must temporarily disable these settings.

4	Delete the temporary table.

5	Delete the record added by the append query.

6	If you had to disable property settings in step 3, return them to their original settings.

When you enter a record in the remaining table, Microsoft Access uses an AutoNumber field value 1 greater than the value you entered in the temporary table.

Note   If you want to compact the database after changing the starting AutoNumber value, make sure to add at least one record to the table first.  If you don't, when you compact the database, the AutoNumber value for the next record added will be reset to 1 more than the highest previous value. For example, if there were no records in the table when you reset the starting value, compacting would set the AutoNumber value for the next record added to 1; if there were records in the table when you reset the starting value and the highest previous value was 50, compacting would set the AutoNumber value for the next record added to 51.


Optimize performance

Depending on your computer's configuration and your working environment, there are several things you can do that may improve the performance of Microsoft Access or your database. The optimal settings in the categories listed below can vary with the type of computer on which you run Microsoft Access.

The best place to start is with the Performance Analyzer. You can use the Performance Analyzer to analyze a whole database or just selected objects in a database. The Performance Analyzer can even make some changes for you automatically if you want.

What do you want to do?

Run the Performance Analyzer

Improve the performance of Microsoft Access and your system

Improve table performance

Improve performance of linked tables

Improve SQL database performance

Improve performance in a multi-user environment

Improve query performance

Improve filter performance

Improve find-and-replace performance

Improve form and subform performance

Improve list box and combo box performance

Improve report and subreport performance

Improve Visual Basic for applications performance


Optimizing general table performance

You can achieve the best performance results by applying the following guidelines for table design:

•	Design tables without redundant data. A well-designed database is a prerequisite for fast data retrieval and updates. If existing tables contain redundant data, you can use the Table Analyzer Wizard to split your tables into related tables to store your data more efficiently. For more information, click  [image].

•	Choose appropriate data types for fields. You can save space in your database and improve join operations by choosing appropriate data types for fields. When defining a field, choose the smallest data type or FieldSize that's appropriate for the data in the field. For more information, click  [image].

•	Create indexes for fields you sort, join, or set criteria for. You can make dramatic improvements in the speed of queries by indexing fields on both sides of joins, or by creating a relationship between those fields and indexing any field used to set criteria for the query. Finding records through the Find dialog box is also much faster when searching an indexed field.

•	Indexes take up disk space and slow adding, deleting, and updating records. In most situations, the speed advantages of indexes for data retrieval greatly outweigh these disadvantages. However, if your application updates data very frequently or if you have disk space constraints, you might want to limit the number of indexes.

•	In a multiple-field index, use only as many fields in the index as necessary. For more information on indexes, click  [image].


Optimizing SQL database performance

If you're connecting to an external SQL database table, you can achieve the best performance results by using linked tables whenever possible instead of tables you open directly. Linked tables are considerably faster, more powerful, and more efficient than directly opened tables.

Note   You can open tables directly only by using Visual Basic for applications code, so this information doesn't apply if you are accessing SQL Server data using the Microsoft Access user interface.

Additional performance tips

•	Retrieve and view only the data you need. Use restricted queries to limit the number of records that you fetch, and select only the columns you need, so that Microsoft Access can transfer less data over the network. Don't use updatable result sets if you're not updating the data. To prevent results from being updated in a form, set the RecordSetType property to Snapshot. Also, don't page up and page down unnecessarily in the data, and avoid jumping to the last record in a large table. The fastest way to add new records to a table, is to click Records, and then click Data Entry.

•	Use cache memory. If the data most recently retrieved from the server will be requested again while the application is running, it's faster to retrieve a single large chunk of data (many rows) and store them in cache than to retrieve many individual rows. Microsoft Access forms and datasheets automatically use a cache; so you need to use cache memory only if you are retrieving data using a dynaset created in Visual Basic. If you are, you can use the CacheStart and CacheSize properties to specify the range you want within the Recordset. Use the FillCache method to quickly fill all or part of this range with data from the server.

•	Avoid using queries that cause processing to be done on a local client computer. When accessing external data, the Jet database engine processes data locally only when the operation can't be performed by the external database server. Query operations performed locally (as defined by the SQL commands used to implement them) include:

•	WHERE clause restrictions on top of a query with a DISTINCT predicate.

•	WHERE clauses containing operations that can't be processed remotely, such as user-defined functions that involve remote columns. (Note that only those parts of the WHERE clause that can't be processed remotely will be processed locally.)

•	Joins between tables from different data sources. For best performance, join only indexed columns. (Note that simply having joins between tables from different data sources doesn't mean that all of the processing occurs locally. If restrictions are sent to the server, only relevant rows are processed locally.)

•	Joins over aggregation or the DISTINCT predicate.

•	Outer joins containing syntax not supported by the ODBC driver.

•	DISTINCT predicates containing operations that can't be processed remotely.

•	ORDER BY arguments (if the remote data source doesn't support them).

•	ORDER BY arguments containing operations that can't be processed remotely.

•	Multiple-level GROUP BY arguments, such as those used in reports with multiple grouping levels.

•	GROUP BY arguments on top of a query with a DISTINCT option.

•	GROUP BY arguments containing operations that can't be processed remotely.

•	Crosstab queries that have more than one aggregate or that have an ORDER BY clause that matches the GROUP BY clause.

•	TOP or TOP PERCENT predicates.


Optimizing the performance of Microsoft Access and your system

The following guidelines can help you optimize the performance of Microsoft Access and your computer:

•	Use the Add-in Manager to uninstall wizards, builders, and other add-ins you don't need. This reduces Microsoft Access memory consumption and the amount or time it takes to start Microsoft Access. The change won't take effect until you restart Microsoft Access.

•	Make more memory available by closing applications that you aren't using.

•	Increase RAM on your computer. Microsoft Access requires a minimum of 12 MB, but additional RAM improves performance.

•	Don't use any of your RAM for a RAM disk.

•	Periodically delete unnecessary files, compact your databases, and then defragment your hard disk with the Disk Defragmenter. To run the Disk Defragmenter, click the Windows Start button, point to Programs, point to Accessories, point to System Tools, and then click Disk Defragmenter.

•	In most cases, the default virtual memory setting used by Windows should perform optimally. However, in some situations adjusting virtual memory parameters can improve performance. If you've already tried deleting unnecessary files, and you still have a performance problem, try changing the default virtual memory setting in the following cases:

•	You don't have much disk space available on the drive that is currently being used for virtual memory, and another local drive with space is available.

•	Another local drive is available that is faster than the current drive (unless that disk is heavily used).

In these cases, you might get better performance by specifying a different drive.

You also might get better performance by specifying that the disk space available for virtual memory is at least 25 MB minus available RAM. For example, if your computer has 12 MB of RAM, you should specify at least 13 MB of virtual memory. You may want to specify more if you are running several large applications.

To change Windows virtual memory parameters, in the Windows Control Panel, double-click the System icon, click the Performance tab, click Virtual Memory, and then click Let Me Specify My Own Virtual Memory Settings. Then specify a different hard disk, or enter a value in the Minimum box that is at least 25 minus your available RAM.

•	If you're using databases that other users don't need to share, install Microsoft Access and all your databases on your hard disk drive rather than on a network server.

•	If you have a wallpaper (full-screen background) bitmap on your Windows desktop, replace it with a solid color or pattern bitmap, or no bitmap at all.


Optimize database performance using the Performance Analyzer

1	Open the database you want to optimize.

2	On the Tools menu, point to Analyze, and then click Performance.

3	In the Object Type list, click the type of database object you want to optimize. (Click All to view a list of all database objects at once.)

4	In the Object Name list, select the database objects you want to optimize. (Click Select All to select all database objects of that type.)

5	Repeat steps 3 and 4 until you've selected all the objects you want to optimize, and then click OK.

A list of three kinds of optimizations is displayed: Recommendations, Suggestions, and Ideas. When you click an item in the list, information about the proposed optimization is displayed in the Analysis Notes box below the list. Suggestion optimizations have potential tradeoffs that you should consider before performing them. To view a description of the tradeoffs, click on a Suggestion optimization in the list, and then read the information in the Analysis Notes box. Microsoft Access can perform Recommendation and Suggestion optimizations for you. You must perform Idea optimizations yourself.

6	Click each of the Recommendation or Suggestion optimizations you want performed, and then click Optimize.

To perform all Recommendation or Suggestion optimizations, click Select All, and then click Optimize.

To perform an Idea optimization, click that optimization, and then follow the instructions displayed in the Analysis Notes box.

Note   The Performance Analyzer doesn't provide suggestions on how to improve the performance of Microsoft Access itself or the system it is running on. For additional suggestions on improving performance in other areas that aren't covered by the Performance Analyzer, click  [image].


Customize Windows Registry settings used by Microsoft Access

Microsoft Access stores its initialization information in the Windows Registry. The Windows Registry is a centralized database that Windows uses to set up and configure the software and hardware running in your Windows environment. The Registry is analogous to the .ini files used under Windows 3.x, with each key in the Registry similar to a bracketed heading in an .ini file, and values under each Registry key similar to entries under an .ini file heading.

Caution   Many Microsoft Access Registry settings are added automatically when you install Microsoft Access. Changing the installed settings can produce unexpected results, which may make it necessary to reinstall Microsoft Access. It is strongly recommended that you not change settings in the Windows Registry. However, if you must change Registry settings or options, use the Windows Registry Editor, and change only those settings or options that are explicitly documented in the topics below. It is recommended that you back up all of the Registry, or at least the part you will be editing. For information, look up "backing up the Registry" in the index of the Registry Editor's online Help on the menu bar of the Registry editor. The revised settings take effect the next time you start Microsoft Access.

In many cases, you can customize builders, wizards and other add-ins using options available in their dialog boxes. For additional information, see Chapter 12, "Using Library Databases and Dynamic-Link Libraries," and Chapter 16, "Creating Wizards, Builders, and Add-ins," in Building Applications with Microsoft Access for Windows 95.

What Registry settings do you want to customize or specify?

Settings that affect how the Microsoft Jet database engine reads and saves Microsoft Access 7.0 data

Settings that affect how the Microsoft Jet database engine reads and saves Microsoft Access 1.x and 2.0 data

Settings used for interaction with Lotus 1-2-3 spreadsheets

Settings used for interaction with Microsoft Excel spreadsheets

Settings used for interaction with delimited and fixed-width text files

Settings used for interaction with Microsoft FoxPro and dBASE databases

Settings used for interaction with Paradox databases

ODBC settings used for interactions with SQL databases

Settings used to register an add-in or wizard that Microsoft Access loads at startup

The workgroup information file that defines your workgroup

Whether OLE links are saved in OLE version 2.0 or 1.0 format


Use the Registry editor

Caution   Many Microsoft Access Registry settings are added automatically when you install Microsoft Access. Changing the installed settings can produce unexpected results, which may make it necessary to reinstall Microsoft Access. It is strongly recommended that you not change settings in the Windows Registry. However, if you must change Registry settings or options, use the Windows Registry Editor, and change only those settings or options that are explicitly documented in the topics below. It is recommended that you back up all of the Registry, or at least the part you will be editing. For information, look up "backing up the Registry" in the index of the Registry Editor's online Help on the menu bar of the Registry Editor. The revised settings take effect the next time you start Microsoft Access.

1	To run the Registry Editor under Windows 95, click the Windows Start button, click Run, type regedit, and then click OK.

To run the Registry Editor under Windows NT, in the Program Manager or File Manager, click Run on the File menu, type regedt32, and then click OK.

2	Double-click the key icons to navigate to the appropriate Registry key. The two main keys that contain settings that affect Microsoft Access are:

•	\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0

•	\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0

If there is a plus (+) to the left of the key, that registry key contains additional keys. To edit a registry key's value(s), double-click the key in the left pane of the Registry Editor window to open it, and then double-click the value you want to edit in the right pane of the Registry Editor window. In some cases, you may need to add new keys or values. For information on how to add new keys and values, use the Registry Editor's online Help.

Important   The keys displayed below the \Microsoft\Access\7.0 key apply only to Microsoft Access 7.0. The keys that are displayed below the \Microsoft\Jet\3.0 key apply to the Microsoft Jet database engine that Microsoft Access uses for data access. Changes to either of these settings affect Microsoft Access and will affect other programs that use the Microsoft Jet database engine, such as Microsoft Excel 7.0. Visual Basic 4.0, Visual C++ 4.0, and possibly others. To make changes to Microsoft Jet database engine settings that affect only Microsoft Access, change the settings in the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0 key.


Specify a workgroup information file using Registry settings

Caution   It is strongly recommended that you use the Workgroup Administrator to change your workgroup information file instead of modifying Registry settings directly. The Workgroup Administrator provides easy-to-use dialog boxes for joining an existing workgroup or for creating a new workgroup information file. For more information, click  [image].

1	Start the Registry Editor, and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0 key of the registry.

How?

2	Open the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines\Jet key.

3	Double-click the SystemDB value in the right pane of the Registry Editor window.

4	In the Value Data box, type the name and new path of the workgroup information file — for example, c:\workgroup\system.mdw. If the workgroup information file is located on a network, you may be able to omit the drive letter by using a UNC path.

5	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the workgroup information file you specified in step 4, including its security and user preference settings.


Customize Lotus driver settings

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Make the desired changes in the \Engines\Lotus and \ISAM Formats\Lotus WK1, WK3, or WK4 keys.

For information on Lotus driver settings, click  [image].

3	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Lotus driver settings you specified in step 2.

Important   Changes to settings in these keys will affect all programs installed on the computer that use the Microsoft Jet database engine to access Lotus 1-2-3 data. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 3.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines or \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\ISAM Formats keys, add the appropriate Lotus key, and then add and specify values there. For example, to specify \Engines\Lotus settings, add a new key named Lotus below Engines, and then add and specify values in that key. To determine the appropriate names and types for values for Lotus settings, click the button following step 2. The reference information that is displayed there refers to the types used in the Windows NT Registry Editor. In the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.


Customize Microsoft Excel driver settings

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Make the desired changes in the \Engines\Excel and \ISAM Formats\Excel 3.0, 4.0, or 5.0 keys.

For information on Microsoft Excel driver settings, click  [image].

3	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Microsoft Excel driver settings you specified in step 2.

Important   Changes to settings in these keys will affect all programs installed on the computer that use the Microsoft Jet database engine to access Microsoft Excel data. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 3.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines or \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\ISAM Formats keys, add the appropriate Excel key, and then add and specify values there. For example, to specify \Engines\Excel settings, add a new key named Excel below Engines, and then add and specify values in that key. To determine the appropriate names and types for values for Excel settings, click the button following step 2. The reference information that is displayed there refers to the types used in the Windows NT Registry Editor. In the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.


Customize Text driver settings

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Make the desired changes in the \Engines\Text and \ISAM Formats\Text keys.

For information on Text driver settings, click  [image].

3	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Text driver settings you specified in step 2.

Important   Changes to settings in these keys will affect all programs installed on the computer that use the Microsoft Jet database engine to access Text data. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 3.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines or \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\ISAM Formats keys, add a new key named Text, and then add and specify values there. To determine the appropriate names and types for values for Text settings, click the button following step 2. The reference information that is displayed there refers to the types used in the Windows NT Registry Editor. In the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.


Customize FoxPro or dBASE driver settings

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Make the desired changes in the \Engines\Xbase and \ISAM Formats\dBASE III, IV, or 5.0 or FoxPro 2.0, 2.5, 2.6, 3.0, or DBC keys.

For information on FoxPro driver settings, click  [image].

For information on dBASE driver settings, click  [image].

3	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the FoxPro or dBASE driver settings you specified in step 2.

Important   Changes to settings in these keys will affect all programs installed on the computer that use the Microsoft Jet database engine to access dBASE or FoxPro data. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 3.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines or \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\ISAM Formats keys, add the appropriate dBASE or FoxPro key, and then add and specify values there. For example, to specify \Engines\Xbase settings, add a new key named Xbase below Engines, and then add and specify values in that key. To determine the appropriate names and types for values for FoxPro or dBASE settings, click the appropriate button following step 2. The reference information that is displayed there refers to the types used in the Windows NT Registry Editor. In the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.


Customize Paradox driver settings

1	Start the Registry Editor and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.0 key of the registry.

How?

2	Make the desired changes in the \Engines\Paradox and \ISAM Formats\Paradox 3.x, 4.x, or 5.x keys.

For information on Paradox driver settings, click  [image].

3	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the Paradox driver settings you specified in step 2.

Important   Changes to settings in these keys will affect all programs installed on the computer that use the Microsoft Jet database engine to access Paradox data. In addition to Microsoft Access, this includes Microsoft Excel 7.0, Visual Basic 4.0, Visual C++ 3.0, and possibly others. To make changes that apply only to Microsoft Access, navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\Engines or \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Jet\3.0\ISAM Formats keys, add the appropriate Paradox key, and then add and specify values there. For example, to specify \Engines\Paradox settings, add a new key named Paradox below Engines, and then add and specify values in that key. To determine the appropriate names and types for values for Paradox settings, click the button following step 2. The reference information that is displayed there refers to the types used in the Windows NT Registry Editor. In the Windows 95 Registry Editor, a REG_DWORD value is called a DWORD value, a REG_BINARY value is called a Binary value, and a REG_SZ value is called a String value.


Specify whether OLE links are saved in OLE version 1.0 or 2.0 format

You can specify whether Microsoft Access saves OLE links in OLE version 2.0 format, which saves both relative and absolute link source references, or OLE 1.0 format, which saves only absolute references. (An absolute link source reference obtains data from an object that's stored as a file. A relative link source reference obtains data from an object that may be embedded within a document.) In an environment where both Microsoft Access versions 7.0 and 1.x are used, set this option to 1 to ensure consistency of OLE linking operations in Microsoft Access 1.x databases.

1	Start the Registry Editor, and navigate to the \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0 key of the registry.

How?

2	Double-click the Options key. If AllowOLE1LinkFormat is already listed in the Name column on the right pane of the Registry Editor, skip to step 5.

3	On the Edit menu, point to New, and then click DWORD Value.

4	Type AllowOLE1LinkFormat and press ENTER.

5	Double-click AllowOLE1LinkFormat, and then, in the Value Data box, enter 1 to save in OLE 1.0 link format or 0 to save in OLE 2.0 link format.

6	Exit the Registry Editor.

The next time you start Microsoft Access, it will use the OLE link settings you specified in step 5.


Convert a database

Although you can open a version 2.0 or 1.x database in Microsoft Access version 7.0 without converting it, you can't change the design of objects in that database, nor can you take advantage of many of the new features in Microsoft Access 7.0 until you convert your database. However, once you've converted a database to Microsoft Access 7.0, you can't open that database in a previous version (2.0 or 1.x), or convert it back.

The primary reason not to convert a database from a previous version of Microsoft Access (version 1.x or 2.0) is if there are users of that database who can't upgrade to Microsoft Windows 95 and Microsoft Access 7.0. If you convert the database, these users will not be able to open or use it. Microsoft Access 7.0 can open and use databases from previous versions, but it can't add new database objects or modify the design of current database objects in those databases. If you need to maintain databases from previous versions of Microsoft Access, you must retain installations of those previous versions to modify the design of those databases.

Similarly, if a database is opened by an application created with Visual Basic for applications 3.0 or 2.0, you should not convert that database until the application can be upgraded to Visual Basic 4.0. Microsoft Access 7.0 can continue to access such a database in its current format.

For the most part, Microsoft Access 7.0 is compatible with databases developed with previous versions; however, in a few cases new features can conflict with existing databases and code.

What do you want to do?

Read about the differences between running converted and unconverted databases

Read about compatibility issues when converting tables, forms, and reports from Microsoft Access 1.x or 2.0

Read about compatibility issues when converting macros and Access Basic code from Microsoft Access 1.x or 2.0

Convert a database

Convert a workgroup file (usually System.mda) created in previous version of Microsoft Access


Convert databases to Microsoft Access version 7.0 from previous versions

Although generally compatible with Microsoft Access version 2.0 and 1.x databases, Microsoft Access version 7.0 may change the behavior of some database objects. For information, click  [image].

1	Make a backup copy of the database you're going to convert, to keep until you're comfortable working with the Microsoft Access 7.0 database.

How?

2	If you're going to convert a database with linked tables, make sure that these tables are still in the directory that the database you are converting refers to.

3	Close the database you're going to convert.

If the database is located on a server or shared folder, make sure that no one else has it open.

4	On the Tools menu, point to Database Utilities, and then click Convert Database.

Important   To convert a secured database, you must meet the following requirements or conversion will fail:

•	You must join the workgroup information file that defines the user accounts used to access the database, or that was in use when the database was created.

•	Your user account must have Open/Run and Open Exclusive permissions for the database object.

•	Your user account must have Modify Design or Administer permissions for all tables in the database, or you must be the owner of all tables in the database.

•	Your user account must have Read Design permissions for all objects in the database.

•	After you convert a secured database, you should also convert the workgroup information file used with it. For more information, click  [image].

5	In the Database To Convert From dialog box, select the database you want to convert, and then click Convert.

6	In the Convert Database To dialog box, do one of the following:

•	Type a new name (without the .mdb extension) for the version 7.0 database file.

•	Select a different location. (You can keep the same name, or change it.)

7	Click Save.

Microsoft Access converts the database to version 7.0 format.

Notes

•	When you convert a Microsoft Access 2.0 or 1.x database that has links to external tables, make sure that these tables are in the same directory that they were originally in. If Microsoft Access can't find the tables that are linked to a database that's being converted, you'll lose table properties defined in the database you're converting. Once you've converted the database, you can move these tables and use the Linked Table Manager to re-link them. Converting a database that has tables linked to it does not convert the linked tables.

•	If a Microsoft Access 2.0 or 1.x database has links to tables stored in a Microsoft Access 7.0 database, you can't use the linked tables from within the Microsoft Access 2.0 or 1.x database. You must convert the database to Microsoft Access 7.0 format. However, if a Microsoft Access 7.0 database is linked to tables stored in a Microsoft Access 2.0 or 1.x database, you can use the linked tables from within the Microsoft Access 7.0 database.


Identifying invalid validation rules using the ConvertErrors table

When Microsoft Access encounters invalid validation rules while converting your database to Microsoft Access version 7.0, it creates a table named ConvertErrors in the converted database, which has information to help you fix the validation rules. The following table describes the fields in the ConvertErrors table.

Field Name	Description
Error	Brief description of the error
Field	Field in the table where the error occurred
Property	Table property where the error occurred
Table	Name of the table where the error occurred
Unconvertible Value	Property value that caused the problem
Microsoft Access can't convert validation rules to Microsoft Access 7.0 if they contain any of the following elements:

•	User-defined functions (functions you or someone else writes in Visual Basic for applications).

•	Microsoft Access domain aggregate functions.

•	Totals (aggregate) functions.

•	References to forms, queries, or tables.

•	For field validation, references to other fields. For record validation, however, references to fields in the current table can be included.

In addition, Microsoft Access 7.0 may prevent some Microsoft Access 1.x validation rules from being converted because it includes the improvements from Microsoft Access 2.0 for validating data in linked tables. In Microsoft Access 1.x, the ValidationRule, ValidationText, and DefaultProperty settings for fields and records in a table don't apply to the table when it's linked to another database. Instead, you add the validation rules and default values you want to the database the table is linked to. But in Microsoft Access 2.0 and 7.0, validation rules and default values for fields and records in the original table do apply to any database the table is linked to. However, you can't add or modify validation rules or default values for a linked table. If you have validation rules or default values defined for a linked table that's in a Microsoft Access 1.x database, the rules and default values won't be converted when you convert the database to Microsoft Access 7.0.

After viewing the table for validation rules that weren't converted, add validation rules as necessary to conform to the following new restrictions:

•	To add a rule that compares the values in two fields, the rule must be for a record, not for a field in the table. For example, you can use a validation rule for a record to make sure that one field's value is always greater than that of another in the same record.

•	To add a rule that includes control or user-defined function references, set the rule for a control on a form, not for a field in a table.


Running converted and unconverted version 2.0 and 1.x databases under version 7.0

Unless you have a reason not to convert a Microsoft Access version 1.x or 2.0 database, you should convert the database to take full advantage of the new features in Microsoft Access 7.0. However, if you need to, you can use most objects in a Microsoft Access 1.x or 2.0 database with Microsoft Access version 7.0 without conversion. In some cases, new features change the way an object works.

The following list explains differences in how objects in your version 1.x or 2.0 database function when you use them with Microsoft Access 7.0 without conversion. For information about changes to methods, actions, properties, syntax, and other language elements, and information about code compatibility and conversion issues, click  [image].

Guidelines for converting Microsoft Access version 1.x or 2.0 to version 7.0

•	Creating and modifying objects. Although you can use objects in the database to view and modify the data in a database, you can't save changes to database objects when you're using Microsoft Access 7.0 to work with a Microsoft Access 2.0 or 1.x database. To modify the design of an object or create a new object in the database, you must either open the database using the previous version or convert the database to Microsoft Access 7.0 format.

•	Changing database permissions. If your database is secure, you can make sure that it retains all its security by using the Workgroup Administrator to join the secure database's Microsoft Access 1.x or 2.0 workgroup information file. As long as you use the database in its original workgroup, it retains all its security. However, you can't use Microsoft Access 7.0 to change or add permissions in the database — you must either open the database with the previous version or convert the database to version 7.0 format. To take advantage of Microsoft Access 7.0's enhanced security, you must recreate your user and group accounts and passwords using a Microsoft Access 7.0 workgroup information file. If all members of a previous version workgroup information file have upgraded to Microsoft Access 7.0, you can convert the previous version file to Microsoft Access 7.0 format. For information, click  [image].

Guidelines for converting Microsoft Access version 1.x only (not version 2.0) to version 7.0

•	Control names that contain the right bracket (]). If your Microsoft Access 1.x forms have controls that include the right bracket in their names, the forms will work the same as they did in Microsoft Access 1.x after you convert them to Microsoft Access 7.0. However, you can't create a new control that contains a right bracket in its name, and if you try to modify a control name that already contains a right bracket, you must remove the right bracket.

•	Backquote character (`) in object names. If an object name in a Microsoft Access 1.x database includes a backquote character (`), you won't be able to open that object using Microsoft Access 7.0 or to convert the database to Microsoft Access 7.0 format. Use Microsoft Access 1.x to rename it first. After renaming the object, you must also change references to that object in your queries, forms, reports, macros, and modules for them to work correctly. To find occurrences of the old name in your references, on the Tools menu, point to Analyze, and then click Documentor.

•	Updating query fields. Using Microsoft Access 7.0, you can update the data in some fields in multiple-table queries that you can't update using Microsoft Access 1.x. For example, in a query that includes fields from a Customers table and an Orders table (where one customer can have more than one order), you can't update fields from the Customers table using Microsoft Access 1.x. Using Microsoft Access 7.0, you can update fields from the Customers table in most situations. This makes your queries and the forms based on them less restrictive. If you don't need to update these fields in a form, set the Locked property of form controls that are bound to the fields to Yes.

•	Combo boxes and list boxes. For combo boxes and list boxes that have their RowSource property set to a table or a query, Microsoft Access 7.0 displays data in the rows of the combo or list box using the format defined for the data in the Format property of the underlying field. Microsoft Access 1.x didn't do this.

•	Validation rules for tables. Enhanced validation rules for fields and records make your data safer in Microsoft Access 7.0, but come with new restrictions on what elements you can include in a rule. Rules in Microsoft Access 1.x databases that conflict with these restrictions can't be converted.

In Microsoft Access 7.0, validation rules you set for tables or their fields are always enforced, whether you add or edit data through a form or datasheet, append or update query, or Visual Basic for applications, or by importing it. Validation rules set for controls on forms are enforced only when you enter data using the form. In Microsoft Access 1.x, validation rules protect your data only when it is entered or modified using a datasheet or form.

In most cases, this enhanced validation doesn't change the way your database works at all. If you have the same validation rule set for both a field in a table and a control on a form that's bound to that field in a Microsoft Access 1.x database, after converting the database you can delete the validation rule set for the control. Your form will work the same way whether you delete it or not.

If your Microsoft Access 1.x database validation rules contain elements not allowed in Microsoft Access 7.0, the rules won't be converted to Microsoft Access 7.0 format. When Microsoft Access encounters invalid validation rules while converting your database, it creates the ConvertErrors table in the converted database with information to help you fix the rules. For information, click  [image].

•	Visible property. In Microsoft Access 1.x, setting a control's Visible property to No makes the control invisible in Form view and also hides its column in Datasheet view. In Microsoft Access 7.0, the Visible property doesn't hide its column in Datasheet view. In Microsoft Access 7.0, if you want to hide a column, on the Format menu, click Hide Columns. In a macro or Visual Basic code, you can set the column's ColumnHidden property.

•	Text and Memo fields with null values. If you don't type a value in a Text or Memo field in a Microsoft Access 1.x database, Microsoft Access stores a null value in the field. In Microsoft Access 7.0 (and Microsoft Access 2.0), you have the option of storing either a null value or a zero-length string. When you convert a database, all the null values in your 1.x database remain null values in the converted database, and your database will work exactly as it did in Microsoft Access 1.x. To take advantage of the new flexibility, you can change the property settings of the new Required and AllowZeroLength properties for Text and Memo fields. For more information, click  [image].


Normalize a table using the Table Analyzer Wizard

If your database has a table that contains a great deal of duplicate information in one or more fields, you can use the Table Analyzer Wizard to split the data into related tables so that you can store data more efficiently. This process is called normalization. Using the wizard, you can either specify the tables you want to create or have Microsoft Access normalize your table automatically.

1	On the Tools menu, point to Analyze, and then click Table.

2	Follow the instructions in the Table Analyzer Wizard dialog boxes. The first two dialog boxes explain what normalization is and why it's useful. In the last dialog box, you can create a query to view all the information from the split tables in a single datasheet.


Selecting the kind of AutoNumber field to use when a table will be replicated

If you plan to replicate your database, you need to consider what field size is appropriate for the AutoNumber field used as a table's primary key. If you use an AutoNumber field as the primary key for a table in the replicated database, set its FieldSize property to either Long integer or Replication ID.

•	If fewer than 100 records are routinely added between synchronizing replicas, use a Long Integer setting for the FieldSize property to take up less disk space.

•	If more than 100 records are routinely added between synchronizing replicas, you should use Replication ID for the FieldSize property setting to prevent records from being assigned the same primary key value in each replica. Note, however, that an AutoNumber with a Replication ID field size produces a 32-bit value that will require more disk space.


Determining the relationships for your database

After you've set up different tables for each subject in your database, you need a way of telling Microsoft Access how to bring that information back together again. The first step in this process is to define relationships between your tables. After you've done that, you can create queries, forms, and reports to display information from several tables at once. For example, this form includes information from these tables:

How do relationships work?

A relationship works by matching data in key fields — usually a field with the same name in both tables. In most cases, this will be the "primary key" from one table, which provides a unique identifier for each record, being matched with an entry in the "foreign key" in the other table. For example, employees can be associated with orders they're responsible for by creating a relationship between EmployeeID fields.

A one-to-many relationship

A one-to-many relationship is the most common type of relationship. In a one-to-many relationship, a record in Table A can have many matching records in Table B, but a record in Table B has no more than one matching record in Table A. For example, the Suppliers and Products tables have a one-to-many relationship: each supplier provides many products, but each product comes from only one supplier.

A many-to-many relationship

In a many-to-many relationship, a record in Table A can have many matching records in Table B, and vice versa. This is only possible by defining a third table (called a junction table) whose primary key consists of at least two fields — the foreign keys from both Table A and B. For example, the Orders table and the Products table have a many-to-many relationship that's defined by creating two one-to-many relationships to the Order Details table.

A one-to-one relationship

In a one-to-one relationship, a record in Table A can have no more than one matching record in Table B, and vice versa. This type of relationship is not common, because most information related in this way would be in one table. You might use a one-to-one relationship to divide a wide table, to isolate part of a table for security reasons, or to store information that only applies to a subset of the main table. For example, you might want to create a table to track employees participating in a fundraising soccer game.

Defining relationships

You define a relationship by adding the tables you want to relate to the Relationships window, and then dragging the key field from one table and dropping it on the key field in the other table.

The kind of relationship that Microsoft Access creates depends on how the related fields are defined.

•	A one-to-many relationship is created if only one of the related fields is a primary key or has a unique index.

•	A one-to-one relationship is created if both of the related fields are primary keys or have unique indexes.

•	A many-to-many relationship is really two one-to-many relationships with a third table whose primary key consists of two fields — the foreign keys from the two other tables.

For more information on how to define relationships, click  [image].

Note   If you drag a field that isn't a primary key and doesn't have a unique index to another field that isn't a primary key and doesn't have a unique index, an indeterminate relationship is created. In queries containing tables with an indeterminate relationship, Microsoft Access displays a default join line between the tables, but referential integrity won't be enforced, and there's no guarantee that records are unique in either table.


Optimizing multiuser performance

The following guidelines can help you optimize the performance of databases that are used in a multiuser environment.

•	Put only the tables on a network server, and keep other database objects on users' computers. The database's performance will be faster because only data is sent across the network. You can separate the tables from other database objects by using the Database Splitter Wizard. For more information, click  [image].

•	Choose an appropriate record-locking strategy. For more information, click  [image].

•	Avoid locking conflicts by adjusting Refresh Interval, Update Retry Interval, Number of Update Retries, and ODBC Refresh Interval settings (if applicable). For more information, click  [image].

•	Optimize table performance. For more information, click  [image].

•	Improve the performance of databases with linked tables. For more information, click  [image].

•	Improve the performance of databases connected to an SQL table. For more information, click  [image].

•	Convert the workgroup information file. For more  information, click  [image].


What's new with table design?

Microsoft Access for Windows 95 provides many new features to make designing tables easier and to make the tables more powerful:

•	Create Lookup Lists with the New Lookup Wizard. Use the Lookup Wizard to create a Lookup field that displays a list of values (either in a list box or combo box) looked up from another table. You can also use the Lookup Wizard in a table to create a field that displays a list of values you define. Adding this Lookup field to a form by dragging it from the field list automatically creates a list box or combo box with the same properties. Lookup field list boxes or combo boxes are also automatically added to any query that includes that field.

•	Create Tables from Datasheet View. Create a table by entering data in a blank datasheet — much like adding data to a spreadsheet. When you save the new datasheet, Microsoft Access evaluates the data you entered and automatically creates appropriate field types and formats for you. Also, you can add, insert, and rename columns (fields) to any table in Datasheet view at any time. For more information on creating tables this way, click  [image].

•	Improve Table Design with the New Table Analyzer Wizard. Use the Table Analyzer to split a large table into two or more smaller tables so that you can store data more efficiently. This is particularly useful if you are importing data from a large flat-file database such as a spreadsheet and want to take advantage of Microsoft Access relational database features. For more information, click  [image].

•	Modify a Table's Design While Setting Relationships. Change a table's design from the Relationships window, for example, to define a primary key or add additional fields.

•	Link Text Files and Spreadsheets. Link (attach) data from delimited and fixed-width text files, and spreadsheets.

For information on new, changed, and deleted table properties or other language elements, click  [image].


What's new in Microsoft Access version 7.0; databases,; databases, designing; designing databases;
What's new with database design?

Microsoft Access for Windows 95 adds the following new features to make designing and using a database easier and make your databases more powerful:

•	Create Databases with the New Database Wizard. Use the Database Wizard to quickly create an entire database from one of many database templates. For more information, click  [image].

•	Optimize Your Database's Performance. Use the Performance Analyzer to optimize the performance of all or selected objects in your database. The Performance Analyzer will automatically make some changes for you, and will provide suggestions and considerations for other improvements you can make yourself. For more information, click  [image].

•	Save Network Overhead with the New Database Splitter Wizard. Use the Database Splitter Wizard to split a database into a back end containing the data (tables) and a front end containing all other objects and links to the tables in the back end. This is useful when sharing a database on a network. The back end (data) then resides in a shared folder, and users run copies of the front end from their own computers. This creates less network overhead than running the entire database from a shared folder. For more information, click  [image].

•	Set Properties for Your Database. View, change, and define database properties. For example, you can view or change summary information (such as a title, subject, or author), or you can view statistics (such as the creation date, the name of the last user to access the database, or total editing time) or a list of all objects in a database. You can also define your own database properties that identify characteristics of the database, which you can search for if you don't remember the filename. For more information, click  [image].

•	Easily Customize Your Database. Create a customized application easily using the new Startup properties to specify whether a specific form displays automatically whenever a database is opened or control whether custom or built-in menus, the Database window, or Status bar are displayed. For more information, click  [image].


Set OLE/DDE preferences

1	On the Tools menu, click Options, and then click the Advanced tab.

2	Under DDE Operations, select the options you want.

•	Select Ignore DDE Requests to ignore DDE requests from other applications.

•	Select Enable DDE Refresh to update DDE links at the interval specified in the Refresh Interval box.

1	In the OLE/DDE Timeout box, enter the number of seconds (0 to 300) to wait before retrying a failed OLE or DDE operation.

Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


The difference between ODBC drivers and built-in drivers for external data

In Microsoft Access, you can import, export, or link data from a number of different database, spreadsheet, and text file formats. To do this, Microsoft Access uses either a built-in driver or an ODBC driver.

Built-in Drivers

Microsoft Access contains built-in drivers that enable you to import, export, or link the following types of data:

•	Other Microsoft Access databases

•	Microsoft FoxPro version 2.0, 2.5, 2.6, and 3.0 database files (version 3.0 files can't be linked)

•	Paradox version 3.x, 4.x, and 5.0 tables

•	dBASE III, IV, and 5 files

•	Microsoft Excel and Lotus 1-2-3 spreadsheets (Lotus 1-2-3 files can't be linked)

•	Text (fixed-width and delimited text files)

•	Microsoft Word for Windows mail merge data files (export only)

The built-in drivers are the only kind of drivers that should be used to import, export, or link these types of data. These drivers are available when you use the Save As/Export command and the Import and Link Tables commands on the Get External Data submenu on the File menu. If a built-in driver for a type of data has been installed, that type will be available in the Save As Type box on the Save In Object Name dialog box, or in the Files Of Type box on the Import or Link dialog boxes. The Microsoft Excel, Lotus 1-2-3, Text, and Microsoft Word for Windows drivers are installed automatically when you install Microsoft Access. If you choose the Typical option when you install Microsoft Access, the other built-in drivers won't be installed. For information on installing additional built-in drivers,  click [image].

ODBC Drivers

You can use ODBC drivers to connect to Microsoft SQL Server databases and data from other programs that provide 32-bit drivers in compliance with ODBC Level 1 to access their data files. The Setup program supplies the Microsoft SQL Server ODBC driver and some ODBC support files (Help files and the 32bit ODBC Control Panel option). If the Microsoft SQL Server ODBC driver and support files have been installed, the ODBC Databases option will be available in the Save As Type box on the Save In Object Name dialog box and in the Files Of Type box on the Import or Link dialog boxes. Also, the 32bit ODBC icon will be available in the Windows Control Panel. For information on installing and setting up ODBC drivers, click  [image].

Third-party vendors may supply additional ODBC drivers and documentation that support other data formats. For more information on whether an ODBC driver is available for a particular type of data, contact the vendor of the program that produces that type of data. Microsoft Access requires 32-bit ODBC drivers that are in compliance with ODBC Level 1.

Note   Other Microsoft products and products from other vendors also contain ODBC drivers, including drivers for the same applications listed in the Built-in Drivers section above. These ODBC drivers may be installed on your computer. If you want to know whether these drivers have been tested and verified for use with Microsoft Access, contact the driver vendor.

The Setup program also provides an option named Microsoft Desktop ODBC Drivers. This option installs ODBC drivers for Microsoft Access, FoxPro, dBASE, Paradox, Excel, and Text that are different from the built-in drivers for the same types of data and cannot be used to import, export, or link these types of data with Microsoft Access. Use the built-in drivers described above to work with these types of data. The Microsoft Desktop ODBC drivers are supplied so that other programs that can use ODBC drivers, such as Microsoft Query (a program that is supplied with Microsoft Excel), can use them.


Install built-in drivers

1	Rerun the Setup program, and then click Add/Remove.

How?

2	Select Data Access, and then click Change Option.

3	Select the drivers you want to install, and then click OK.

4	Click Continue, and follow the instructions in the remaining Setup dialog boxes.


Install ODBC drivers and set up ODBC data sources

You can install the Microsoft SQL Server driver using the Setup program, then use the ODBC Manager (called the ODBC Administrator if you are using Microsoft Windows NT) to specify data sources. You can also use the ODBC Manager (or ODBC Administrator) to specify data sources for other installed ODBC drivers.

Install the Microsoft SQL Server driver supplied with Microsoft Access

When you installed Microsoft Access, if you chose the Custom installation option in the Microsoft Access Setup program and left the Data Access option and the Microsoft SQL Server ODBC Driver option under the Data Access option checked, then ODBC support and the Microsoft SQL Server driver was installed on your workstation. If you didn't do this or if you chose Typical when installing, you need to re-run the Setup program and choose to add this component. For information on re-running Setup to install drivers, click  [image]. For specific requirements for installing the Microsoft SQL Server driver and setting up data sources, click  [image]. After the driver is installed, you still need to set up data sources using the ODBC Manager according to the instructions below.

Note    The Microsoft Desktop ODBC Driver option of the Setup program installs ODBC drivers for Microsoft Access, FoxPro, dBASE, Paradox, Excel, and Text data. However, these drivers are not for use with Microsoft Access; they are supplied so that other applications, such as Microsoft Query, can use them.

Install ODBC drivers other than Microsoft SQL Server

To install drivers other than the Microsoft SQL Server driver, you need to obtain the files and documentation for that ODBC driver from the vendor of the data format. Microsoft Access requires 32-bit ODBC drivers that are in compliance with ODBC Level 1. Each ODBC driver has specific requirements for installing and setting up data sources. Refer to the driver's documentation for more information.

Start the ODBC Manager

If you installed the Microsoft SQL Server ODBC driver when you ran the Setup program, you can use the 32bit ODBC Manager (or the ODBC Administrator for Windows NT) to set up new data sources or modify existing data sources.

1	In Microsoft Windows 95, click the Windows Start button, point to Settings, click Control Panel, and then double-click the 32bit ODBC icon.

In Microsoft Windows NT, double-click the ODBC Administrator icon in the ODBC program group, or run the Odbcad32.exe program installed in your \Windows\System directory.

2	Do one of the following:

•	To define a new data source for a currently installed driver, click Add.

•	To modify the definition of an existing data source, click a name in the User Data Sources list, and then click Setup.

Notes

•	You must use specific network protocols and network configurations when you connect a Microsoft Access database to an SQL database using an ODBC driver. For more information, click  [image].

•	When you start the ODBC Manager (or the ODBC Administrator), you can click the Help button in each dialog box to get Help on how to enter the information in that dialog box. For more information on how to use this program, click  [image].


Network configurations and ODBC Drivers

You must use specific network protocols and network configurations when you connect a Microsoft Access database to an SQL database using an ODBC driver. The following protocols and configurations have been tested for use with Microsoft Access and the Microsoft SQL Server driver.

Server platform	Network protocol
Microsoft SQL Server version 4.2a (OS/2)	Microsoft Named Pipes
Microsoft SQL Server NT	Microsoft Named Pipes
For other supported platforms, please consult your Microsoft SQL Server documentation including the SQL Server Driver Help file. For more information, click  [image].


Use the SQL Server driver and the ODBC help files

The Microsoft SQL Server Driver Help file (Drvssrvr.hlp) provides detailed information on using the Microsoft SQL Server driver and setting up data sources for SQL Server databases.

The ODBC Manager Help (Odbcinst.hlp) explains how to use the ODBC Manager (called the ODBC Administrator if you have Microsoft Windows NT) to add, modify, and delete ODBC drivers and data sources.

Because the ODBC Help files are separate from the Microsoft Access Help file and are meant to be used with a number of Microsoft applications, you should keep the following information in mind when you use these files:

•	The Microsoft SQL Server Driver and ODBC Control Panel Option Help files are installed on your computer only if you have installed ODBC.

•	You can't use the Back button at the top of the Help window to return to Microsoft Access Help from one of these Help files. You must reopen Microsoft Access to return to the original Microsoft Access Help window.

What do you want to do?

Display the Microsoft SQL Server Driver Help file

Display the ODBC Manager Help file


Install, uninstall, or customize wizards, builders, and menu add-ins

You can install or uninstall wizards, builders, and other add-ins using the Add-in Manager.

1	On the Tools menu, point to Add-ins, and then click Add-in Manager.

The Add-in Manager dialog box is displayed. The Available Add-ins list displays the add-ins that are currently available. An add-in is already installed if there is an X next to its name. If an add-in is uninstalled, Microsoft Access removes the X but keeps the name in the list.

2	Do one of the following:

•	To add an add-in to the list, click Add New, and then specify its location.

•	To install a currently available add-in, click the add-in name in the Available Add-ins list, and then click Install.

•	To uninstall a currently available library database, click the add-in name in the Available Add-ins list, and then click Uninstall.

3	Click Close when you've finished.

Notes

•	You should uninstall an add-in before opening it as a database to modify its design. Uninstalling add-ins can also improve response time in Microsoft Access.

•	You can no longer customize wizards using the Add-in Manager. In most cases, customization is now available as an option in the wizard dialog boxes.


Convert a workgroup information file from a previous version of Microsoft Access

While Microsoft Access for Windows 95 can use a workgroup information file from previous versions of Microsoft Access, additional memory is required to do so. To take full advantage of improvements in security and to reduce memory usage, you should convert your workgroup information files.

Important   If any member of a secure workgroup that was defined with a previous version will not be upgraded to Microsoft Access 95, do not convert the workgroup information file (usually system.mda). Those users must continue to use the file in its current format. Users of Microsoft Access 95 can either use the Workgroup Administrator to join the workgroup information file created by the previous version, or you can re-create their user accounts and groups in a new workgroup information file for Microsoft Access 95. For information on setting more than one workgroup to share the same secure database, click  [image].

1	If you are currently using the workgroup information file from a previous version of Microsoft Access, use the Workgroup Administrator to join another workgroup.

How?

2	Make sure that no other users are using the workgroup information file from the previous version by having them exit Microsoft Access.

3	Start Microsoft Access without opening a database. On the Tools menu, point to Database Utilities, and then click Convert Database.

4	In the Files Of Type box, select Add-ins (*.mda), enter the workgroup information file you want to convert, and then click Convert. The Database To Convert From dialog box is displayed.

5	In the Convert Database Into dialog box, do one of the following:

•	Type a new name for the Microsoft Access 95 workgroup information file.

•	Select a different location. You can keep the same name, or change it.

6	Click Save.

Note   To save the converted file using the new .mdw extension, select Workgroup Files (*.mdw) in the File Of Type box before you click Save.

7	Use the Workgroup Administrator to join the converted workgroup information file.

Note   Users of a Microsoft Access 2.0 or 1.x workgroup information file that was converted using this procedure will not be able to print user and group information unless they are logged on as members of the Admins group. If you want all users in the workgroup to be able to print user and group information (a new feature in Microsoft Access 7.0), you must create a new workgroup information file, and then re-create the original user accounts and groups by re-entering their exact names and personal identifiers.


Copy or move data

What do you want to do?

Copy or move data from one field to another

Copy or move data from multiple fields in Datasheet view

Copy or move records to a datasheet

Copy or move records to a form

Copy or move records from Microsoft Access to another application

Copy or move records from another application to Microsoft Access


Check the spelling of data

What do you want to do?

Check the spelling of data in Datasheet view

Check the spelling of data in Form view

Check the spelling in a table, query, or form in the Database window


Create a shortcut to open a form, table, query, report, macro, or module from the desktop or another folder

You can create a shortcut to open an object that's stored locally in a database on your computer or remotely in a database on a network file server or in a shared directory.

1	In the Database window, click the tab containing the object you want to create a shortcut for.

2	Use the right mouse button to click the object you want to make a shortcut for, and then click Create Shortcut.

3	If you want the shortcut to go to a location other than the desktop, type a new path in the Location box, or click Browse to choose the location and have Microsoft Access fill in the path for you. For example, you might want to store the shortcut in the Favorites folder, which stores shortcuts to items you use frequently or to items you want to find quickly.

4	If you're creating a shortcut for an object in a database that isn't currently on a network but will be moved to one, or if the database is already on the network but will be moved to a different network location, press ALT+N and then type the path to it in this format:

\\server\share\filename

With the network path specified, you can, for example, send the shortcut through email so that others with access to the network can use the shortcut too.

Note   If you're already using the database over the network, Microsoft Access fills in the path for you.

5	Click OK.

When you double-click the shortcut, Microsoft Access opens the database in which the object is stored and displays the object in its default view. To open the object in a specific view, use the right mouse button to click the shortcut, and then click the view you want.

Notes

•	If you have a shortcut to a database that is subsequently moved, delete the old shortcut and create a new one.

•	To delete a shortcut, click it, and then press the DEL key. Deleting the shortcut does not delete the item that the shortcut opens.

•	If you have the Microsoft Windows operating system, you can quickly create a shortcut by dragging the object from the Database window to the desktop or to a folder. Make sure the place you want to drag the shortcut to is visible. (If you previously maximized the Microsoft Access window, minimize it enough to show the desktop or the folder where you want to place the shortcut.)


 Print a table, query, form, report, or module from a shortcut

After you create a shortcut for an object, you can print the object directly from the shortcut icon.

1	Use the right mouse button to click the shortcut.

2	Click Print.

3	Select the options you want to use, and then click OK.

Tip   If you have the Microsoft Windows operating system, you can quickly print from a shortcut by dragging the shortcut icon to a printer icon on the desktop or in the Printers folder.


Open a table

1	In the Database window, click the Tables tab.

2	Click the name of the table you want to open.

3	To open the table in Design view, click Design.

To open the table in Datasheet view, click Open.

Notes

•	Once you've opened a table, you can easily switch between the two views by clicking the arrow next to the View button on the toolbar.

•	For information about creating a shortcut that opens a table directly from the desktop or a folder, click  [image].


View or print properties, permissions, and design information for database objects

Viewing and printing the design characteristics (the definition) of an object helps you document a database's design or the design of a Microsoft Access application you create. You can view or print the definition of the selected database object or of multiple objects.

1	On the Tools menu, point to Analyze, and then click Documentor.

2	In the Object Type box, enter the type of database object you want to view or print.

You can click All Object Types to display a complete list of objects in the database.

3	In the Objects box, click the objects whose definitions you want to view or print.

To select all the database objects, click Select All.

4	Click Options to specify which features of the selected object you want to print, and then click OK.

Microsoft Access saves the options in the Print ObjectType Definition dialog box between sessions.

5	Click OK.

You might want to check the length of your definitions in the Print Preview window, because some definitions, particularly those for forms and reports, can be many pages long.

6	To print the definition, click  [image]  on the toolbar.


Copy a table, query, form, report, macro, or module

1	In the Database window, click the tab containing the object you want to copy.

2	Click the object, and then click  [image]  on the toolbar.

3	If you are copying the object to a different database, close the current database and open the database into which you want to paste the object.

4	With the Database window displayed, click  [image]  on the toolbar.

5	Provide the information requested in the Paste As dialog box, and then click OK.

Note   If you have problems copying a table's data, click  [image].

To undo the paste operation, click  [image]  on the toolbar.

Notes

•	When you copy an object, Microsoft Access includes any properties associated with the object.

•	You can drag a table, query, or report from the Database window to another Microsoft application to copy the object. You can also drag standard modules between Microsoft Access and Microsoft Excel.

•	You can drag a table, query, form, report, macro, or module from the Database window in one Microsoft Access database to the Database window in another Microsoft Access database to copy the object. Before you do this, you must open the second database in another instance of Microsoft Access.

•	It may be easier to copy a large number of records with an append query.

How?


Copy or move a field, a control, text, a macro action, or another item

1	Click the items you want to copy or move.

2	To copy the item, click  [image]  on the toolbar.

To move the item, click  [image]  on the toolbar.

3	Click the location where you want to place the item.

4	Click  [image]  on the toolbar.

To undo the paste operation, click  [image]  on the toolbar.

Notes

•	When you copy a field, control, or action, Microsoft Access includes any associated properties, controls, or action arguments. For example, when you copy a text box control, Microsoft Access copies its label as well. When you copy an action, Microsoft Access copies the associated action arguments, macros, and conditional expressions.

•	Microsoft Access doesn't copy event procedures associated with a control.

•	You can drag OLE objects onto a form in Form view or onto a form and report in Design view to copy those objects.


Rename a database in the Microsoft Windows operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	In My Computer or Windows Explorer, find the database file.

3	Click the name of the file (not its icon), and then click it again to edit the title.

4	Type the new name. Include the .mdb extension only if you've set up Microsoft Windows to display MS-DOS file extensions. Press ENTER.

The filename can be up to 255 characters, including spaces.

Important   If other databases include linked objects from the database you renamed, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].


Rename a database in the Microsoft Windows NT operating system.
Rename a database in the Microsoft Windows NT operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	Use the Windows File Manager or the MS-DOS rename command to rename the Microsoft Access .mdb file. The new name can be up to eight characters long but can't contain spaces. Remember to include .mdb as the filename's extension.

Important   If other databases include linked objects from the database you renamed, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].


Copy or move a database in the Microsoft Windows operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	In My Computer or Windows Explorer, find the database file and then click it.

To select more than one database file to copy or move, hold down the CTRL key and then click each file.

3	To copy the file, click Copy on the Edit menu.

To move the file, click Cut on the Edit menu.

4	Open the folder or disk where you want to put the file.

5	On the Edit menu, click Paste.

To undo the paste operation, click Undo Paste on the Edit menu.

Important   If other databases include linked objects from a database you moved, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].

Note  If the destination where you're placing the file is already visible, you can quickly move the file by dragging it to the new destination, or you can copy the file by holding down the CTRL key while you drag the file.


Copy or move a database in the Microsoft Windows NT operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	Use the Windows File Manager or the MS-DOS copy command to copy or move the Microsoft Access .mdb file.

Important   If other databases include linked objects from a database you moved, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].


Delete a database in the Microsoft Windows operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	In My Computer or Windows Explorer, find the database file, and then click it.

3	Press the DEL key.

Note   If you want to get your file back, look in the Recycle Bin. Your deleted file will remain in the bin until you empty it.

Important   If other databases include linked objects from the database you deleted, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].


Delete a database in the Microsoft Windows NT operating system

1	Close the database. In a multiuser environment, confirm that all users have closed the database.

2	Use the Windows File Manager or the MS-DOS del command to delete the Microsoft Access .mdb file.

Important   If other databases include linked objects from the database you deleted, use the Linked Table Manager in those other databases to update the link information. Otherwise, Microsoft Access will produce an error when you try to use those linked objects. For more information, click  [image].


Delete a table, query, form, report, macro, or module

1	In the Database window, click the tab containing the object you want to delete.

2	Click the object, and then press the DEL key.

To undo the delete operation, click  [image]  on the toolbar.


Save a table, query, form, report, macro, or module

•	Click  [image]  on the toolbar.

If you are saving an object for the first time, type a name that follows Microsoft Access object-naming rules in the Save As dialog box, and then click OK.

Note   You don't need to save data in records. Microsoft Access automatically saves a record when you do any of the following: move the focus to a different record; close the active form, datasheet, or database; or quit Microsoft Access.


Save a copy of a database object with a new name or to another file or database

1	If the object is open and is selected, click Save As/Export on the File menu.

If the object isn't open, click the tab in the Database window that contains that object, click the object, and then click Save As/Export on the File menu.

2	To save the object in the current database, click the first option in the Save As dialog box, type a unique name for the object that follows Microsoft Access object-naming rules, and then click OK.

If you're saving an object to an external file or database, Microsoft Access will export the object or output its data in a different format depending on the options you select. For more information on exporting objects and data, click  [image].

Tip   To easily customize an existing database object, save a copy of the object with a different name and then modify the copy.


Rename a table, query, form, report, macro, or module

1	Make sure the object you want to rename is closed.

2	In the Database window, click the tab for the object you want to rename.

3	Click the object's name, and then click the name again to edit it.

4	Type the new name for the object following Microsoft Access object-naming rules, and then press ENTER.

Important   If you rename a database object, such as a table, you need to update any reference to the object in other database objects, such as forms or reports. For example, if you created a form that is bound to the table, be sure to change the table's name in the form's RecordSource property.


Bypass settings that determine how a database or application starts

If you used the Startup dialog box on the Tools menu or created an AutoExec macro to specify what happens when a database or application starts, you can bypass those settings to regain full access to the database or application.

•	Hold down the Bypass key (the SHIFT key) while you open the database.


Set or view database properties used for locating the database later
Set or view database properties used for locating a database

Database properties identify characteristics of a particular database file. These properties help identify the file when the filename is forgotten or unknown. When users are trying to locate a database using the Open dialog box in Microsoft Access, Microsoft Word, or Microsoft Excel, they can use advanced find criteria to specify the properties of the file they are looking for. For example, they can search for a database whose Contents property includes a table named Suppliers.

1	With the database open, click Database Properties on the File menu.

2	Click the tab for the properties you want to view, set, or change.

Note   Except for the properties on the General and Statistics tabs, these properties can also be manipulated using Visual Basic.


Document a database's characteristics and associated keywords for use in locating the file later
Document a database's characteristics and associated keywords for use in locating the file

A database's characteristics and associated keywords help identify the file when the filename is forgotten or unknown. When users try to locate a database using the Open dialog box in Microsoft Access, Microsoft Word, or Microsoft Excel, they can use advanced find criteria to specify the characteristics or keywords associated with the file they are looking for. For example, they can search for a database that lists you as the author.

1	With the database open, click Database Properties on the File menu.

2	Click the Summary tab, and then specify as much of the requested information as you want to.

3	Click OK.

Note   For each item you complete on the Summary tab, the associated properties are automatically set. For a list of those properties, click  [image].


Create custom database properties for use in locating the file later
Create custom database properties for use in locating the file

Custom properties of a database help identify the file when the filename is forgotten or unknown. When users try to locate a database using the Open dialog box in Microsoft Access, Microsoft Word, or Microsoft Excel, they can use advanced find criteria to specify the custom properties of the file they are looking for. For example, they can search for a database file that has a custom property named DeliveryDate whose value is less than 1/1/95.

1	With the database open, click Database Properties on the File menu.

2	Click the Custom tab, and then type values in the Name, Type, and Value boxes.

3	Click Add, and then click OK.

Note   These properties can also be manipulated using Visual Basic.


Modify or delete custom database properties

1	With the database open, click Database Properties on the File menu.

2	Click the Custom tab.

3	Click the name of the property you want to delete or modify in the Property Name column.

4	To modify the property, type the changes in the Name, Type, or Value boxes, and then click Modify.

To delete the property, click Delete.


View a list of tables, queries, forms, reports, macros, and modules in the current database

1	With the database open, click Database Properties on the File menu.

2	Click the Contents tab.

Tip   If you forget the name of a database, you can use advanced find criteria to locate the file based on the information on the Contents tab. For example, you can search for a database whose Contents property includes a table named Suppliers. You specify advanced find criteria in the Open dialog box in Microsoft Access, Microsoft Excel, or Microsoft Word.


View the attributes of a database file

1	With the database open, click Database Properties on the File menu.

2	Click the General tab.

Tip   If you forget the name of a database, you can use advanced find criteria to locate the file based on the information on the General tab. For example, you can search for a database that was created on 7/1/95. You specify advanced find criteria in the Open dialog box in Microsoft Access, Microsoft Excel, or Microsoft Word.


Delete a field, a control, text, a macro action, or another item

1	Select the items you want to delete.

2	Press the DEL key.

Note   To undo the delete operation, click  [image]  on the toolbar.


Print the datasheet of a table, query, or form

To print the entire datasheet

1	Display the table, query, or form datasheet.

2	To change the settings in the Print dialog box before printing, click Print on the File menu, and then select the options you want to use.

To print immediately without changing the settings in the Print dialog box, click  [image]  on the toolbar.

To print only certain records in the datasheet

1	Display the table, query, or form datasheet.

2	Select the records you want to print.

3	On the File menu, click Print, and then click Selected Record(s).

Notes

•	You can preview your datasheet before printing by clicking  [image]  on the toolbar.

•	For information about how to quickly print the datasheet from a shortcut, click  [image].


Control how a Microsoft Access database or application starts

You can specify, for example, what form to display, whether toolbars can be customized, or whether shortcut menus are available.

1	On the Tools menu, click Startup.

2	Select the options, or enter the settings you want to use.

Notes

•	For information about a specific item in the dialog box, click  [image], and then click the item.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].

•	For additional information about creating an application, click  [image].


Considerations when setting options in the Startup dialog box

•	The Startup options apply only to the current database or application.

•	When you specify a setting in the Startup dialog box, you automatically set the database property associated with that setting. For a list of those properties, click  [image].

•	The Menu Bar and Shortcut Menu Bar options in the Startup dialog box don't override the property settings for specific forms or reports that have a custom menu bar or shortcut menu. Thus, when you open a form or report, Microsoft Access displays the custom menu bar attached to the form or report instead of the global menu bar specified in the Startup dialog box.

•	You can use the Startup dialog box instead of or in addition to an AutoExec macro. An AutoExec macro runs after the Startup options have taken effect; therefore, you should avoid any actions in an AutoExec macro that change the effect of the Startup option settings. For example, if you specify a form in the Display Form box in the Startup dialog box, and you also use the OpenForm action in an AutoExec macro, Microsoft Access first displays the form specified in the Startup dialog box, then immediately displays the form specified in the OpenForm action.

•	If user-level security has been defined for your database, you can prevent users from changing the settings in the Startup dialog box by making sure they haven't been granted the Administer permission for the database. For more information, click  [image].

•	To bypass the Startup option settings, hold down the Bypass (SHIFT) key while opening the database.


Display a startup form when a database or application opens

1	On the Tools menu, click Startup.

2	In the Display Form box, click a form from the current database.

3	If you don't want users to see or use the Database window, which appears behind the form, clear the Display Database Window check box.

If you clear the Display Database Window check box but leave the Use Access Special Keys check box selected, the database window is still accessible. For more information, click  [image].

Notes

•	Changes to these settings in the Startup dialog box won't take effect until the next time the database or application is opened.

•	The form displays in the application window. You can display a custom title in the application window's title bar by typing it in the Application Title box.

•	The startup form for the Northwind sample database is the form you see when you first open the database. The Main Switchboard form in the database is an example of a form that you might use as a startup form to control navigation in your database. To view these forms, open the Northwind database in your Microsoft Access program folder's Samples subfolder. The Startup form appears automatically, but you can view it or the Main Switchboard form whenever you want by clicking the Forms tab in the Database window, clicking Startup or Main Switchboard, and then clicking Open. For information on opening Northwind, click  [image].

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Create a global menu bar that displays when a database or application opens

By using your own global menu bar, you control what tasks users can perform in your database or application by limiting and customizing the menus and commands that are available.

1	On the Tools menu, click Startup.

2	In the Menu Bar box, click the name of a menu bar macro from the current database, or click (Default) to display the built-in menu bar. If you want to create a custom menu bar, click the Build button next to the Menu Bar box to display the Menu Builder. For information on using the Menu Builder, click  [image].

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	If you select the Use Access Special Keys check box, the built-in menu bar will also be accessible. For more information, click  [image].

•	You can designate or change the global menu bar in a Visual Basic for applications procedure by setting the MenuBar property of the Application object. For more information about the MenuBar property, click  [image].

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Create a global shortcut menu for a database or application

1	On the Tools menu, click Startup.

2	In the Shortcut Menu Bar box, click the name of a menu bar macro from the current database, or click (Default) to display the built-in shortcut menu. If you want to create a custom shortcut menu, click the Build button next to the Menu Bar box to display the Menu Builder. For information on using the Menu Builder, click  [image].

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	You can designate or change the shortcut menu in a Visual Basic for applications procedure by setting the ShortcutMenuBar property of the Application object. For more information about the ShortcutMenuBar property, click  [image].

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Display or hide the Database window when a database or application opens

1	On the Tools menu, click Startup.

2	Clear or select the Display Database Window check box.

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	If you don't display the Database window, you need to display a form for users to use to navigate in your database or application. For more information, click  [image].

•	If you clear the Display Database Window check box but leave the Use Access Special Keys check box selected, the Database window is still accessible. For more information, click  [image].

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Show or hide the status bar when a specific database or application opens

1	On the Tools menu, click Startup.

2	Select or clear the Display Status Bar check box.

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	You can also control whether the status bar is shown or hidden by default for all Microsoft Access databases. To do this click Options on the Tools menu, click the View tab, and then select or clear the Status Bar check box. The current database won't display a status bar if either the Status Bar check box in the Options dialog box or the Display Status Bar check box in the Startup dialog box is cleared.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Allow or prevent access to built-in toolbars when a database or application opens

1	On the Tools menu, click Startup.

2	Clear or select the Allow Built-in Toolbars check box.

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	To prevent users from customizing built-in toolbars, select the Allow Built-in Toolbars check box, but clear the Allow Toolbar Changes check box. To enable users to modify built-in toolbars, make sure both the Allow Built-in Toolbars and Allow Toolbar Changes check boxes are selected.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Control whether all or a subset of the built-in menus is displayed

If the database or application you're creating provides the user access to the built-in menu bar, you can control whether only a predefined subset of the menus is displayed or all the menus are displayed, including menus that enable changing the design of objects in the database.

1	On the Tools menu, click Startup.

2	Clear or select the Allow Full Menus check box.

Notes

•	Changes to these settings in the Startup dialog box won't take effect until the next time the database or application is opened.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Allow or prevent toolbar changes when a database or application opens

You can control whether users can change built-in toolbars and custom toolbars.

1	On the Tools menu, click Startup.

2	Clear or select the Allow Toolbar Changes check box.

Notes

•	Changes to these settings in the Startup dialog box won't take effect until the next time the database or application is opened.

•	To prevent users from using the built-in toolbars, clear the Allow Built-in Toolbars check box.

•	If you want all shortcut menus except those on the toolbars to be available (so that toolbars can't be changed), clear the Allow Toolbar Changes check box but select the Allow Default Shortcut Menus check box.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Enable or disable shortcut menus when a database or application opens

You can control whether built-in shortcut menus are accessible.

1	On the Tools menu, click Startup.

2	Clear or select the Allow Default Shortcut Menus check box.

Notes

•	Changes to these settings in the Startup dialog box won't take effect until the next time the database or application is opened.

•	If you want shortcut menus accessible for everything except toolbars (so that toolbars can't be changed), leave the Allow Default Shortcut Menus check box selected, but clear the Allow Toolbar Changes check box.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Enable or disable the capability to view code after an application run-time error

1	On the Tools menu, click Startup.

2	Click Advanced.

3	Clear or select the Allow Viewing Code After Error check box.

Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	If the Use Access Special Keys check box is selected, you can manually stop code from executing and display the current module in the Module window at any time by pressing CTRL+BREAK.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Enable or disable keys that display the Database or Debug windows, menu bars, or modules

1	On the Tools menu, click Startup.

2	Click Advanced.

3	Clear or select the Use Access Special Keys check box to enable or disable the following keys:

Keys	Result
F11 or ALT+F1	Brings the Database window to the front
CTRL+G	Brings up the Debug window
CTRL+F11	Toggles between the custom menu bar and the built-in menu bar
	Stops code from executing and displays the current module in the Module window
Notes

•	Changes to this setting in the Startup dialog box won't take effect until the next time the database or application is opened.

•	Whether or not you select the Use Access Special Keys check box, you can display the Module window to debug code after a run-time error occurs by selecting the Allow Viewing Code After Error check box.

•	If you clear the Use Access Special Keys check box and you specify a custom menu bar in the Menu Bar box, the built-in menu bar isn't accessible.

•	If you clear both the Use Access Special Keys check box and the Display Database Window check box, the Database window isn't accessible.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Display a custom icon for an application

1	On the Tools menu, click Startup.

2	In the Application Icon box, enter the name of the .ico or .bmp file that contains the application's icon. If you don't know the name of the file, click the Build button next to the box, and then use the Icon Browser to locate the file. (The Icon Browser works the same way as the Open dialog box. For information on using the search features in these dialog boxes, click  [image].)

Note

•	Changes to the Application Icon setting take effect immediately upon closing the Startup dialog box.

•	If you’ll be distributing your application, it’s recommended that the icon file reside in the same folder as your Microsoft Access application.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Display a specific title in the application window title bar

1	On the Tools menu, click Startup.

2	In the Application Title box, enter the title you want displayed in the application window's title bar.

Notes

•	Changes to the Application Title setting take effect immediately upon closing the Startup dialog box.

•	For a list of things to consider when setting options in the Startup dialog box, click  [image].


Open a database created with this or a previous version of Microsoft Access

For considerations when opening a database created with a previous version of Microsoft Access, click  [image].

1	Click  [image]  on the toolbar.

2	Do one of the following:

•	If you know the drive where the database file is located, click that drive in the Look In box. If the file is in the Favorites folder, click  [image]  on the toolbar. In the display area below the Look In box, click the database file you want to open (or double-click the folder the file is in, and then click the file). Click Open.

Note   The first time you open a database from a previous version of Microsoft Access or each time you open it after changing its Access Basic code in modules, forms, or reports, Microsoft Access for Windows 95 displays the Convert/Enable Database dialog box. Click Open Database.

•	If you don't know where the database file is located, enter specific information about it in the boxes at the bottom of the dialog box. Microsoft Access will use this information as the search criteria to find the file for you. Click Find Now.

To use more advanced search criteria, click Advanced. For more information on the Advanced Find dialog box, click  [image].

3	To open the database for read-only access, click  [image], and click Open Read Only.

4	To open the database for exclusive access, select the Exclusive check box.

To open the database for shared access in a multiuser environment, clear the Exclusive check box if it's selected.

For more information on items in the dialog box, click  [image]  at the top of the dialog box, and then click the item.

Notes

•	To open one of the last four databases you had open, on the File menu, click the filename. Microsoft Access opens the database with the same option settings it had the last time you opened it.

•	Microsoft Access can automatically create a shortcut in the Favorites folder, which you can use to open the database directly the next time. For more information, click  [image]. For information on creating a shortcut manually, click  [image].

•	You can create custom properties to search on when trying to locate the database later. Once you've opened the database, on the File menu, click Database Properties, and then click the Custom tab. For more information, click  [image].


Refine criteria for finding a database by using the Advanced Find dialog box

The box at the top of the Advanced Find dialog box lists criteria statements, which define what properties you want to search for. By default, Microsoft Access searches for all files with the .mdb extension. You can refine the search by adding more criteria statements in the Advanced Find dialog box.

1	Click  [image]  on the toolbar.

2	Click Advanced.

3	In the Property box, click the property you want to use as criteria.

4	In the Condition box, click the condition you want.

5	In the Value box, type the value that completes the criteria statement.

6	To the left of the Property box, do one of the following:

•	If you want the search to be dependent on this criteria statement and the last one listed in the Find Files That Match These Criteria box, click And.

•	If you want this criteria statement to be independent of the last one listed, click Or.

7	Click Add To List.

8	If you want to limit the search to a specific folder, type the path in the Look In box.

9	If you want to save the current search criteria, click Save Search and type a name for the search. When you want to use that search criteria again, click Open Search and click the name of the search you want.

10	To start the search, click Find Now.

For more information on each item in the dialog box, click  [image]  at the top of the dialog box, and then click the item.

Note   You can set or view the properties for a database by clicking Database Properties on the File menu.


Customize the Microsoft Access environment by setting defaults

If you choose the same settings repeatedly for particular tasks, you can customize Microsoft Access to use those settings by default. For example, if you always want datasheets to look a certain way, you can set default colors for the font, background, and gridlines, and set other effects you use routinely.

1	On the Tools menu, click Options.

2	Click the tab for the options you want to set.

3	Select the options you want to use.

4	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.

Note   Microsoft Access saves the option settings in your workgroup information file, not in your user database (the .mdb file). When you change an option setting, the change applies to any database that anyone in your workgroup (who uses the same workgroup information file) opens or creates.


Show or hide system objects in the Database window by default

Microsoft Access automatically creates the tables it needs when you create a new database. In the Database window, you can show or hide these system-defined tables or any system objects you create.

1	On the Tools menu, click Options, and then click the View tab.

2	Under Show, select or clear the System Objects check box.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Show or hide objects defined as hidden by default

If you need to work with objects that are defined as hidden without changing their status as hidden, you can display them in the Database window.

1	On the Tools menu, click Options, and then click the View tab.

2	Under Show, select or clear the Hidden Objects check box. Microsoft Access displays hidden objects with dimmed icons to distinguish them from objects that aren't defined as hidden.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Change default behavior for find and replace operations
Change default behavior for find or replace operations

1	On the Tools menu, click Options, and then click the Edit/Find tab.

2	Under Default Find/Replace Behavior, click the option you want to use.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.

Note   Changes made to this setting don't take effect until the next time you start Microsoft Access. To change the behavior for a specific find or replace operation, choose Find or Replace from the Edit menu, and then set the appropriate options in the dialog box.


Set default print margins

1	On the Tools menu, click Options, and then click the General tab.

2	Under Print Margins, specify the margins you want to use as defaults.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.

Note   Changing these options doesn't affect the margin settings for existing forms and reports.


Set databases to open in exclusive or shared mode by default

1	On the Tools menu, click Options, and then click the Advanced tab.

2	Under Default Open Mode, click the option you want to use.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Change the default folder for new Microsoft Access databases

1	On the Tools menu, click Options, and then click the General tab.

2	In the Default Database Folder box, type the path name of any valid folder where you want new Microsoft Access databases to be stored, and then click OK.

If no path is specified (which is the default), Microsoft Access defaults to the My Documents folder.

The new default folder won't take effect until you restart Microsoft Access.


Specify the default language sort order for a database

Set this option to specify the alphabetic sort order Microsoft Access uses when you create a new database.

1	On the Tools menu, click Options, and then click the General tab.

2	In the New Database Sort Order box, click the language you want to use.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.

Note   To reset the sort order for an existing database using the language you selected on the General tab, compact that database.


Turn confirmation messages for record changes, document deletions, or action queries on or off

1	On the Tools menu, click Options, and then click the Edit/Find tab.

2	Under Confirm, select or clear the check boxes, as appropriate.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Change default behavior of the ENTER key, arrow keys, TAB key, and insertion point

Set these options to change the behavior of the specified keys for moving within or between fields.

1	On the Tools menu, click Options, and then click the Keyboard tab.

2	Under Move After Enter, Arrow Key Behavior, and Behavior Entering Field, select the options you want, and then select or clear the Cursor Stops At First/Last Field check box.

Note   For Microsoft Access to use the Behavior Entering Field option you select, Arrow Key Behavior must be set to Next Field.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Show or hide the Microsoft Access startup dialog box by default

The startup dialog box is the first dialog box you see when you start Microsoft Access. It has options for creating a new database and opening an existing one.

1	On the Tools menu, click Options, and then click the View tab.

2	Under Show, select or clear the Startup Dialog Box check box.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.


Show or hide the status bar by default for all Microsoft Access databases

1	On the Tools menu, click Options.

2	On the View tab under Show, select or clear the Status Bar check box.

3	Click Apply to apply the settings immediately without closing the dialog box; click OK to apply the settings and close the dialog box.

Note   You can control whether the status bar shows or hides for a specific database or application. For more information, click  [image].


Bound, unbound, and calculated controls


Customizing a chart


Customizing a form


Customizing a query


Customizing a report


Customizing a table


Events: Making your database objects work together


Example of a crosstab query


Example of grouped records in a report


Example of sorting records in a report


Examples of customized fields in tables


Examples of performing calculations in a query


Forms: What they are and how they work


Getting assistance while you work


How data is represented in a chart


Improving a report's appearance


Join types and how they affect query results


Macros: What they are and how they work


Modules: What they are and how they work


Primary key fields in tables


Queries: What they are and how they work


Reports: What they are and how they work


Sections of a report


Sections of a form


Specifying multiple criteria in a query


Tables: What they are and how they work


Using the Table Analyzer Wizard's query


Views of a form


What are filters and how do they work?


What is a database?


Working in Form view


Working in query Datasheet view


Working in table Datasheet view


What is an expression?

Expressions are a fundamental part of many Microsoft Access operations. An expression is a combination of symbols — identifiers, operators, and values — that produces a result.

For example, you can use the following expression in a control on a form or report to display the sum of the values in the Freight and OrderAmount controls:

= [Freight] + [OrderAmount]

Here are a few common examples of operations where you use expressions:

•	Setting a property that defines a calculated control, establishes a validation rule, or sets a default field value.

•	Entering a criteria expression, creating a calculated field, or updating records in a query or filter.

•	Setting a condition for carrying out an action or series of actions in a macro, or specifying arguments for many actions.

•	Specifying arguments for many functions, statements, and methods in Visual Basic for applications procedures.

•	Editing an SQL query in SQL view of the Query window, or using an SQL statement in a property setting or argument.

For information on creating an expression, click  [image].

To see examples of expressions, click  [image].


Create an expression

When you create an expression, you combine identifiers, values, and operators into a unit that produces a result. Expressions can be as simple as an arithmetic expression, such as (1 + 1), that produces a numeric result, 2. Or they can perform complex operations on data, such as the following validation expression which generates an error if the value of the Country field is France, Italy, or Spain and the PostalCode field contains less than or greater than five characters:

= [Country] In ("France", "Italy", "Spain") And Len(([PostalCode])<>5)

You can create an expression using the Expression Builder, or you can create it on your own by combining the elements of the expression to do what you want.

What do you want to do?

Create an expression using the Expression Builder

Create an expression without using the Expression Builder

Read more about what expressions are

See examples of expressions


Create an expression using the Expression Builder

1	Start the Expression Builder.

How?

2	In the Expression box, type or paste the elements of the expression.

How?

Tip   To undo your most recent action, click Undo.

3	When your expression is complete, click OK.

Microsoft Access copies your expression to the location where you started the Expression Builder. If that location already contains a value, or if you started from the Module window with text selected, your new expression replaces the value or text.


Start the Expression Builder

You can start the Expression Builder from most places where you write expressions, such as in a property sheet, a criteria cell in the query design grid, the Macro window, or the Module window.

What do you want to do?

Start the Expression Builder in a property sheet or the lower pane of the Macro window

Start the Expression Builder in a field or criteria cell in the Query window, in the Condition column of the Macro window, or in the Module window


 Start the Expression Builder in a property sheet or the lower pane of the Macro window

1	Click the property or argument box that will contain the expression.

2	Click the Build button next to the property or argument box.

If a property has more than one builder associated with it, Microsoft Access displays the Choose Builder dialog box. Click Expression Builder and click OK.


Start the Expression Builder in the query grid, a macro condition, or a module

You can start the Expression Builder in a field or criteria cell in the Query window, in the Condition column of the Macro window, or in the Module window.

1	With the right mouse button, click where you want to insert the expression.

2	On the shortcut menu, click Build.

If the property box, argument box, query cell, or Condition column where you start the Expression Builder already contains a value, that value is automatically copied into the Expression box. To copy text from the Module window into the Expression Builder, select the text you want to copy before starting the Expression Builder.


Paste an element of an expression into the Expression box in the Expression Builder

You paste an element of an expression in the Expression Builder by selecting the element in the lower part of the Expression Builder and then double-clicking the element or clicking Paste.

1	In the leftmost box, double-click the folder that contains the type of object or element you want.

2	Click the folder for the object you want.

3	Use the middle and rightmost boxes to select the element you want to paste, and then double-click the element or click Paste.

For example, to paste an identifier that refers to a field in a table, double-click the Tables folder, click the folder for the table that contains the field, and then double-click the field.

Notes

•	If an object or function isn't listed in the lower part of the Expression Builder, it's not valid in the context where you started the builder. For example, you can't refer to other fields and controls in the validation rule for a field in a table, so the Tables, Queries, Forms, and Reports folders aren't available if you start the Expression Builder from the ValidationRule property of a table field.

•	If you paste an element that requires another element that is missing in your expression, the Expression Builder inserts «Expr» in place of the missing element. To insert the missing element, select «Expr» and then type the element or paste it from the lower part of the Expression Builder.

•	When you paste an identifier in your expression, the Expression Builder pastes only the parts of the identifier that are required in context. For example, if you start the Expression Builder from the property sheet of the Customers form, 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 the context of the form, you must include the full identifier: Forms![Customers].Visible.


Create an expression without using the Expression Builder

You create an expression by combining identifiers, operators, and values to produce the result you want. For example, the following expression increases the value displayed in the Freight control on the Orders form by 10 percent:

= Forms![Orders]![Freight] * 1.1

In this expression:

•	Forms![Orders]![Freight] is an identifier that refers to the value of the Freight control on the Orders form.

•	* is the multiplication operator.

•	1.1 is the value by which Microsoft Access multiplies the value of the Freight control.

Depending on the result you want, you can combine identifiers, operators, and values in a variety of ways. You use expressions to combine strings of text, add or multiply numeric values, call functions, refer to objects and their values, and perform many other operations.

Some expressions produce a true or false result. For example, if you enter an expression in the Condition column of a macro, Microsoft Access carries out the specified action only when the expression is true. The following expression is true only if UK is the value displayed in the Country control on the Employees form:

Forms![Employees]![Country] = "UK"

For more information on using identifiers in expressions, click  [image].

For more information on operators, click  [image].

For more information on using values in expressions, click  [image].


Using identifiers in expressions

You use an identifier in an expression to refer to an object or its properties. For example, you can refer to an open form, an open report, a control on an open form or report, or any properties of the form, report, or control. The following identifier refers to the Visible property of a control:

Reports![Invoice]![ShipName].Visible

The full identifier for an object or property shows the relationship between items in the identifier. In this identifier:

•	Reports refers to the collection of open reports in the database. Microsoft Access automatically creates Forms and Reports collections for each database. The Forms collection is made up of all open forms, while the Reports collection is made up of all open reports.

•	[Invoice] refers to the Invoice report in the Reports collection.

•	[ShipName] refers to the ShipName control on the Invoice report.

•	Visible refers to the Visible property of the ShipName control.

It's often a good idea to refer to an object or property using its full identifier. In some cases, a full identifier is required. For example, to refer to a control on a form or report that isn't the current form or report, you must type its full identifier. The following expression displays the sum of the values in the Subtotal and Freight controls on the Orders form in a control on a different form:

= Forms![Orders]![Subtotal] + Forms![Orders]![Freight]

However, in some circumstances you can refer to a control or its properties without specifying a full identifier:

•	If you're referring to a control on the current form or report, you don't have to specify the form or report identifier. For example, to display the sum of the values in the Subtotal and Freight controls in a different control on the same form, set the ControlSource property of the control to:

= [Subtotal] + [Freight]

•	If you're referring to a control on a subform or subreport, you don't have to specify the full identifier for the form or report using the Form or Report property. For example, you can use the following identifier to refer to the Quantity control on the Orders Subform subform:

Forms![Orders]![Orders Subform]![Quantity]

The full identifier for the Quantity control would be:

Forms![Orders]![Orders Subform].Form![Quantity]

Note   If you are using the Expression Builder to refer to a control on a subform, the subform and its parent form must be open. In the Expression Builder, click Forms, and then click Loaded Forms. Click the name of the parent form, then click the name of the subform, and then double-click the name of the control on the subform.

•	In a macro or action argument, you don't have to specify the identifier for the form or report from which the macro is run. For example, if you set an event property on a form to the name of a macro, you can refer to controls on the form in the macro's Condition column or action arguments without specifying the form's identifier.

•	In a Visual Basic for applications procedure, you can use the Me keyword rather than the full identifier to refer to a control on the current form or report. For example, to assign the sum of the values in the Subtotal and Freight controls on a form to the variable OrderTotal in one of the form's event procedures, add the following statement to the event procedure:

OrderTotal = Me![Subtotal] + Me![Freight]

Note   In a Visual Basic procedure, you can refer to an object by enclosing its name in parentheses and quotation marks (" ") instead of using the ! operator. The parentheses syntax is required if you want to use a variable in an identifier. For example, the following identifiers are equivalent:

Forms![Orders]![OrderDate]

Forms("Orders")("OrderDate")

For information on using the ! and . (dot) operators in expressions, click  [image].

For more information on referring to a form, report, subform, or subreport in an expression, click  [image].

For more information on referring to the value of a control or property in an expression, click  [image].


Using values in expressions

You can specify a value in an expression by using a literal value, a constant, a function, or an identifier:

•	A literal value represents a value such as a number, string, or date that Microsoft Access evaluates exactly as written.  "New York," 100, and #1-Jan-94# are examples of literal values. Dates are enclosed in number signs (#), and strings in double quotation marks (").

•	A constant represents a value that doesn't change. True, False, Yes, No, and Null are examples of constants that are defined automatically by Microsoft Access. You can also define your own constants in Visual Basic for applications that you can use in Visual Basic procedures.

•	A function returns a value based on the results of a calculation or other operation. Microsoft Access includes many built-in functions; for example:

•	The Date function returns the current date.

•	The Sum function returns the sum of a set of field values.

•	The DLookup function returns a specific field value.

You can also create your own functions using Visual Basic.

•	An identifier refers to the value of a field, control, or property. For example, the following identifier refers to the value of the DefaultValue property of the OrderDate control on the Orders form:

Forms![Orders]![OrderDate].DefaultValue

You can combine the value of a field, control, or property with a literal string by using the & (concatenation) operator. For example, the following expression combines the literal string "[CategoryID] = " with the value of the CategoryID control on the Products form:

"[CategoryID] = " & Forms![Products]![CategoryID]

In some circumstances — for example, in a domain aggregate function such as DLookup — the value of the field, control, or property must appear in single or double quotation marks. The easiest way to accomplish this is to add a single quotation mark (') to the literal string, and then combine the expression with another literal string made up of a single quotation mark after the field, control, or property value, as follows:

"[CategoryID] = ' " & Forms![Products]![CategoryID] & " ' "

Existing Microsoft Access applications may use the vertical bar operators (| |) in place of an opening and closing combination of double quotation marks (") and & (concatenation) operators, as follows:

"[CategoryID] = '|Forms![Products]![CategoryID]|' "

However, the use of vertical bars is not recommended because they can produce unexpected results in some circumstances.

If you want an expression to produce a string that is enclosed in quotation marks, you can either enclose the nested string in single quotation marks (') or three sets of double quotation marks ("). For example, the following expressions are equivalent:

Forms![Contacts]![City].DefaultValue = " 'Paris' "

Forms![Contacts]![City].DefaultValue = " " "Paris" " "

For more information on constants, click  [image].

For more information on creating your own functions, click  [image].

For more information on using identifiers in expressions, click  [image].


Examples of expressions

You use expressions in many operations in Microsoft Access, including creating calculated controls, query and filter criteria, default values, validation rules, and macro conditions. Often, the easiest way to create an expression is to find an example of an expression that is similar to what you want to create, and then modify it to do what you want.

What examples do you want to see?

Examples of expressions used in calculated controls

Examples of expressions used in queries and filters

Examples of default value expressions

Examples of field validation rule expressions

Examples of macro condition expressions


Using the ! and . (dot) operators in expressions

You use the ! and .(dot) operators in an identifier to indicate the type of item that immediately follows.

The ! operator indicates that what follows is a user-defined item (an element of a collection). For example, use the ! operator to refer to an open form, an open report, or a control on an open form or report.

Identifier	Refers to
Forms![Orders]	The open Orders form
Reports![Invoice]	The open Invoice report
Forms![Orders]![OrderID]	The OrderID control on the open Orders form
The . (dot) operator usually indicates that what follows is an item defined by Microsoft Access. For example, use the . (dot) operator to refer to a property of a form, report, or control.

Note   You can also use the . (dot) operator to refer to a field value in an SQL statement, a Visual Basic for applications method, or a collection. For example, the identifier Forms![Orders].Controls refers to the Controls collection of the Orders form. However, because the Controls collection is the default collection for forms and reports, it's usually not necessary to refer to it explicitly.


Entering an expression in a property sheet, a design grid, or an action argument

If you are entering an expression that is longer than the standard input area in a property sheet, a design grid, or an action argument, you can type the expression in the Zoom box.  To open the Zoom box, press SHIFT+F2 when the focus is where you want to enter the expression.

When you enter an expression in a property sheet, a design grid, or an action argument, Microsoft Access:

•	Recognizes region-specific function names, property names, and list separators for international versions.

•	Inserts certain characters for you when the focus changes. Depending on where you enter the expression, Microsoft Access automatically inserts:

•	Brackets ([ ]) around form, report, field, or control names.

•	Number signs (#) around dates.

•	Quotation marks (" ") around text.

Note   Calculated control expressions are always preceded by an equal sign (=).

Using functions and properties in international versions of Microsoft Access

When you enter a function or property in an expression in most international versions of Microsoft Access:

•	You can type its localized name (in your language) in a property sheet, a design grid, or an action argument.

•	You can use the list separator for your country when you specify more than one argument for a function. You specify the list separator on the Number tab of the Regional Settings Properties dialog box in the Windows Control Panel. For most international versions, the default list separator is a semicolon (;).

However, in Visual Basic for applications code, you must type the English function or property name and use a comma (,) as a list separator.

Entering object names

Brackets ([ ]) around a field, control, or property in an identifier indicate that the element is the name of a table, query, form, report, field, or control.

When you type an object name in an identifier, you surround the name with brackets if it contains a space or a special character, such as an underscore.  If the name doesn't contain a space or a special character, you can type the name without brackets. Microsoft Access inserts brackets automatically (with two exceptions noted below).

For example, you can type the following expression as a setting for the ControlSource property to calculate the sum of the values in the Freight and OrderAmount fields:

= Freight + OrderAmount

Microsoft Access displays the expression as follows:

= [Freight] + [OrderAmount]

Note   In a ValidationRule property setting or in a Criteria cell in the query design grid, Microsoft Access doesn't automatically insert brackets around a name. If you are entering an object name, be sure to type brackets around it. Otherwise, Microsoft Access may assume you are entering text and may insert quotation marks.

Entering date/time values

Number signs (#) around an element of an expression indicate that the element is a date/time value. Microsoft Access automatically evaluates a value surrounded by number signs as a date/time value and lets you type the value in any common date or time format.

You don't have to type number signs around a date/time value in a validation expression or a criteria expression for a field whose data type is Date/Time. You can type the value in any common date or time format and Microsoft Access automatically inserts number signs around the value.

Microsoft Access displays the value according to the settings in the Regional Settings Properties dialog box in the Windows Control Panel. You can change the output format of a date by using the Format property.

Entering text

Double quotation marks (" ") around an element of an expression indicate that the element is text.

When you type text in a validation or criteria expression, you surround the text with double quotation marks if it contains a space or punctuation. If the text doesn't contain a space or punctuation, you can type the text without double quotation marks and Microsoft Access will insert them automatically.

For example, if you type the following expression:

Paris

Microsoft Access displays the expression as follows:

"Paris"


Refer to a form, report, subform, or subreport in an expression

You refer to an open form or report, or the subform or subreport of an open form or report, in an expression by typing its identifier.

To refer to an open form or report

•	Type the name of the Forms or Reports collection, followed by the ! operator and the name of the form or report. For example, the following identifier refers to the Orders form:

Forms![Orders]

To refer to a subform or subreport

Refer to the subform or subreport control on the form or report that contains the subform or subreport, then use the Form or Report property of the control to refer to the actual subform or subreport.

•	Type the identifier for the form that contains the subform, followed by the name of its subform control, the . (dot) operator, and the Form property. For example, the following identifier refers to the Orders Subform subform on the Orders form:

Forms![Orders]![Orders Subform].Form

Tip   You can use the Expression Builder to create an identifier for a form, report, subform, or subreport.

For more information on creating an expression using the Expression Builder, click  [image].

For more information on using identifiers in expressions, click  [image].

For information on referring to the value of a control or property in an expression, click  [image].


Refer to the value of a control or property in an expression

You refer to the value of a control or property in an expression by typing its identifier.

To refer to the value of a control

•	Type the identifier for the form or report that contains the control, followed by the ! operator and the name of the control. For example, the following identifier refers to the value of the OrderID control on the Orders form:

Forms![Orders]![OrderID]

Tip   If you're referring to a control on a subform or subreport, you don't have to specify the full identifier for the form or report using the Form or Report property. For example, you can use the following identifier to refer to the Quantity control on the Orders Subform subform:

Forms![Orders]![Orders Subform]![Quantity]

To refer to the value of a property

•	Type the identifier for the form, report, or control to which the property applies, followed by the . (dot) operator, and the name of the property. For example, the following identifier refers to the DefaultValue property of the OrderDate control on the Orders form:

Forms![Orders]![OrderDate].DefaultValue

Tip   You can use the Expression Builder to create an identifier for a control or property.

For more information on creating an expression using the Expression Builder, click  [image].

For more information on using identifiers in expressions, click  [image].

For more information on using values in expressions, click  [image].

For more information on referring to a form, report, subform, or subreport in an expression, click  [image].


Refer to a form or report section or report group level

•	Type the identifier for the form or report, followed by the . (dot) operator and the name of the section or group level. For example, the following identifier refers to the Detail section on the Orders form:

Forms![Orders].Detail

Note   You can also refer to form or report sections or report group levels by index number using the Section property. For more information on the Section property, click  [image].

For more information on using identifiers in expressions, click  [image].


Refer to a column in a list

You can refer to a column in a multiple-column list box or combo box by using the Column property of the list box or combo box control.

•	Type the identifier for the Column property, followed by the index number of the column in parentheses. Use 0 to refer to the first column, 1 to refer to the second column, and so on. For example, the following identifier refers to the second column of the Country list box control on the Customers form:

Forms![Customers]![Country].Column(1)

For more information on creating a multiple-column list box or combo box, click  [image].

For information on referring to the value of a control or property in an expression, click  [image].


Guidelines for naming fields, controls, and objects

Names of fields, controls, and objects in Microsoft Access:

•	Can be up to 64 characters long.

•	Can include any combination of letters, numbers, spaces, and special characters except a period (.), an exclamation point (!), an accent grave (`), and brackets ([ ]).

•	Can't begin with leading spaces.

•	Can't include control characters (ASCII values 0 through 31).

Although you can include spaces in field, control, and object names, most examples in the Microsoft Access documentation show field and control names without spaces because spaces in names can produce naming conflicts in Visual Basic in some circumstances.

When you name a field, control, or object, it's a good idea to make sure the name doesn't duplicate the name of a property or other element used by Microsoft Access; otherwise, your database can produce unexpected behavior in some circumstances. For example, if you refer to the value of a field called Name in a table NameInfo using the syntax NameInfo.Name, Microsoft Access displays the value of the table's Name property rather than the value of the Name field.

Another way to avoid unexpected results is to always use the ! operator instead of the . (dot) operator to refer to the value of a field, control, or object. For example, the following identifier explicitly refers to the value of the Name field rather than the Name property:

[NameInfo]![Name]

For more information on using the ! and . (dot) operators in expressions, click  [image].


Guidelines for naming Visual Basic procedures, variables, and constants

Names of procedures, variables, and constants in your Visual Basic for applications code:

•	Can be up to approximately 200 characters long.

•	Must begin with a letter.

•	Can include letters, numbers, or underscore characters (_).

•	Can't include punctuation characters or spaces.

•	Can't include Visual Basic keywords.

A keyword is a word that Visual Basic uses as part of its language. This includes predefined statements (such as If and Loop), functions (such as Len and Abs), and operators (such as Or and Mod).


Troubleshoot expressions

What do you need help with?

I don't understand how expressions work. Please give me an overview.

The criteria argument in a DLookup or other domain aggregate function produces unexpected results.

I'm seeing unexpected results when I try to combine (concatenate) control or field values, variables, or text in an expression.

I'm seeing unexpected results when I try to perform operations on fields that have blank values.

I'm seeing unexpected results when I enter a date value in an expression.

I'm seeing unexpected results when I try to refer to a subform or subreport property or control.

I'm seeing unexpected results when I try to refer to a column in a list box or combo box.

How do I convert text so that the first letter is capitalized and the rest is lowercase?


I'm seeing unexpected results when I try to combine (concatenate) control or field values, variables, or text in an expression.

Concatenating control or field values or text in an expression may produce unexpected results for any of the following reasons:

•	You're referring to a control or field that has the same name as the current control, creating a circular reference. Change the name of the field or control.

•	You're referring to a control or field using a name that is misspelled or typed incorrectly. Verify that it's entered correctly.

•	You're referring to a control or field that has the same name as a property. Use the full identifier for the control or field. For more information about identifiers in expressions, click  [image].

•	Microsoft Access isn't evaluating the expression correctly because part of the expression must be surrounded by brackets( [ ) or single (') or double quotation (") marks. Check to see whether bracket or quotation mark characters are required.

For more information about concatenating values in text expressions, click  [image].


I'm seeing unexpected results when I try to perform operations on fields that have blank values.

Many operations may produce unexpected results if they use an expression that refers to a field that has blank (Null) values. For example, the DCount or DSum functions may produce unexpected results if they use criteria expressions that refer to a field with Null values.

To correct this problem, you can either:

•	Pass field values to the Nz function in the expression. When the Nz function evaluates a Null value, it returns zero or a zero-length string. For more information about the Nz function, click  [image].

•	Use the IIf and IsNull function to test whether a value is Null, and then return an appropriate value. For more information about the IIf function, click  [image]. For more information about the IsNull function, click  [image].

For more information about setting field properties that determine how blank fields are handled, click  [image].


I'm seeing unexpected results when I enter a date value in an expression.

Microsoft Access can produce unexpected results if you enter a date value in an expression without surrounding it with number signs (#). For more information about entering expressions, click  [image].


I'm seeing unexpected results when I try to refer to a subform or subreport property or control.

Microsoft Access can produce unexpected results if you refer to a subform or subreport property or control using an incorrect identifier.

To refer to a subform or subreport property, you must type a full identifier for the form or report using the Form or Report property of a subform or subreport control. For example, the following identifier refers to the Visible property of the Orders Subform subform:

Forms![Orders]![OrdersSubformControl].Form.Visible

In this example:

•	Forms![Orders]![OrdersSubformControl] refers to the subform control that contains the subform.

•	Forms![Orders]![OrdersSubformControl].Form refers to the subform itself. You must specify the Form property to refer to the subform itself or one of its properties.

In contrast, to refer to a control on a subform or subreport, or one of the control's properties, you don't have to use the Form or Report property. For example, the following identifier refers to the Visible property of the Discount control on the Orders Subform subform:

Forms![Orders]![OrdersSubformControl]![Discount].Visible

For more information about referring to a form, report, subform, or subreport in an expression, click  [image].

For more information about referring to the value of a control or property in an expression, click  [image].

For more information about identifiers in expressions, click  [image].


I'm seeing unexpected results when I try to refer to a column in a list box or combo box.
I'm seeing unexpected results when I try to refer to a column in a list box or combo box

You use the Column property to refer to a column in a list box or combo box. The Column property may produce unexpected results for any of the following reasons:

•	You haven't supplied an index number to the Column property. The index number identifies the column you're referring to. For example, Column(0) refers to the first column in a list box or combo box.

•	You've specified an index number for the wrong column. Remember that index numbers for the Column property start at zero. Column(0) refers to the first column, Column(1) refers to the second column, and so on.

•	You're performing a numeric calculation directly on the value returned by the Column property. Because the Column property returns a text value, you must convert it to a numeric value before performing a numeric calculation. For example, the following expression uses the CCur function to convert the value returned by the Column property to a currency value before multiplying it by the value of the Quantity field:

[Quantity] * CCur([PriceListBox].Column(1))

For more information about referring to a column in a list, click  [image].


How do I convert text so that the first letter is capitalized and the rest is lowercase?

You can convert text so that the first letter is capitalized and the rest is lowercase by using the Proper function. The Proper function is a sample Function procedure included with the Orders sample database.

To use the Proper function in your database, open the Orders sample database, copy the function from the UtilityFunctions module, and then paste the function in a module in your database.

For information about opening the Orders sample database, click  [image].


What's new with filters?

Microsoft Access for Windows 95 makes filtering even easier with the following new ways to filter records:

•	With Filter By Selection, you can specify which set of records you want to work with by selecting (highlighting) directly in the form or datasheet the value you're searching for, and then clicking  [image]  on the toolbar. Once you've narrowed the focus to a specific set of records, you can narrow it even further by selecting another value from within the subset of records.

•	With Filter By Form, you can specify which set of records you want to work with by switching to a view of your form or datasheet with blank fields (instead of data) into which you can specify the value or values you're searching for. You specify a value you're searching for by typing it or picking it from a list in the field.

After creating a filter using one of these methods, you can save the filter as a query if you want, bypassing the query design grid altogether. For examples of these filtering methods, click  [image].

Note   You can still create advanced filters in the Advanced Filter/Sort window using the design grid, formerly called the Query By Example (QBE) grid.

In addition, you can now do the following with filters:

•	Filter records in the Datasheet view of a table or query.

•	Base a new form or report on filtered data. After applying a filter to a table or query, you can display just the filtered records in a form or report. For example, you can quickly create mailing labels from the filtered records by clicking the arrow next to the New Object button on the toolbar, clicking New Report, and then selecting Mailing Label.

•	Save a filter with a table, query, or form. Previously you had to save a filter as a query to reuse it at a later time. If you base a new form or report on a closed table or query that has a filter saved with it, the form or report will inherit the filter, which you can then apply as needed.

Note   A saved filter doesn't become a separate object in the Database window.

•	Save a sort order you've applied to the filtered records in a table, query, or form. If you sort the records in ascending or descending order, Microsoft Access saves the sort order when you save the object and its filter. If you base a new form or report on the filtered and sorted data, the records in the form or report will be sorted automatically. You can remove the sort order or reapply it as needed.

Note   If you sort the records in a table, query, or form that doesn't have a filter, Microsoft Access still saves the sort order. If you base a new form or report on a table or query in this case, the form or report inherits the sort order and applies it automatically.

•	Apply, remove, or change a filter and sort order that a report inherits by setting the new Filter, FilterOn, OrderBy, and OrderByOn properties. For more information on these properties and how they are affected by the Sorting And Grouping dialog box in the report, click  [image].

•	Apply a filter to a subform. The filter limits records in the subform without limiting records in the main form.

•	Apply a filter automatically when a form is first opened by specifying a macro using the ApplyFilter action or an event procedure using the ApplyFilter method of the DoCmd object as the OnOpen property setting of the form. You can also apply a filter using the OpenForm or OpenReport action, or their corresponding methods. To apply a filter automatically when a table is first opened, open the table using a macro containing the OpenTable action, immediately followed by an ApplyFilter action.

•	Affect what happens on a form in response to someone creating or applying a filter. This is possible using the new OnFilter event and OnApplyFilter event.

•	Create a custom Filter By Form or add or modify expressions entered into a Filter By Form window using the BuildCriteria method in code. For example, you could use the BuildCriteria method to add criteria in addition to any criteria specified in the Filter By Form window.


Switch between filter windows in a table, query, or form

You can switch between windows to create or modify a filter using the method that works best for your filtering needs, or to see a different view of an existing filter. Filter By Form and Advanced Filter/Sort have their own windows. However, you use Filter By Selection directly in Form or Datasheet view.

To switch to  this window	From this window	Do this
Filter By Form	Datasheet view or Form view	Click  [image]  on the toolbar.
	Advanced Filter/Sort	On the Filter menu, click Filter By Form.
Advanced  Filter/Sort	Datasheet view or Form view	On the Records menu, point to Filter, and then click Advanced Filter/Sort.
	Filter By Form	On the Filter menu, click Advanced Filter/Sort.
To apply a filter from either Filter By Form or the Advanced Filter/Sort window and see the results in Datasheet view or Form view, click  [image]  on the toolbar. To close either filter window and return to Datasheet view or Form view without applying the filter, click  [image]  on the toolbar.

Note   After specifying the values you're searching for using either Filter By Selection or Filter By Form, you can switch to the Advanced Filter/Sort window to see how the values you specified are translated into a criteria expression in the design grid.


Similarities and differences between select queries and filters

The basic similarity between select queries and filters is that they both find and retrieve a subset of records from the underlying table or query. How you want to use the records that are returned determines whether you use a filter or a query.

Generally, use a filter to temporarily view or edit a subset of records while you're in a form or datasheet. Use a query if you want to do any or all of the following:

•	View the subset of records without first opening a specific table or form.

•	Choose the tables containing the records you want to work with and add more tables at a later date if necessary.

•	Control which fields from the subset of records display in the results.

•	Perform calculations on values in fields.

Note   Even if you determine you need a query, consider taking advantage of the easy Filter By Form or Filter By Selection techniques for creating a filter, and then saving the filter as a query. This enables you to bypass the query's design grid altogether (unless you want to make additional changes to the query). Even so, when you open the query in Design view, you'll see how Microsoft Access filled in the design grid using the information from the filter. You can then use this information as a guide for making additional changes.

The following table identifies the similarities and differences between queries and filters.

Characteristics	Filters	Queries
Enable you to add more tables if you want to include their records in the subset that's returned	No	Yes
Enable you to specify which fields, from the subset of records, that you want to display in the results	No	Yes
Appear as a separate object in the Database window	No	Yes
Can only be used on an open table, query, or form	Yes	No
Produce results that can be used as the source of data for a form or report	Yes	Yes
Can calculate sums, averages, counts, and other types of totals	No	Yes
Can sort records	Yes	Yes
Save the sort order for future working sessions	Yes	Yes
Enable you to edit data if editing is otherwise allowed	Yes	Yes, depending on the type of query. You can also perform bulk updates with an update query.


Find data

There are many ways in Microsoft Access to find just the data you need, whether you're looking for a particular value, one record, or a group of records.

•	With the Find dialog box, you can locate specific records or find certain values within fields. You can navigate through records as Microsoft Access finds each occurrence of the item you're looking for. If you want to replace certain values that you find, use the Replace dialog box instead.

•	With filters, you can temporarily isolate and view a specific set of records to work with while you have a form or datasheet displayed.

•	With queries, you can work with a specific set of records that meet criteria you specify from one or more tables in the database. You can work with this subset independent of a specific form or datasheet by running the query.

Which method do you want to use to find data?

Find dialog box

Replace dialog box

Filter

Query


Using wildcard characters as placeholders when searching for values

You use wildcard characters as placeholders for other characters when you are specifying a value you want to find and you:

•	Know only part of the value; or you

•	Want to find values that start with a specific letter or match a certain pattern.

You can use the following characters in the Find and Replace dialog boxes, or in queries, commands, and expressions, to find such things as field values, records, or filenames.

Character	Usage	Example
*	Matches any number of characters. It can be used as the first or last character in the character string.	wh* finds what, white, and why
?	Matches any single alphabetic character.	B?ll finds ball, bell, and bill
[ ]	Matches any single character within the brackets.	B[ae]ll finds ball and bell but not bill
!	Matches any character not in the brackets.	b[!ae]ll finds bill and bull but not bell
-	Matches any one of a range of characters. You must specify the range in ascending order (A to Z, not Z to A).	b[a-c]d finds bad, bbd, and bcd
#	Matches any single numeric character.	1#3 finds 103, 113, 123
Notes

•	Wildcard characters are meant to be used with text data types, although you can sometimes use them successfully with other data types, such as dates, if you don't change the Regional Settings properties for these data types.

•	When using wildcard characters to search for an asterisk (*), question mark (?), number sign (#), opening bracket ( [ ), or hyphen (-), you must enclose the item you're searching for in brackets. For example, to search for a question mark, enter [?] in the Find dialog box. If you're searching for a hyphen and other characters simultaneously, place the hyphen before or after all the other characters inside the brackets. (However, if you have the exclamation point after the opening bracket, place the hyphen after the exclamation point.) If you're searching for an ! or closing bracket ( ] ), you don't need to enclose them in brackets.

•	You can't search for the opening and closing brackets ([ ]) together because Microsoft Access interprets this combination as a zero-length string.

•	If you're searching for values in a table other than a Microsoft Access table, such as a SQL Server table, you may need to use different wildcard characters. Check the documentation for that data source for more information.


Find specific occurrences of a value in a field

You can find all occurrences of a specified value at once, or each occurrence one at a time. For information on finding null values and zero-length strings, click  [image].

1	In Form or Datasheet view, select the field (column) you want to search, unless you want to search all fields. (Searching a single field is faster than searching the entire table.)

2	Click  [image]  on the toolbar.

3	In the Find What box, type the value you want to find.

If you don't know the exact value you want to find, you can use wildcard characters in the Find What box to specify what you're looking for. For examples of wildcard characters and how to use them, click  [image].

4	Set any other options you want to use in the Find dialog box.

5	To find the first occurrence of the value, click Find First. To find the next occurrence of the value and all subsequent occurrences, continue clicking Find Next.


Replace specific occurrences of a value in a field

You can replace all occurrences of the specified value at once or each occurrence one at a time. If you want to find null values and zero-length strings, however, you must use the Find dialog box to find these occurrences, and then replace them manually. For more information, click  [image].

1	In Form or Datasheet view, select the field (column) you want to search, unless you want to search all fields. (Searching a single field is faster than searching the entire table.)

2	On the Edit menu, click Replace.

3	In the Find What box, type the value you want to find; in the Replace With box, type the value you want to replace it with.

If you don't know the exact value you want to find, you can use wildcard characters in the Find What box to specify what you're looking for. For examples of wildcard characters and how to use them, click  [image].

4	Set any other options you want to use in the Replace dialog box.

5	To replace all occurrences of the specified value at once, click Replace All.

To replace each occurrence one at a time, click Find Next, and then click Replace; to skip an occurrence and find the next one, click Find Next.

Note   You can replace large amounts of data more quickly or perform calculations on data (such as raising all salaries in an Employee table by 5 percent) using an update query instead of the Replace dialog box. However, you can't confirm individual replacements when using an update query and an update query isn't as convenient when you want to search for and replace data in more than one field.


Optimizing find and replace performance

For the fastest searches, search for whole field values or the first character within a single indexed field. If you search the same nonindexed field repeatedly, index the field.

How?


Find blank fields or zero-length strings using the Find dialog box

1	In Form or Datasheet view, click in the field (column) you want to search, and then click  [image]  on the toolbar.

2	Do one of the following:

•	To find unformatted blank fields, in the Find What box, type Null or Is Null, and make sure that the Search Fields As Formatted check box is not selected. If blank fields are formatted (such as "Unknown"), type the formatted string, and make sure that the Search Fields As Formatted check box is selected.

•	To find zero-length strings, in the Find What box, type double quotation marks (" "), with no spaces in between, and make sure that the Search Fields As Formatted check box is not selected.

3	In the Search box, click Up or Down.

4	In the Match box, make sure that Whole Field is selected.

5	Make sure that Search Only Current Field is selected.

6	To find the first occurrence of a blank in a field, click Find First. To find the next and all subsequent occurrences of a blank, continue clicking Find Next.


How a filter for a table or query affects new forms or reports

When you save a table, query, or form, Microsoft Access saves any filter currently defined in the object whether or not the filter is applied. It also saves any sort order that you've specified for the records in that object.

If you create a form or report based on a closed table or query that has a filter or sort order saved with it, the form or report uses the table or query as its record source, inheriting that object's filter and sort order. The filter won't be applied in the new form or report. You apply it when you need it. The sort order is automatically applied; however, you can remove or change it as necessary without affecting the underlying table or query.

If you create a form or report directly from filtered data while the data is displayed, the form or report uses the table or query as its record source, inheriting that object's filter and sort order, as in the previous situation. It also applies the sort order automatically in the new form or report. However, in this case the filter is applied automatically each time you view the report, but it is applied only the first time you view the form after creating it. (The next time you open the form, you'll apply the filter yourself.)

In a form, you can work with an inherited filter using Filter By Selection, Filter By Form, or the Advanced Filter/Sort window. You apply the sort order using  [image]  or  [image]  on the toolbar or the Sort cell in the Advanced Filter/Sort window. You remove the sort order using the Remove Filter/Sort command on the Records menu or the Sort cell in the Advanced Filter/Sort window.

In a report, the filtering and sorting features that the form has aren't available. Therefore, to apply or remove a filter and sort order that a report inherits, or to change a filter, you change the settings for the new properties listed in the following table.

This property	Does this
Filter	Stores the SQL string's WHERE clause, which defines the records the filter displays. (WHERE does not appear in the property setting.)
FilterOn	Applies or removes the filter defined in the Filter property.
OrderBy	Identifies the field or fields that are used for sorting, and the sort order (ascending or descending).
OrderByOn	Applies or removes the sort order defined in the OrderBy property.
(The RecordSource property stores the name of the underlying table or query.)

Notes

•	If you specify a sort order in a report wizard or in the Sorting And Grouping dialog box in report Design view, it overrides any sort order the report inherited from the underlying object.

•	You can have Microsoft Access apply a filter automatically when you open a form by specifying a macro using the ApplyFilter action or an event procedure using the ApplyFilter method of the DoCmd object as the OnOpen property setting of the form. You can also apply a filter using the OpenForm or OpenReport action, or their corresponding methods.


Apply an inherited filter in a report

If you create a report based on a table or query that had a filter saved with it, the report uses the table or query as its record source, inheriting that object's filter. You can apply the filter by setting the FilterOn property to Yes in the report's property sheet.

1	In report Design view, click  [image]  on the toolbar to display the property sheet.

2	Click in the FilterOn property box, and then click Yes.

Notes

•	If you create a report directly from filtered data, the filter is automatically applied in the new report.

•	You can remove a filter in a report by setting the FilterOn property to No.

•	You can have Microsoft Access apply a filter automatically when you open a report by attaching a macro using the ApplyFilter action or an event procedure using the ApplyFilter method of the DoCmd object to the report's Open event. You can also automatically apply a filter to a report using the OpenReport action, or its corresponding method.


 Remove an inherited filter from a report

If you create a report directly from filtered data, the report uses as its record source the table or query in which the filter was created, and it inherits the current filter. The filter is applied automatically in the report; however, you can remove the filter by setting the FilterOn property to No in the property sheet.

1	In report Design view, click  [image]  on the toolbar to display the property sheet.

2	Click in the FilterOn property box, and then click No.

Notes

•	If you base a report on an object that has a filter saved with it, the report inherits the filter, but the filter isn't automatically applied.

•	You can reapply a filter by setting the FilterOn property to Yes.

•	You can have Microsoft Access remove a filter automatically using the ShowAllRecords action or the ShowAllRecords method of the DoCmd object.


Modifying an inherited filter in a report
Modifying an inherited filter or sort order in a report

If you create a report directly from filtered and sorted data, or if you base the report on a closed object that had a filter or sort order saved with it, the report inherits the filter and sort order. To edit an inherited filter, you modify the SQL WHERE clause in the report's Filter property. If you don't know SQL, you can modify the WHERE clause by changing the filter in the underlying table or query, switching to Design view and displaying the property sheet for the table or query, and then copying the revised WHERE clause from its Filter property to the Filter property for the report.

To edit the sort order, you modify the SQL OrderBy clause in the report's OrderBy property. (Or specify a sort order in the Sorting And Grouping dialog box in report Design view, which overrides the setting in the OrderBy property.)


Remove an inherited sort order from a report

If you create a report based on a closed table or query that had a sort order saved with it, or if you create a report directly from filtered data that has a sort order in effect, the report inherits the sort order and applies it automatically. You can remove the sort order by setting the OrderByOn property to No in the property sheet.

1	In report Design view, click  [image]  on the toolbar to display the property sheet.

2	Click in the OrderByOn property box, and then click No.

Notes

•	You can reapply the sort order by setting the OrderByOn property to Yes.

•	If you specify a sort order in a report wizard or in the Sorting And Grouping dialog box in report Design view, it overrides the inherited sort order.


Apply an inherited sort order in a report

If you create a report based on a closed table or query that had a sort order saved with it, or if you create a report directly from filtered data that has a sort order in effect, the report inherits the sort order and applies it automatically. If you remove the sort order and then want to reapply it, set the OrderByOn property to Yes in the report's property sheet.

1	In report Design view, click  [image]  on the toolbar to display the property sheet.

2	Click in the OrderByOn property box, and then click Yes.

Note   If you specify a sort order in a report wizard or in the Sorting And Grouping dialog box in report Design view, it overrides the inherited sort order.


Change an inherited sort order in a report

If you create a report based on a table or query that had a sort order saved with it, or if you create a report directly from filtered data that has a sort order in effect, the report inherits the sort order and applies it automatically. You can change the sort order by setting the OrderBy property in the report's property sheet to a different setting.

1	In report Design view, click  [image]  on the toolbar to display the property sheet.

2	Click the OrderBy property box, and then specify the field and sort order you want to sort on.

•	To sort records in one field in ascending order, type the field name enclosed in brackets ([ ]) followed by ASC.

[fieldname1] ASC

•	To sort records in one field in descending order, type the field name enclosed in brackets ([ ]) followed by DESC.

[fieldname1] DESC

•	To sort records in more than one field in ascending or descending order, type the setting this way:

[fieldname1] ASC,
[fieldname2] DESC

Note   If you don't specify ASC or DESC after field names, Microsoft Access sorts the first listed field in ascending order, then the next listed field in ascending order, and so on.


Optimize performance in the Filter By Form window

If the lists in fields in the Filter By Form window take too long to display or they aren't displaying values from the underlying table, you can change Filter By Form performance for all tables, queries, and forms by setting filtering options, or change performance for a specific form by changing the setting of the FilterLookup property for text box controls on the form. By changing the options or property setting, you can prevent the lists from displaying the underlying table's field values, display field values on the list for certain types of indexed or nonindexed fields only, or change the record limit that determines if the list displays a field's values.

What do you want to do?

Optimize performance in the Filter By Form window for all tables, queries, and forms in the database

Optimize performance in the Filter By Form window for a specific form


Optimize Filter By Form performance for all tables, queries, and forms

1	On the Tools menu, click Options.

2	Click the Edit/Find tab, and then set the Filter By Form Defaults according to the performance you want to achieve.

•	If the list of values takes too long to display in nonindexed fields only, try limiting the lists to indexed fields. You can do this by clearing the check box for Local Nonindexed Fields and ODBC Fields. If the lists take too long to display in indexed fields, clear the Local Indexed Fields check box as well since there are too many records in the indexes for the lists to display quickly.

Note   If you use the same nonindexed field repeatedly to filter records, consider indexing it to improve filtering and other search operations on the field. For more information, click  [image].

•	If lists aren't displaying the values from indexed or nonindexed fields, check under Show List Of Values In to make sure the appropriate boxes are selected, or try increasing the number in the box Don't Display Lists Where More Than This Number Of Records Read so that it's greater than or equal to the maximum number of records in any nonindexed field in the underlying table.

Note   For information on how Microsoft Access reads records differently in indexed fields than in nonindexed fields and how this difference relates to the Don't Display Lists Where More Than This Number Of Records Read box, click  [image].


Optimize Filter by Form performance for a specific form

For each text box control on a form, you can specify whether the values stored in the field appear on its list in the Filter By Form window.

1	In form Design view, display the property sheet for any text box control.

2	Click in the FilterLookup property box, and then set the property to the setting that will achieve the performance you want.

•	If the list takes too long to display in the Filter By Form window, either set the FilterLookup property to Never, or set it to Database Default and then display the Options dialog to clear the option that applies to that type of field. For example, if the field is indexed, clear the Local Indexed Fields and ODBC Fields options. (To display the Options dialog box, click Options on the Tools menu, and then click the Edit/Find tab. Note that changes in this dialog box affect Filter By Form performance in all tables, queries, and forms, not just the current form.)

Tip  If you use the same nonindexed field repeatedly to filter records, consider indexing it to improve filtering and other search operations on the field. For more information, click  [image].

•	If the list in the Filter By Form window isn't displaying the values stored in that field, make sure the FilterLookup property isn't set to Never. If the FilterLookup property is set to Database Default, display the Options dialog box, and verify that the appropriate box under Show List Of Values In is checked. (For example, if the control is for an indexed field, make sure Local Indexed Fields is checked.) If it is, or if the FilterLookup property is set to Always, try increasing the number in the Don't Display Lists Where More Than This Number Of Records Read box so that it's greater than or equal to the maximum number of records in any nonindexed field in the underlying table.

Notes   For information on how Microsoft Access reads records differently in indexed fields than in nonindexed fields and how this difference relates to the Don't Display Lists Where More Than This Number Of Records Read box, click  [image].


Clear the design grid in query Design view or the Advanced Filter/Sort window

•	On the Edit menu, click Clear Grid.


Filter records by entering values in a blank view of your form or datasheet

1	In Datasheet or Form view, click  [image]  on the toolbar to switch to the Filter By Form window.

2	Click the field in which you want to specify the criteria that records must meet to be included in the filtered set of records.

3	Enter your criteria by selecting the value you're searching for from the list in the field (if the list includes field values), or by typing the value into the field.

•	To find records in which a check box, toggle button, or option button is or is not selected, click the check box or button until it's the way you want. To return it to a neutral position so that it won't be used as criteria for filtering records, continue clicking the check box or button until it's grayed.

•	To find records in which a particular field is empty or not empty, type Is Null or Is Not Null into the field. (You can select these options from the list in fields with a Memo or OLE Object data type, and in calculated fields in queries.)

•	To find records using a criteria expression, type the expression into the appropriate field or enter one using the Expression Builder. For more information on expressions, click  [image].

If you specify values in more than one field, the filter returns records only if they contain the same values you specified in each of those fields.

4	To specify alternative values that records can have to be included in the filters results, click the Or tab at the bottom of the window.

The filter returns records if they have all the values specified on the Look For tab or all the values specified on the first Or tab or all the values specified on the second Or tab, and so on.

5	Click  [image]  on the toolbar.

Notes

•	When you save the table, query, or form, Microsoft Access saves the filter.

•	For information on how to see your filter defined in the Advanced Filter/Sort window, click  [image]. The values specified on each Or tab are shown in one criteria row in the design grid in the Advanced Filter/Sort window.

•	For information on creating a form or report based on the filtered data, click  [image].


 Modify a filter in the Advanced Filter/Sort window in a table, query, or form

While you're working in the Advanced Filter/Sort window, you can modify the filter's design and change the design grid.

What do you want to do in the design grid?

Add a field

Insert a field between other fields

Move a field

Add a column

Remove a field or column

Change column widths

Insert or delete a criteria row

Enter criteria

Specify a sort order for the filtered records

Clear the design grid


Apply an existing query as a filter on a form, subform, or datasheet

While you can save only one filter with a table, query, or form, you can use queries that you've already created as additional filters. A query must meet certain requirements if you're going to use it as a filter. For more information on those requirements, click  [image].

1	Switch to the Filter By Form window or the Advanced Filter/Sort window.

How?

2	On the toolbar, click

3	Select a query, and then click OK.

4	Click  [image]  on the toolbar.

Note   For information on creating a form or report based on the filtered data, click  [image].


Requirements for using queries as filters

A query must meet certain requirements if you're going to use it as a filter. The query:

•	Must be based on the same underlying table or query as the datasheet or form to which you're applying it.

•	Can't include other tables or queries.

•	Must be a select query (not a crosstab query or action query).

•	Can't include fields that sum, count, or calculate another type of total for the values in a field.


Filter records using the Advanced Filter/Sort window in a table, query, or form

1	In Datasheet or Form view, on the Records menu, point to Filter, and then click Advanced Filter/Sort.

2	Add to the design grid the field or fields you'll need to specify the values or other criteria the filter will use to find records.

How?

3	To specify a sort order, click in the Sort cell for a field, click the arrow, and select a sort order.

Microsoft Access first sorts the leftmost field in the design grid, then it sorts the next field to the right, and so on.

4	Enter the value you're looking for or enter an expression in the Criteria cell for the fields you have included.

For more information on entering criteria, click  [image].

5	Apply the filter by clicking  [image]  on the toolbar.

Notes

•	When you save the table, query, or form, Microsoft Access saves the filter.

•	For information on creating a form or report based on the filtered data, click  [image].

•	Instead of creating a filter from scratch, you can use an existing query as a filter. For more information, click  [image].


Filter records by selecting values in a form, subform, or datasheet

Use this method to create a new filter or further limit records returned from a filter you originally created in the Filter By Form window or the Advanced Filter/Sort window.

1	In a field on a form, subform, or datasheet, find one instance of the value you want records to contain to be included in the filter's results.

2	Select the value, and then click  [image]  on the toolbar. How you select the value determines what records the filter returns. For more information on selecting values, click  [image].

3	To further limit the set of records, select another value, and then click  [image]  again.

Repeat steps 2 and 3 until you have the set of records you want.

Notes

•	When you save the table, query, or form, Microsoft Access saves the filter.

•	You can also filter for records that do not have the selected value. After selecting the value, click the right mouse button, and then click Filter Excluding Selection.

•	For information on creating a form or report based on the filtered data, click  [image].


How selecting values for a filter determines what records are returned

You can select all or part of a value in a field. How you select the value determines what records the filter returns.

Selecting	Finds records in which	Example
The entire  contents of a  field (or if you  place the insertion point in a field without selecting anything)	The entire contents of that field matches the selection.	You select the value "Berlin" in the City field. The filter returns all records with "Berlin" as the city.
Part of a value starting with the  first character in  a field	The value in that field  starts with the same characters you selected.	In the CompanyName field containing the value "France Restauration," you select only "Fran." The filter returns all records that have a company name starting with "Fran" (for example, Franchi S.p.A. and Frankenversand).
Part of a value starting after the  first character in  a field	All or part of the value in  that field contains the  same characters you selected.	In the CompanyName field containing the value "Old World Delicatessen," you select the letters "Del." The filter returns all records that have "del" anywhere in the CompanyName field (for example, Ernst Handel, Galería del gastrónomo, and Que Delícia).


Create a filter in a table, query, or form

There are three methods you can use to filter records: Filter By Selection, Filter By Form, and Advanced Filter/Sort. The method you pick depends on the criteria you want the records to meet to be included in the filter's results and how you want to sort records (if at all).

Filter By Selection and Filter By Form are the easiest ways to filter records. If you can easily find and select in the form, subform, or datasheet an instance of the value you want the filtered records to contain, use Filter By Selection; otherwise, use Filter By Form. You can use these filtering methods as an easy, convenient way to create queries, too, simply by saving the filter as a query. For complex filters, use Advanced Filter/Sort.

Note   In a report, you can't create a filter using Filter By Selection, Filter By Form, or the Advanced Filter/Sort window. However, a report (as well as a form) can inherit a filter if you base it on a closed table or query that has a filter saved with it, or if you base the report or form directly on filtered data while the data is displayed. For more information, click  [image].

What do you want to do?

See a comparison of each filtering method for help with deciding which one to use

See an example of how each filtering method works

Filter using Filter By Selection

Filter using Filter By Form

Filter using the Advanced Filter/Sort window


Comparing filtering methods

What do you want the filter to do?	Filter By Selection	Filter By Form	Advanced Filter/Sort
Search for records that meet one  criteria And other criteria.	Yes (but you must specify the criteria one at a time).	Yes (and you can specify the criteria  all at once).	Yes (and you can specify the criteria all at once).
Search for records that meet one  criteria Or other criteria.	No.	Yes.	Yes.
Allow you to enter expressions as criteria.	No.	Yes.	Yes.
Sort records in ascending or descending order.	No. (However, after applying the filter,  you can sort all records by clicking  [image]  or  [image]  on the toolbar.)	No. (However, after applying the filter,  you can sort all records by clicking  [image]  or  [image]  on the toolbar.)	Yes. (You can sort all records in ascending or descending order, or some fields in ascending order and other fields in descending order.)


Modify a filter in a table, query, or form

If a filter isn't giving you the results you need, you can modify it. You modify a filter in the same window you used to create it or in the filter window that works best for the modifications you want to make.

Note   If you just want to further limit the set of records returned from a Filter By Selection, continue to select a value, and then click  [image]  on the toolbar until you have the records you want. For other types of modifications to this filter, use Filter By Form or the Advanced Filter/Sort window instead.

Which window do you want to use to modify a filter?

Filter By Form

Advanced Filter/Sort


Modify a filter in the Filter By Form window in a table, query, or form

You can modify the filter by adding to blank fields other values you want the filtered records to contain, deleting or changing values in a field, or making any of the following modifications.

How do you want to modify the filter?

Clear all the fields in the Filter By Form window

Delete an Or tab at the bottom of the Filter By Form window

Enter an expression


Clear all the fields in the Filter By Form window

•	Click  [image]  on the toolbar.


Delete an Or tab at the bottom of the Filter By Form window

1	Click the Or tab you want to delete.

2	On the Edit menu, click Delete Tab.


Create a query from a filter in a table, query, or form

Instead of designing a query from scratch in query Design view, you can create it automatically by saving an existing filter in a table, query, or form as a query. A query offers more flexibility than a filter. For more information, click  [image].

1	With the filter displayed in the Filter By Form window or the Advanced Filter/Sort window, click  [image]  on the toolbar.

2	Type a name for the query, and then click OK.

The new query appears in the Database window. It automatically includes all the fields from the underlying table because the query's OutputAllFields property is automatically set to Yes, but you can change the query's design if necessary. For more information, click  [image].

Note   You can use the query as a filter, too. You might do this if you already saved one filter with the form or datasheet, and you want to use the query as a second filter.


Remove a filter from a table, query, or form

•	To remove a filter and redisplay the records that were previously in the table, query, or form, click  [image]  on the toolbar in Datasheet view or Form view.

•	To remove a filter and display all the records in the table, query, or form, including those that were added, deleted, or changed since you opened the table, query, or form, click Remove Filter/Sort on the Records menu in Datasheet view or Form view.

Notes

•	Removing a filter doesn't delete it. You can reapply the filter by clicking  [image]  on the toolbar.

•	If you prefer, you can use the ShowAllRecords action in a macro or Visual Basic for applications code to remove the filter.


Display the most current records when a filter is applied in a table, query, or form

If you're working with filtered data in a multiuser (shared) database, you may want to reapply the filter occasionally to view records that have been added, deleted, or changed since you opened the form or datasheet and applied the filter.

•	With the filtered records displayed, click Apply Filter/Sort on the Records menu.


Apply a filter in a table, query, or form

Use the following procedure to apply a filter you just created in the Filter By Form window or Advanced Filter/Sort window, apply a filter that was previously saved with the form or datasheet, or apply a filter that a new form inherited from its underlying table or query.

•	In the form, datasheet, or either filter window, click  [image]  on the toolbar.

Notes

•	You can have Microsoft Access apply a filter automatically when you open a form by attaching a macro using the ApplyFilter action or an event procedure using the ApplyFilter method of the DoCmd object to the Open event of the form.

•	If you create a new filter, it replaces any filter previously saved with the form or datasheet. To apply the previous filter, close the form or datasheet without saving it (unless you've made design or layout changes besides creating a filter), and then reopen the form or datasheet. To apply the filter, click  [image]  on the toolbar. If you made design or layout changes, you'll probably want to save the form and then recreate the previous filter rather than lose the design changes.


Enable or disable filtering records in a form

•	Set the form's AllowFilters property to Yes to enable filtering or to No to disable filtering capabilities in Form view and in form Datasheet view.

Notes

•	When you set the AllowFilters property to No, you disable Filter By Selection, Filter By Form, and Advanced Filter/Sort.

•	For information on setting properties in a form, click  [image].


Create a form or report from filtered records

After you create a new report from filtered records, Microsoft Access will display the filtered records automatically. After you create a new form from filtered records, Microsoft Access will display the filtered records the first time you view them. The next time you open the form, it displays all the records until you apply the filter.

1	With the filtered records displayed, click the arrow next to the New Object button on the toolbar.

•	To use the AutoForm or AutoReport Wizard, click AutoForm or AutoReport.

•	To specify the type of form or report you want to create, click New Form or New Report, and then make your selection.

The new object uses as its record source the table or query in which the filter was created, and it inherits the filter.

2	Complete the design or make any other changes you want to the form or report, and then save it.

3	Continue working in the new form or report, or in the table, query, or form on which you based the new form or report.

Notes

•	The new form or report will use the sort order that was in effect on the filtered data. In a report, you can remove or reapply a sort order by setting the OrderByOn property. Or, you can use the Sorting And Grouping dialog box in report Design view to override any sort order the report inherited from the underlying object. In a form, you remove or reapply a sort order using  [image]  or  [image]  on the toolbar or by specifying a sort order in the Advanced Filter/Sort window.

•	In a report, you remove or reapply the filter by setting the FilterOn property. In a form, you remove or reapply a filter by clicking  [image]  on the toolbar.

•	If you subsequently change the filter in a table or query, it has no effect on a form or report that was based on a filter you created previously in that table or query.


Sort data

Sorting data in a particular order often helps you find information more quickly. This is true whether you're looking at multiple records in a table, query, form, subform, or report, or looking at a list of values in a combo box or list box. In Microsoft Access you can sort data in ascending order (0 to 9, A to Z) or descending order (9 to 0, Z to A) in any of these locations.

What data do you want to sort?

Records in a table, query, form, or subform

Records in a report


Sort records in a table, query, form, or subform

You can sort records on demand in Form view, or in Datasheet view of a table, query, form, or subform, even if a filter is already applied. To sort filtered data automatically, you can specify a sort order in the Advanced Filter/Sort window. To sort a query's results automatically, you can specify a sort order in query Design view.

When you sort records on demand, you can perform simple sorts, which means you can sort all records in ascending or descending order (not both). When you sort records by specifying a sort order in query Design view or in the Advanced Filter/Sort window, you can perform complex sorts. This means you can sort records in ascending order by some fields and in descending order by others. Regardless of the method you use to sort the records, Microsoft Access saves the sort order when you save the form or datasheet, and reapplies it automatically when you reopen the object or base a new form or report on that object.

What do you want to do?

Sort records on demand in Datasheet view or Form view

Automatically sort filtered records by specifying a sort order in the Advanced Filter/Sort window

Automatically sort records that a query retrieves by specifying a sort order in query Design view


Sort records on demand in Form or Datasheet view

You can sort records on demand in Form view of a form or subform, or in Datasheet view of a table, query, form, or subform, even if a filter is already applied.

1	In Form view, select the field you want to use for sorting records.

In Datasheet view, select the column or columns you want to sort.

2	To sort in ascending order, click  [image].

To sort in descending order, click  [image].

Note   In a form, you can sort on only one field at a time; in a datasheet, you can select two or more adjacent columns at the same time, and then sort them. Microsoft Access sorts records starting with the leftmost selected column. When you save the form or datasheet, Microsoft Access saves the sort order.


Remove a sort order from a table, query, or form

•	In Datasheet or Form view, click Remove Filter/Sort on the Records menu. If you specified the sort order in the Advanced Filter/Sort window where you also specified criteria for a filter, you can delete the sort order in the Sort cell in the design grid and still leave the filter's criteria intact.


Troubleshoot filter problems

What do you need help with?

The filter returned the wrong number of records or didn't return any. What happened?

The filter didn't sort the records in the correct order. Why not?

 I can't use an existing query as a filter. Why not?

Why are some of the fields in the Filter By Form window disabled?

Why do some or all of the lists in the Filter By Form window take so long to display?

I don't have lists of values to pick from on one or more of the fields in the Filter By Form window. Why not?

I created a filter on a subform in which the records were synchronized with the main form, but the filter didn't have any affect on the main form. Why not?


 Why isn't the filter returning the correct records in my table, query, or form?

If the filter is returning too many records, the criteria you're using may not be restrictive enough to exclude records you don't want to see. To further limit the records that the filter returns:

•	For Filter By Selection, select another value that you want the records to contain, and then click  [image]  on the toolbar. Repeat these steps until you have just the records you want to see. For Filter By Form, enter a value or expression or pick a value from the list in other fields on the Look For tab. In the Advanced Filter/Sort window, add more fields to the design grid, and then specify criteria for them in the Criteria row.

•	For Filter By Form, delete some of the alternative criteria that records can meet by deleting one or more Or tabs. In the Advanced Filter/Sort window, delete one or more extra rows of criteria (the Or rows) and use expressions with And instead of Or.

If the filter is returning too few records, the criteria you're using may be too restrictive.

•	For Filter By Selection, remove the filter, reselect a value you're looking for, and then click  [image]  on the toolbar. If necessary, repeat these steps until you have the records you want to see. In Filter By Form, delete the value or expression on the Look For or Or tab that's restricting the records you want to see. In the Advanced Filter/Sort window, delete criteria for one or more fields in the design grid.

•	In Filter By Form, add alternative criteria that records can meet on the Or tab at the bottom of the window. In the Advanced Filter/Sort window, add extra Or rows where you can specify alternative criteria.

•	In the Advanced Filter/Sort window, use expressions with Or instead of And.

If the filter is returning the wrong records, make sure you're using the correct field or fields to specify the value you're searching for or to specify other criteria, and make sure you've entered the correct value or criteria. If you're using expressions in the Filter By Form window or Advanced Filter/Sort window, verify you're using the correct operators. If you're specifying multiple criteria in the Advanced Filter/Sort window, verify you've entered it in the correct rows and columns in the design grid.

If the filter won't return records when you're filtering on a form using Filter By Form or the Advanced Filter/Sort window, it may be that the form formats data differently than the underlying table. This means that the criteria you specified may not match the actual value in the underlying table. For example, a form may display a date as "January 5, 1995" but the underlying table stores the date as 1-5-95. If you specify "January" in your filter's criteria, it won't find any records because January is stored as "1" in the underlying table.


Why didn't the filter sort the records in the correct order in my table, query, or form?

You may need to:

•	Add or delete a sort order.

•	Sort by a different field.

•	Change the sort order from "Ascending" to "Descending" or vice versa.

•	In the Advanced Filter/Sort window, rearrange the columns in the design grid, and then respecify a sort order on one or more fields. Microsoft Access sorts the records starting with the leftmost column in the grid.

Notes

•	If you have numbers in fields with a Text data type, those numbers will not sort from lowest number to highest or vice versa. Instead, they will sort according to the following convention: 1, 11, 12, 2, 20, 21, and so on.

•	If you have Null values in a field that you're sorting in ascending order, records with those values appear first in the sort order before any records with text or numeric values in the sorted field.

For more information about sorting, click  [image].


Why are some of the fields in the Filter By Form window disabled?

The following types of fields are disabled in the Filter By Form window because you can't use them to filter records:

•	A calculated field in a form.

•	A field created with an unbound control or unbound object frame.


How Microsoft Access reads records in indexed fields differently than in nonindexed fields in the Filter By Form window

How many records Microsoft Access reads depends on whether or not the field is indexed. If the field is indexed, Microsoft Access reads only the unique values, not all the values in a field. If the field isn't indexed, Microsoft Access reads all the values in the field. If the number of records it reads is more than the maximum it's allowed to display, which is determined by the setting for Don't Display Lists Where More Than This Number Of Records Read, Microsoft Access doesn't display the values for that field on the list. Consequently, you need to change the setting to a number greater than (or equal to) the maximum number of records in any nonindexed field in the underlying table.

Note   When Microsoft Access is able to display the list in a field, it only shows the unique values, even for a nonindexed field.


I created a filter on a subform, but the filter didn't have any affect on the main form. Why not?

The filter behaved correctly. When you create a filter on a subform, it only applies to the subform. To filter the records on the main form, click the main form, and then create the filter.


 Create a pop-up form or custom dialog box

You can create a pop-up form to display information to a user or to prompt a user for data. A pop-up form stays on top of other open forms, even when another form is active. A pop-up form can be modeless or modal. When a pop-up form is modeless, you can access other objects and menu commands while the form is open. For example, on an Orders form, you could add a command button that displays a Products pop-up form. The pop-up form displays information about a product in the Orders form. To see an example of this type of form, click  [image].

When a pop-up form is modal, you can't access any other objects or menu commands unless you hide or close the form. A modal pop-up form is called a custom dialog box. For example, you could create a custom dialog box that asks what report you want to print. To see an example of this type of form, click  [image]. To read more about using forms to collect and display information, see Chapter 3, "Using Forms to Collect, Display, and Filter Information," in Building Applications with Microsoft Access for Windows 95

What do you want to do?

Create a modeless pop-up form

Create a custom dialog box

Temporarily open a form as a dialog box

Read about properties that you can use to customize a pop-up form or custom dialog box


Create a modeless pop-up form

1	Create the form. The form can include any combination of controls.

2	In Design view, double-click the form selector to open the property sheet for the form.

3	In the PopUp property box, click Yes.

4	In the BorderStyle property box, click Thin if you don't want the form to be sizable; otherwise, skip to the next step. If you select the Thin setting, you can move the pop-up form, but you can't size it.

5	Create a macro or event procedure that opens the form.

Note   To see an example of an event procedure that displays a modeless pop-up form, click the Build button next to the OnClick property box of the See Product Details button on the Orders form in the Orders sample application.

6	Attach the macro or event procedure to a form or report by specifying the macro name or event procedure as the setting for the appropriate event property. For example, type the name of the macro or event procedure in the OnClick property box of a command button.

Notes

•	To position a pop-up form on the screen, open the form in Design view, maximize the Microsoft Access window, position the form where you want it, and then save the form. The form will appear in this location when it's opened (assuming the AutoCenter property is set to No).

•	For information on other properties you might want to set for a pop-up form, click  [image].


Create a custom dialog box

If you want to use the form as a normal form as well as a dialog box, you can use the Dialog setting of the OpenForm action to open the form temporarily as a dialog box instead of using this procedure. For more information, click  [image].

1	Create the form. The form can have any combination of controls.

2	In Design view, double-click the form selector to open the property sheet for the form.

3	In the PopUp property box, click Yes.

4	In the Modal property box, click Yes.

5	In the BorderStyle property box, click Dialog. If you select the Dialog setting, the form has a thick border and can include only a title bar and a Control menu. The form can't be maximized, minimized, or resized.

6	Create a macro or event procedure that opens the form.

Note   To see an example of an event procedure that opens a custom dialog box, click the Build button next to the OnClick property of the Print Invoice button on the Orders form in the Orders sample application.

7	Attach the macro or event procedure to a form or report by specifying the macro name or event procedure as the setting for the appropriate event property. For example, type the name of the macro or event procedure in the OnClick property box of a command button.

Notes

•	A custom dialog box usually contains one or more command buttons that run macros or event procedures that use the information entered in the dialog box to perform other actions. These buttons are often named OK and Cancel. You can control which button has the focus and which button will work as the Cancel button by setting the Default and Cancel properties for these types of command buttons. For more information on the Default property, click  [image]. For more information on the Cancel property, click  [image].

•	To position a custom dialog box on the screen, open the form in Design view, maximize the Microsoft Access window, position the dialog box where you want it, and then save the form. The dialog box will appear in this location when it's opened (assuming the AutoCenter property is set to No).

•	For information on other properties you might want to set for a custom dialog box, click  [image].

•	For information on creating a custom dialog box that prompts you to enter report criteria, click  [image].


Temporarily open any form as a dialog box

1	Create a macro or event procedure that uses an OpenForm action to open the form.

2	Set the Window Mode argument of the OpenForm action to Dialog (acDIALOG for an event procedure).

When you open a form that has its Window Mode argument set to Dialog, Microsoft Access sets the form's PopUp and Modal properties to Yes until the form is closed. It also disables user-defined key combinations and some other Microsoft Access function keys and suspends the macro or event procedure until you close or hide the form. You can hide a form by setting its Visible property to No using the SetValue action.


Properties that you can use to create or customize pop-up forms and custom dialog boxes
Properties you can use to create or customize pop-up forms and custom dialog boxes

The following table lists properties you can use to create or customize pop-up forms and custom dialog boxes. For more information on any of these properties, click the property in the property sheet and press F1.

This property	Determines
PopUp	Whether a form opens as a pop-up form. A pop-up form always remains on top of other Microsoft Access windows.
Modal	Whether a form opens as a modeless form (you can switch to other windows) or a modal form (the form retains the focus until it's closed).
BorderStyle	The type of border and border elements (title bar, Close button, Control menu, Maximize and Minimize buttons) to use for the form.
ControlBox	Whether a form has a Control menu in Form view.
MinMaxButtons	Whether a form has Minimize and Maximize buttons in Form view. If you set the BorderStyle property to Dialog, Microsoft Access automatically removes the Minimize and Maximize buttons.
CloseButton	Whether the Close button is disabled.
ScrollBars	Whether a form has scroll bars.
NavigationButtons	Whether a form has navigation buttons.
RecordSelectors	Whether a form has record selectors.
ShortcutMenu	Whether a shortcut menu is displayed when you click a form with the right mouse button.
AutoCenter	Whether a form is centered automatically in the application window when the form is opened.
AllowEdits	Whether a user can make any editing changes to saved records in a form.
AllowDeletions	Whether a user can delete records using a form.
AllowAdditions	Whether a user can add records using a form.
DataEntry	Whether a form shows all records or a blank (new) record when it opens.
DefaultView	Whether a form is displayed in Datasheet view, as a single form (one record), or as a continuous form (multiple records).


Specify border and title bar elements for a pop-up form or custom dialog box

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the BorderStyle property box, click one of the following settings:

•	None — the form has no border, no title bar, no Close button, no Control menu, and no Minimize and Maximize buttons. The form cannot be resized. If you set this property, you'll have to add a Close button to the form to close it.

•	Thin — the form has a thin border, a title bar, a Close button, a Control menu (unless the ControlBox property is set to No), and Minimize and Maximize buttons (unless the MinMaxButtons property is set to None). The form cannot be resized. You often use this setting for modeless pop-up forms.

•	Sizable — the form has the default border, a title bar, a Close button, a Control menu (unless the ControlBox property is set to No), and Minimize and Maximize buttons (unless the MinMaxButtons property is set to None). The form can be resized. You use this setting for normal forms.

•	Dialog — the form has a thick (double) border, a title bar, and a Control menu (unless the ControlBox property is set to No). You can't minimize, maximize, or size the form. Use this setting for custom dialog boxes.

Note   For more information on the BorderStyle property, click  [image]. For information on creating pop-up forms and custom dialog boxes, click  [image].


Specify whether a form can be sized

In most cases, you don't want to prevent a form from being resized. Use this procedure for pop-up forms or custom dialog boxes.

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the BorderStyle property box, click None, Thin, or Dialog. To read more about these settings, click  [image].

Note   For information on creating pop-up forms and custom dialog boxes, click  [image].


Remove record selectors from a form

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the RecordSelectors property box, click No.


Remove the shortcut menu from a form

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the ShortcutMenu property box, click No.


Remove the Control menu from a form in Form view

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the ControlBox property box, click No.

Note   If the BorderStyle property for the form is set to None, the form won't have a Control menu even if the ControlBox property is set to Yes.


Remove the Maximize and Minimize buttons from a form in Form view

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the MinMaxButtons property box, click a setting.

Note   If the BorderStyle property for the form is set to None or Dialog, the form won't have Minimize and Maximize buttons even if the MinMaxButtons property is set to Min Enabled, Max Enabled, or Both Enabled.


Remove the navigation buttons from a form

1	Open the form in Design view.

2	Double-click the form selector to open the form's property sheet.

3	In the NavigationButtons property box, click No.


Create custom online Help for a form, report, or control

There are several ways to add online assistance to a Microsoft Access form, report, or control. If you want to display tips that pop up over controls when you move the mouse pointer over the control, you can use the ControlTipText property. Or you might want to use the StatusBarText property to display helpful information about a form or control in the status bar. You can also create tips for new toolbar buttons that you create.

If you want to create more extensive Help, or have Help for a control pop up only when you click  [image]  and then click a control, you can use a text editor or word-processing program to create a Help file (the program must be able to save documents in rich-text format). Then you can compile that Help file with the Windows Help Compiler and attach it to a form, report, or control using the HelpFile and HelpContextID properties.

Note   The Windows Help Compiler is included with the Microsoft Access Developer's Toolkit, Microsoft Visual Basic, Microsoft Visual C++, and the Microsoft Windows Software Development Kit (SDK). To find out more about what's included in the Microsoft Access Developer's Toolkit, click  [image].

What do you want to do?

Create a control tip using the ControlTipText property

Add status bar text for a control or form

Create a tip for a custom toolbar button

Create a compiled Help file that displays Help for a form, report, or control when you press F1

Create topics that are displayed when you click  [image]  on the title bar and then click a form or control

Add the What's This button ( [image]) to a form


Create a compiled Help file that is displayed when you press F1

1	Create the source file using the text editor or word-processing program of your choice. For information on creating the source file, see the online Help that comes with the Windows Help Compiler. Make sure to save the source file in rich-text format.

2	Compile the Help file using the Windows Help Compiler.

3	Display the property sheet for the form or report and specify the filename for the compiled Help file in the HelpFile property box.

Note   For best results, put the Help file in the same directory as your application. That way, you can keep the setting for the HelpFile property the same for each site using your application, but allow users to install the application in the directory of their choice. If you omit a path setting in this property, Microsoft Access looks for the Help file in the directory where your application is installed.

4	In the HelpContextID property box for the form or report, type the number of the topic (a number other than 0) that will be displayed when a user presses F1. This topic would generally cover assistance for the whole form or report.

5	In the HelpContextID property box for any control on a form that can receive the focus, type the number of the topic that will be displayed when a user presses F1. This topic would cover assistance specific to the control.

Notes

•	You must map the values set for the HelpContextID property to the context strings in your Help system. For more information, see the online Help file that comes with the Windows Help Compiler.

•	If a control has the focus when you press F1, but it doesn't have a custom Help topic, the custom Help topic for the form will be displayed. If there is no custom Help topic for the form, Microsoft Access displays the Microsoft Access Help Topics dialog box.


Create What's This tips

1	Create the source file using the text editor or word-processing program of your choice. For information on creating the source file, see the online Help that comes with the Windows Help Compiler.  Make sure to save the source file in rich-text format.

2	Compile the Help file using the Windows Help Compiler.

3	Display the property sheet for the form and specify the filename for the compiled Help file in the HelpFile property box.

Note   For best results, put the Help file in the same directory as your application. That way, you can keep the setting for the HelpFile property the same for each site using your application, but allow users to install the application in the directory of their choice. If you omit a path setting in this property, Microsoft Access looks for the Help file in the directory where your application is installed.

4	In the HelpContextID property box for the form, type a minus sign, and then the number of the topic (a number other than 0) that will be displayed when a user clicks  [image]  and then clicks the background or title bar of the form. This topic would generally cover assistance for the whole form.

5	In the HelpContextID property box for each control on the form that can receive the focus, type a minus sign and then the number of the topic that will be displayed when the user clicks  [image]  and then clicks the control.

Notes

•	You must map the values set for the HelpContextID property to the context strings in your Help system. For more information, see the online Help file that comes with the Windows Help Compiler.

•	If a control doesn't have a custom Help topic, the custom Help topic for the form will be displayed when the user clicks  [image]  and then clicks the control. If there is no custom Help topic for the form, Microsoft Access displays the Microsoft Access Help Topics dialog box.


Add the What's This button to a form

You might want to use this procedure for a custom dialog box or if you've disabled the title bar for a particular form or removed the What's This button ( [image]) from the title bar for that form.

1	In form Design view, double-click the form selector to display the form's property sheet.

2	In the WhatsThisButton property box, click Yes.

Note   If you haven't specified a custom Help file in the HelpFile property box for the form, the Microsoft Access Help file is displayed when you click  [image]  and then click the form or a control on the form. For more information on using the HelpFile and HelpContextID properties, click  [image].


Work with option groups

What do you want to do?

Move the option group

Size the option group

Figure out why the option group isn't working the way I want


Work with combo boxes

What do you want to do?

Move the combo box

Size the combo box

Figure out why the combo box isn't working the way I want

Read about properties that I can use to modify the combo box


Work with list boxes

What do you want to do?

Move the list box

Size the list box

Figure out why the list box isn't working the way I want

Read about properties that I can use to modify the list box


Work with command buttons

What do you want to do?

Move the command button

Size the command button

Add a picture to the command button

Change the command button caption

See the event procedure behind the command button


Change label text or command button text

1	In form or report Design view, click the label or button, and then select the label text or button text.

2	Type the new text.


See an event procedure created by the Command Button Wizard

1	In form Design view, use the right mouse button to click the command button created by the Command Button Wizard.

2	On the shortcut menu, click Build Event.


Work with subforms

What do you want to do?

Move the subform control

Size the subform control

Change the layout of the subform

Figure out why the subform isn't working the way I want


Create a form

You can create a form on your own or you can have Microsoft Access create your form for you using a Form Wizard. A Form Wizard speeds up the process of creating a form because it does all the basic work for you. When you use a Form Wizard, Microsoft Access prompts you for information and creates a form based on your answers. Even if you've created many forms, you may want to use a Form Wizard to quickly lay out all the controls on your form. Then you can switch to Design view to customize your form.

If you just want to create a simple single-column form, you can use the New Object button.

What do you want to do?

Create a single-column form using the New Object button

Create a form with a wizard

Create a form on my own

Create a form based on more than one table

Create a form from records you've already filtered in a table, query, or another form


 Create a form with a wizard

1	In the Database window, click the Forms tab.

2	Click New.

3	In the New Form dialog box, click the wizard that you want to use. A description of the wizard appears in the left side of the dialog box.

4	Click the name of the table or query that includes the data you want to base your form on.

Note   You don't need to do this step if you click the Form Wizard option—you can specify the record source for the form in the wizard.

5	Click OK.

6	If you clicked Form Wizard, Chart Wizard, or PivotTable Wizard in step 3, follow the directions in the wizard dialog boxes. If you clicked AutoForm: Columnar, AutoForm: Tabular, or AutoForm: Datasheet, Microsoft Access automatically creates your form.

If the resulting form doesn't look the way you want, you can change it in Design view.

How?

Note   If you click one of the AutoForm options, Microsoft Access uses the autoformat you last specified, either in the Form Wizard or using the AutoFormat command.


Create a form without a wizard

1	In the Database window, click the Forms tab.

2	Click New.

3	In the New Form dialog box, click Design View.

4	Click the name of the table or query that includes the data you want to base your form on. If the form won't contain data (for example, if you want to create a form to use as a switchboard or custom dialog box), don't select anything from this list.

Note If you want to create a form that uses data from more than one table, base your form on a query that includes the tables you want to include.

5	Click OK.

Microsoft Access displays the Form window in Design view. For information on adding controls in Design view, click  [image].


Create a form using AutoForm

AutoForm creates a form that displays all fields and records in the selected table or query. Each field appears on a separate line with a label to its left.

1	In the Database window, click the Tables or Queries tab.

2	Click the table or query you want to base the form on, or open the table or query in any view.

3	Click the arrow next to the New Object button on the toolbar, and then click AutoForm.


Create a form based on more than one table

Using a Form Wizard is the simplest and fastest way to create a form that brings data together from more than one table. A Form Wizard speeds up the process of creating a form because it does all the basic work for you. In the first screen of a Form Wizard, you can pick the fields you want to include in your form. These fields can be from one table or from multiple tables. When you use a Form Wizard to create a multiple-table form, Microsoft Access creates an SQL statement behind the form. The SQL statement includes the information about which tables and fields to use.

You can use a Form Wizard to create a form that displays data from multiple tables as a "flat form" or as a "hierarchical form." An example of a flat form is a form that shows products and product suppliers. To see an illustration of this type of form, click  [image]. A hierarchical form is a form with one or more subforms. Subforms are useful if you want to show data from tables that have a one-to-many relationship. For example, you could have a Categories form that includes data from a Categories table and a Products table. To see an illustration of this type of form, click  [image].

You may want to present your data hierarchically without using a subform. For example, if you have a form with lots of controls, you may not have room for a subform. In this case, you can use a Form Wizard to create synchronized forms. When you click a command button on one form, it opens another form that's synchronized with the record on the first form. To see an illustration of this type of form, click  [image].

Although a Form Wizard is the easiest way to create any of these types of forms, in certain cases you may want to create a query instead, and base your form on that query. To read about when you would want to base your form on a query instead of using a Form Wizard, click  [image].

What do you want to do?

Use a Form Wizard to create a flat form, a form with one or more subforms, or a form that's synchronized with another form

Add a subform to an existing form

Synchronize a form with another form

Create a query

Create a form on my own and use a query as the data source for that form


Switch between views of a form

Forms have three views: Design view, Form view, and Datasheet view. You use Design view to create a form or change the structure of an existing form. You use Form view to view data using the form. You can usually see all the fields for only one record in Form view. You use Datasheet view to see many records at one time.

•	Click the View button on the toolbar. To change to the view indicated by the graphic, click the button itself. To see a list of other views to choose from, click the arrow next to the button.


Open a form

1	In the Database window, click the Forms tab.

2	Click the form you want to open.

3	Click the Open button to open the form in Form view, or the Design button to open the form in Design view.

Tip   You can also open a form in Form view by dragging the form from the Database window to the application background.

Once you've opened a form, you can easily switch among the three views of the form by clicking the View button on the toolbar.


Open or close a field list for a form or report

You can use the field list to add bound controls to a form or report. The field list is available only in the Design view of the form or report.

•	Click  [image]  on the toolbar.


Open or close the toolbox

You can use the toolbox to add controls to a form or report. The toolbox is available only in the Design view of the form or report.

•	Click  [image]  on the toolbar.


Lock down a toolbox tool or toolbar button

If you want to do the same task more than once, you can lock down a toolbox tool or toolbar button so you don't have to click it again. For example, if you want to add several labels to a form, you can lock down the Label tool in the toolbox.

•	Double-click the button or tool you want to lock down.

To release the lock, press ESC.


What is a property sheet?

In Microsoft Access, you use properties to determine the characteristics of tables, queries, fields, forms, and reports. Every control on a form or report has properties as well. Control properties determine the structure, appearance, and behavior of a control as well as the characteristics of the text or data it contains. You set properties using the property sheet. For example, the following illustration shows the property sheet for a Total Sales control. The Format property for this control is set to Currency.


Set properties for a form or report

You can set properties for a form or report, a section within a form or report, or for controls on the form or report.

1	In form or report Design view, double-click the form selector or the report selector to open the property sheet.

2	In the property sheet, click the property you want to set, and then do one of the following:

•	If an arrow appears in the property box, click it and then select a value from the list.

•	Type a setting or expression in the property box.

•	If a Build button appears next to the property box, click it to display a builder or to display a dialog box giving you a choice of builders. For example, you can use the Query Builder to change the design of an underlying query for a form or report.

3	If you need more space to enter or edit a property setting, press SHIFT+F2 (or click the right mouse button and then click Zoom) to open the Zoom box.

If the property sheet is blank or if you don't see the properties you expect in the property sheet, click  [image].

Tip   When you click a property in the property sheet, a short description of the property appears in the status bar. For a more detailed description of the property and its settings, click the property and then press F1.


Set properties for a section

1	In form or report Design view, double-click the section selector to open the property sheet.

2	In the property sheet, click the property you want to set, and then do one of the following:

•	If an arrow appears in the property box, click it and then select a value from the list.

•	Type a setting or expression in the property box.

•	If a Build button appears next to the property box, click it to display a builder or a dialog box giving you a choice of builders.

3	If you need more space to enter or edit a property setting, press SHIFT+F2 (or click the right mouse button and then click Zoom) to open the Zoom box.

If the property sheet is blank or if you don't see the properties you expect in the property sheet, click  [image].

Tip   When you click a property in the property sheet, a short description of the property appears in the status bar. For a more detailed description of the property and its settings, click the property and then press F1.


Set properties for a control

1	Double-click the control to open the property sheet, or click the control and then click  [image]  on the toolbar.

2	Click the property you want to set in the property sheet and then do one of the following:

•	If an arrow appears in the property box, click it and then choose a value from the list.

•	Type a setting or expression in the property box.

•	If a Build button appears next to the property box, click it to display a builder or a dialog box giving you a choice of builders.

3	If you need more space to enter or edit a property setting, press SHIFT+F2 (or click the right mouse button and then click Zoom) to open the Zoom box.

If the property sheet is blank or if you don't see the properties you expect in the property sheet, click here  [image].

Tip   When you click the property in the property sheet, a short description of the property appears in the status bar. For a more detailed description of the property and its settings, click the property in the property sheet and then press F1.


Troubleshoot property sheets

What do you need help with?

Why is the property sheet blank even though I selected a control or other object?

I selected controls. Why don't I see all the properties for the controls in the property sheet?

I selected controls and the correct properties appear in the property sheet, but the property box for a particular property is blank even though values have been set for that property in one or more of the selected controls.

Why don't the property settings for my bound control match the property settings for the field in table Design view?


Why is the property sheet blank?

•	If the property sheet is displayed and you click a control that's already selected, the property sheet will go blank. If you don't need to type a value in the control, press the ESC key to redisplay the property sheet. Otherwise type a value and press ENTER.


Why don't I see all the properties in the property sheet?

•	If you select multiple controls but don't see the properties you expect in the property sheet, you may have selected a control that you didn't mean to select. For example, you may have included a line in a group of text boxes. Properties appear in the property sheet only if they apply to all of the selected controls. To remove a control from a group selection, hold down the SHIFT key and click the control.


Why is the property box for a particular property blank?

•	If the property setting for a particular property is the same for all selected controls, that setting appears in the property sheet; otherwise, the property box for that property is blank. If you have multiple controls selected, and you change a setting for a property in the property box, that change affects all selected controls.


Why don't the property settings for my control match the settings in table Design view?

•	The property settings for a bound control might not match corresponding settings in the field in the underlying table that the control is bound to. If the settings are different, the form or report settings typically override those in the table, but they apply only to the current form or report. It's generally a good idea to set the Format, DecimalPlaces, InputMask, ValidationRule, ValidationText, and DefaultValue properties in the underlying table or query rather than in the control. This way, you can be sure that you have consistent settings for the field whenever you add it to a form or report. To learn more about property inheritance in controls, click  [image].


Select a section on a form or report

•	Click the section selector or anywhere in the section bar.

You can also click anywhere in the background of the section to select it.


Select a form or report

•	Click the form selector or report selector.

If the rulers aren't displayed, you can click Select Form or Select Report on the Edit menu, or you can click the gray background to the right of the form to select it.


When should I base a form or report on a saved query instead of an SQL statement?

You can create many types of forms and reports, including fairly complicated multiple-table forms and reports, using the Form and Report Wizards. When you create a form or report with a wizard, Microsoft Access creates an SQL statement to use as the record source for the form or report. In some cases, you may want to base your form or report on a saved query instead. Even in these cases, however, you can use the Form or Report Wizard to create an SQL statement, and then modify that SQL statement and save it as a query.

How?

You'll need to base your form or report on a query in the following cases:

•	If your form or report contains an expression that you want to use with other objects besides the current form or report. In this case, you define the expression in the query.

•	If you want to set criteria for data that you'll use with other objects besides the current form or report. You can't set criteria in the Form and Report Wizards. After you've created a form or report with a wizard, however, you can click the Build button to modify the SQL statement behind the form or report. When you click the Build button, Microsoft Access opens query Design view so you can set or modify criteria. This criteria applies only to the current form or report, however, so if you want to use the same criteria with other objects, you'll need to save the SQL statement as a query and then base your form or report on that query.

•	If you want your form or report to open faster. Microsoft Access opens a form or report based on a saved query faster than a form or report based on an SQL statement. The performance gain is a few seconds and varies with the clock speed of your computer.

Notes

•	If you always want to restrict data in your form or report to meet certain criteria, or to sort your form data the same way, you can still create your form or report with a wizard. However, you'll need to set the criteria and/or the sort order for the SQL statement by clicking the Build button.

•	In most cases, you can update the fields in a form based on a query or SQL statement. For information on designing queries and SQL statements that you can use to update fields in underlying tables, click  [image].


Change the underlying table, query, or SQL statement for a form or report

1	In form or report Design view, double-click the form selector or the report selector to open the property sheet.

2	Do one of the following:

•	If the form or report is based on an SQL statement or a query, and you want to modify the SQL statement or change the design of the query, click the Build button next to the RecordSource property to open query Design view. You can modify an SQL statement the same way that you modify a query — just drag fields and set the criteria and sort order in the design grid.

•	If you just want to change from one table or query to another, click the arrow in the RecordSource property box to select from a list of tables or queries.


Display or hide the grid

•	On the View menu, click Grid.


Change the grid's fineness (granularity)

1	In form or report Design view, double-click the form selector or the report selector to open the property sheet.

2	To change the horizontal units, type a new value for the GridX property. To change the vertical units, type a new value for the GridY property. Higher numbers indicate greater fineness.

Note   The grid is preset to 10 units per inch horizontally and 12 units per inch vertically. If you're using centimeters as your unit of measure, the grid is set to 5 x 5. You can change these settings to any integer value from 1 to 64. Dots on the grid are invisible if the fineness is greater than 16 units per inch or 6 units per centimeter.


Set the size of a form when it's first opened

1	In Form view, size the form by dragging the borders of the Form window.

2	On the File menu, click Save.

Note   If the AutoResize property is set to Yes, Microsoft Access automatically sizes the form to display complete records. To set the form to the size you want, make sure the AutoResize property is set to No.


Size a form to fit its contents

1	In Form view, click Size To Fit Form on the Window menu.

Note   If the Form window is maximized, the Size To Fit Form command is unavailable.

2	On the File menu, click Save to save the size of the form.

When you click Size To Fit Form, Microsoft Access adjusts the size of the form depending on the form's DefaultView property setting.

DefaultView setting	Result
Single Form	If the displayed record is smaller than the Form window, Size To Fit Form crops the window to the size of the record. If the record is larger than the Form window, Size To Fit Form expands the Form window to show as much of the record as possible.
Continuous Forms	If only part of the bottom record is displayed, Size To Fit Form crops that record. If only one record is partially displayed, Size To Fit Form enlarges the window to show as much of the record as possible.


Center a form in the application window when it's first opened

1	In form Design view, double-click the form selector to open the property sheet.

2	Set the AutoCenter property to Yes.

The next time you open the form, it will be centered in the application window.


Change the title bar text for a form in Form view

1	In form Design view, double-click the form selector to open the property sheet.

2	In the Caption property box, type the title bar text.

3	To see the title bar text, switch to Form view.

Tip   If you don't want to have any title bar text, type a space in the Caption property box.


Preview a form

To preview a form from Design view, Form view, or Datasheet view

•	Click  [image]  on the toolbar.

To preview a form from the Database window

1	Click the Forms tab.

2	Select the form you want to preview.

3	Click  [image]  on the toolbar.

How Microsoft Access displays a form in Print Preview depends on the view from which you preview it.

From	You see the form
Design view	In Form view.
Form view	In Form view.
Datasheet view	As a datasheet.
Database window	In the view specified by the DefaultView property of the form.
For information on viewing a form at different magnifications, click  [image].

For information on viewing two or more pages at one time, click  [image].


Print a form

What do you want to do?

Set the page orientation or other page setup options

Print a form from Design view, Form view, or Datasheet view

Print a form from the Database window

Print selected records in a form or datasheet

Print the current record


Print a form from Design view, Form view, or Datasheet view

1	On the File menu, click Print.

2	In the Print dialog box, select the printing options you want.

How Microsoft Access prints a form depends on the view from which you print it.

From	The form prints
Design view	In Form view.
Form view	In Form view.
Datasheet view	As a datasheet.

Tip   If you want to print a form without having to specify options in the Print dialog box, click  [image]  on the toolbar.


Print a form from the Database window

1	Click the Forms tab.

2	Select the form you want to print.

3	On the File menu, click Print.

4	In the Print dialog box, select the printing options you want.

5	Click OK.

Microsoft Access prints the form in the view specified in the form's DefaultView property.

Tip   If you want to print a form without having to specify options in the Print dialog box, click  [image]  on the toolbar.


Print selected records in a form or datasheet

1	In Form view or Datasheet view, select the records you want to print by clicking the record selector or pressing SHIFT+SPACEBAR.

2	On the File menu, click Print.

3	In the Print dialog box under Print Range, click Selected Record(s).


Troubleshoot problems with printed forms

What do you need help with?

Why do the fonts in my printed form look different from my on-screen fonts?


Why do the fonts in my printed form look different from my on-screen fonts?

When you choose a font for a printed form, unless you select a scaleable font, such as a TrueType font, the characters on the screen may not look exactly like those that appear in print.

By default, the fonts that appear in the Font box on the Formatting toolbar are screen fonts or TrueType fonts. Microsoft Access uses the screen fonts and TrueType fonts that were set up on your computer when Windows was set up. You can change this so that Microsoft Access displays your printer's fonts on the toolbar. To do this, change the form's LayoutForPrint property to Yes. If the LayoutForPrint property is set to Yes, the fonts and the point sizes displayed in the Font box correspond to the fonts and sizes available on the printer that you specify using the Print command on the File menu. The fonts your printer uses depend entirely on the kind of printer you have (see your printer documentation for details on which fonts are available on your printer). Microsoft Access displays the screen font that is most like the printer font.

Note   It's generally a good idea to use TrueType fonts since they look the same on screen and on paper.

After you've chosen a printer, designed a form, and saved the form, Microsoft Access uses the printer you selected for that form. If you try to print the form on a different printer, your printer may substitute fonts if it doesn't have all the fonts used in the form's design.


Add a control to a form or report

Everything you add to a form or report is a control. Text boxes, labels, list boxes, option buttons, command buttons, and lines are examples of different controls. The way you create a control depends on whether you want to create a bound control, an unbound control, or a calculated control.

What do you want to do?

Learn more about bound, unbound, and calculated controls

Create a bound control

Create an unbound control

Create a calculated control

Create a specific type of control on a form (text box, check box, list box, and so on)

Create a specific type of control on a report (label, text box, check box, and so on)


 Create a specific type of control on a form

What do you want to do?

Create a text box

Create a label

Create a check box, toggle button, or option button that isn't included in an option group

Create an option group that will include check boxes, toggle buttons, or option buttons

Create a command button

Create a list box or combo box

Create a subform

Create a control for a picture or other object created with another application (Word document, for example)

Create a chart

Create a control to display Microsoft Access data in a Microsoft Excel PivotTable

Add a custom control


Create an unbound control

1	Open the form or report in Design view.

2	If you want to use a wizard to help you create the control, make sure  [image]  in the toolbox is pressed in.

Note  You can use a wizard to create command buttons, list boxes, combo boxes, subforms, and option groups.

3	In the toolbox, click the tool for the control you want to create.

4	In the form or report, click the place where you want the upper-left corner of the control to be.
If you click and release the mouse button, Microsoft Access creates a default-sized control. To create a control of a particular size, click the mouse button and then drag until the control is the size you want.

Tip   If you want to create several controls of the same type, you can double-click the appropriate tool in the toolbox to lock it down.


Create a bound control

1	Open the form or report in Design view.

2	If you want to use a wizard to help you create the control, make sure  [image]  in the toolbox is pressed in.

Note You can use a wizard to create command buttons, list boxes, combo boxes, subforms, and option groups. You can also use wizards to create a control for a chart or PivotTable.

3	Display the field list by clicking  [image]  on the toolbar.

4	Select one or more fields in the field list.

To select	Do this
One field	Click the field.
A block of  fields	Click the first field in the block, hold down the SHIFT key, and then click the last field in the block.
Nonadjacent  fields	Hold down the CTRL key and click the name of each field you want to include.
All fields	Double-click  the field list title bar.
5	Drag the selected field or fields from the field list to the form or report. Place the upper-left corner of the icon where you want the upper-left corner of the main control (not its label) to be, and release the mouse button.

Microsoft Access creates the appropriate control for the field and sets certain properties, based on the field's data type and the settings of the DisplayControl property. If this isn't the type of control you want to create, click the appropriate control tool in the toolbox before dragging the field from the field list. To read about the DisplayControl property, click  [image].

You can also change a control to another type of control after you create it.

How?


Delete a control

1	Click the control.

2	Press DEL.

If the control has an attached label, Microsoft Access deletes the control and its label. If you want to delete just the attached label, click the label and press DEL.


Bind an unbound control to a field

1	Double-click the control to open its property sheet.

2	In the ControlSource property box, enter the name of the field you want to bind the control to.

Note   If you bind a control to a field this way, or if you change the underlying field for a bound control, Microsoft Access doesn't set the control properties to the values set for the same properties in the underlying field. ValidationRule, ValidationText, and DefaultValue property settings in the underlying field will be applied, however, since these properties are enforced for the field, not just the control. If you create a bound control by dragging fields from the field list, the bound control inherits certain properties from the field. For more information about which properties are inherited and how this inheritance works, click  [image].


Select a control

•	Click anywhere in the control.

If the control has an attached label, it looks like this:

Note   If you click a control that's already selected, an insertion point appears inside the control so that you can enter or edit text. To select the control, click outside the control, and then click the control again.


Select adjacent controls

•	Starting at any point outside a control, drag a rectangle over the controls you want to select.

Tips

•	You can specify whether the rectangle you drag over controls needs to only touch the controls or must enclose them completely to select them. On the Tools menu, click Options, click the Forms/Reports tab, and then click one of the options under Selection Behavior.

•	To remove one or more controls from the selected group, hold down the SHIFT key and then click the controls you want to remove.


Select nonadjacent or overlapping controls

•	Hold down the SHIFT key and click each control you want to select.


Select controls with the rulers

You can use the rulers to select all the controls that are located at one horizontal or vertical location. For example, you can use this technique to select all the text boxes in a single-column form, or all the controls that appear across the bottom of a form.

•	Click the horizontal ruler above the column of controls you want to select, or the vertical ruler to the left of the row of controls you want to select.

You can also drag along the ruler to select a wider area of controls.


Remove a control from a selected group

•	Hold down the SHIFT key and click the control or controls you want to remove from the selected group.


Move a control and its label

1	Click the control or its label.

When you click either part of a compound control, Microsoft Access displays the move handles for both controls, as well as the sizing handles for the control you clicked.

2	Pass the pointer over the border (not the move handle) of either the control or its label until it turns into an open hand, and then drag the controls to a new position.

As you're moving the controls, you can use the rulers to help you position them.

Tips

•	If you want to cancel a move in progress, press ESC.

•	When you move a control, you can maintain its horizontal or vertical alignment with other controls by holding down the SHIFT key while selecting and moving the control. You can move the control horizontally or vertically only, depending on which direction you move it first.

•	If you need to make small adjustments to the placement of a control, you may find it easier to press CTRL plus the appropriate arrow keys. When you move a control this way, Microsoft Access does not align the control with the grid, even if Snap To Grid is on.


Move a control or its label separately

The parts of a compound control remain related even if you move the individual parts separately.

1	Click the control or its label.

2	Place the pointer over the move handle in the upper-left corner of the control or label.

3	When the pointer changes to an upward-pointing hand, you can drag the control or label.

Tips

•	If you want to cancel a move, press ESC.

•	To move an attached label to another section without moving the control, you must use the Cut and Paste commands. If you move a label to another section, the label will no longer be related to the control.

•	When you move a control, you can maintain its horizontal or vertical alignment with other controls by holding down the SHIFT key while selecting and moving the control. You can move the control horizontally or vertically only, depending on which direction you move it first.

If you're moving a group of controls, hold down the SHIFT key as you select each control. When you select the last control, continue to hold down the mouse button as you drag the group.

•	If you need to make small adjustments to the placement of a control, you may find it easier to press CTRL plus the appropriate arrow keys. When you move a control this way, Microsoft Access does not align the control with the grid, even if Snap To Grid is on.


Change the ruler's unit of measure

The ruler's unit of measure is inches or centimeters. You can change the unit of measure if you don't want to use the default unit of measure. For example, you can change from inches to centimeters if you find that using inches doesn't allow you to place controls as accurately as you'd like.

1	Click the Windows Start button, point to Settings, and then click Control Panel.

2	Double-click the Regional Settings icon.

3	Click the Number Tab.

4	In the Measurement System list, click Metric or U.S.


Move a control in front of or behind other controls

To make a form or report more attractive, you may want to overlap lines and boxes with other types of controls. You can move a line, box, or other control to the top of a stack of controls or send it to the bottom of a stack of controls.

•	Click the item you want to move, and then click Send To Back or Bring To Front on the Format menu.

Note   A list box or subform is always at the top of the stack; you can't move a list box or subform to the bottom of a stack.


Size a control

1	Click the control or controls you want to resize.

2	Drag the sizing handles until the control is the size you want.

If you select more than one control, all the controls change size as you drag the sizing handle of one control.

Tip   If you want to make small adjustments to the size of a control, you may find it easier to press SHIFT plus the appropriate arrow keys.


Size a control to fit its contents

If you have changed the size of text in a control, or if you have added a picture to a control, you can use this procedure to quickly size the control to fit the contents.

1	Select the control or controls you want to resize.

2	On the Format menu, point to Size, and then click To Fit.


Size controls uniformly using the grid

1	If the grid isn't already displayed, click Grid on the View menu.

2	Select the controls you want to resize.

3	On the Format menu, point to Size, and then click To Grid.

Notes

•	You can have Microsoft Access automatically snap items to the grid as you size them. For more information, click  [image].

•	You may find that you need to adjust the distance between the dots on the grid so that you can size controls more accurately. For more information, click  [image].


Size controls uniformly relative to each other

1	Select the controls you want to size.

2	On the Format menu, point to Size, and then click one of the following commands:

•	To Tallest — makes the controls as tall as the tallest selected control.

•	To Shortest — makes the controls as short as the shortest selected control.

•	To Widest — makes the controls as wide as the widest selected control.

•	To Narrowest — makes the controls as narrow as the narrowest selected control.


Cut or copy and paste a control

Note   If you want to create a group of evenly spaced controls, it's better to use the Duplicate command instead of the Copy command. For more information, click  [image].

1	Click the control you want to cut or copy. If the control has an attached label, click the control, not the label.

2	On the Edit menu, click Cut to delete the control, or click Copy to copy the control.

3	Select the section you want to paste the control to.

4	On the Edit menu, click Paste.

To a limited extent, you can determine where Microsoft Access pastes the control. If you select a section, Microsoft Access pastes the control in the upper-left corner of the section. If you select a control near the area where you want to paste the control, Microsoft Access pastes the control just below the selected control. Note, however, that if you paste a label, and the control you select doesn't have an attached label, Microsoft Access attaches the label to the selected control.

Note   Microsoft Access doesn't copy event procedures associated with a control.


Duplicate a control

Duplicating controls is a convenient way to create a group of evenly spaced controls. However, when you duplicate a control, Microsoft Access doesn't copy event procedures associated with the control.

1	Click the control you want to duplicate. If the control has an attached label, click the control, not the label.

2	On the Edit menu, click Duplicate.

Microsoft Access pastes the control just below the control you selected.

3	If you want to create another evenly spaced control, click Duplicate again.

Microsoft Access places the control beneath the most recently pasted control, even if you moved that control.

Tip   If you just want to copy formatting properties from one control to another, you can click  [image]  on the toolbar. For more information, click  [image].


Align controls using the grid

1	If the grid isn't already displayed, click Grid on the View menu.

2	Select the control or controls you want to align.

3	On the Format menu, point to Align, and then click To Grid.

Microsoft Access aligns the upper-left corner of the selected controls to the grid. For information on aligning all corners of the controls to the grid, click  [image].

Notes

•	You can have Microsoft Access automatically snap items to the grid as you create or move them. For more information, click  [image].

•	You may find that you need to adjust the distance between the dots on the grid so that you can align controls more accurately. For more information, click  [image].


Turn Snap To Grid behavior on or off

•	On the Format menu, click Snap To Grid.

If Snap To Grid is turned on, when you create a control by clicking the form or report, Microsoft Access aligns the upper-left corner of the control to the grid. If you create a control by dragging, Microsoft Access aligns all corners of the control to the grid. If you move or resize an existing control, Microsoft Access lets you move the control or its boundary from grid point to grid point only.

When Snap To Grid is turned off, Microsoft Access ignores the grid and lets you place, move, or resize controls anywhere on the form or report.

Tip If you want to turn Snap To Grid off temporarily, hold down the CTRL key before or while you're placing, moving, or sizing a control. Releasing the CTRL key turns Snap To Grid back on.


Align all corners of controls to the grid

1	Select the controls you want to align.

2	On the Format menu, point to Size, and then click To Grid.

Microsoft Access adjusts the size of the controls so that all four corners meet the nearest points on the grid.

Notes

•	You can have Microsoft Access automatically snap items to the grid as you create or move them. For more information, click  [image].

•	You may find that you need to adjust the distance between the dots on the grid so that you can align controls more accurately. For more information, click  [image].


Align controls to each other

1	Select the controls you want to align. Select only controls that are in the same row or in the same column.

2	On the Format menu, point to Align, and then click one of the following commands:

•	Left — aligns the left edges of the controls with the left edge of the leftmost control.

•	Right — aligns the right edges of the controls with the right edge of the rightmost control.

•	Top — aligns the top edges of the controls with the top edge of the highest control.

•	Bottom — aligns the bottom edges of the controls with the bottom edge of the lowest control.

Note   If any of the selected controls would overlap after being aligned, Microsoft Access doesn't overlap them. Instead, it places the controls with their edges next to each other.


Space controls evenly

1	Select the controls (at least three) that you want to adjust. For controls with attached labels, select the controls, not their labels.

2	On the Format menu, point to Horizontal Spacing or Vertical Spacing, and then click Make Equal.

Microsoft Access spaces the controls evenly. Only the middle controls actually adjust, however; the top and bottom controls don't change location.


Increase or decrease space between controls

1	Select the controls you want to adjust.

2	On the Format menu, point to Horizontal Spacing or Vertical Spacing, and then click Increase or Decrease.

When the space between controls is increased or decreased, the leftmost (horizontal spacing) and highest (vertical spacing) controls don't change positions.


Change a control to another type of control

1	Click the control you want to change.

2	On the Format menu, point to Change To.

Microsoft Access displays a list of controls that the selected control can be changed to. If a type of control appears dimmed on the menu, you can't change the selected control to that type of control.

3	Click the type of control you want to change to.

When you change a control to another type of control, Microsoft Access copies the appropriate property settings from the original control to the new control. If a property exists for the original control but not for the new control, Microsoft Access doesn't copy it. If a property exists for the new control but not for the original control, Microsoft Access sets the property to the default control style for that type of control.


Control properties and property inheritance

When you create a bound control by dragging a field from the field list, Microsoft Access copies certain properties from the field in the underlying table or query to the control. For example, if the Unit Price field in a Products table has the Format property set to Currency and the DecimalPlaces property set to Auto, when you create a bound text box in a form by dragging the Unit Price field from the field list, Microsoft Access automatically sets the Format and DecimalPlaces properties for the text box control to the same values. (This assumes that the DisplayControl property for the field is set to Text Box or has no setting.)

You can change the settings of any inherited (copied) properties in the control's property sheet. If you change a control's property setting, the change doesn't affect the setting of that property for the field in the underlying table or query. Likewise, if you change the property setting for a field in a table or query after you've created a form using that field, the property setting for the control isn't updated; you must update this manually. (Note, however, that if you change field property settings for the DefaultValue, ValidationRule, and ValidationText properties, these changes will be enforced in any controls based on these fields, even if the controls were created before you changed the field properties.)

Tip   It's best to set the Format, DecimalPlaces, InputMask, ValidationRule, ValidationText, and DefaultValue properties in the underlying field rather than in a control. This way, you can be sure that you have consistent settings whenever you add fields to a form or report.

The following table lists properties that are inherited for each type of bound control when you drag a field from the field list.

Bound control	Properties inherited
Text box	Format, DecimalPlaces, InputMask, and StatusBarText (from Description property)
Combo box or list box	All of the properties specified in the Lookup tab in table Design view, and the StatusBarText property (from Description property)
Check box, option button, option group, toggle  button, bound object frame	StatusBarText (from Description property)
Notes

•	The DefaultValue, ValidationRule, and ValidationText properties are not inherited. That is, Microsoft Access doesn't set the control properties to the values set for the same properties in the underlying field. These property settings are enforced, however, when you create a control based on a field with these settings. If you set the ValidationRule property in a field, and also in a control based on that field, Microsoft Access enforces both rules. If you set the DefaultValue property for a field, and also in a control based on that field, the control property will override the field property.

•	If you create a text box based on a field with the Memo data type, Microsoft Access automatically sets the EnterKeyBehavior property to New Line In Field, and the ScrollBars property to Vertical Only. These properties aren't inherited from the field properties — they are just properties of the control.


Change the properties of several controls at once

You can change property settings for a group of controls of the same type or for a group of controls of different types. If you select controls of different types, Microsoft Access displays only the properties shared by the group in the property sheet. If all the controls you've selected share the same property setting, that setting appears in the property sheet; otherwise, the property box is blank. If you change the property setting, the change is applied to all selected controls.

1	Double-click any control to open its property sheet.

2	Select the other controls by holding down the SHIFT key as you click each control.

3	In the property sheet, change the appropriate properties.

If you don't see the properties you expect in the property sheet, click  [image].

Note   The Name property never appears when more than one control is selected because control names must be unique.


Change default properties for a type of control

Each type of control has a default set of properties that determine the general appearance and behavior of that type of control. For example, the default properties for a text box determine the size and font of the text box and whether the text box has an attached label. This set of properties for a control is called the "default control style." You may want to change the default control style for a type of control if you find that you often make the same changes to that type of control after you add it to a form or report.

For example, suppose you don't want to create labels for text boxes you add to a new form. Rather than deleting the label each time you create a text box, you can change the AutoLabel property setting to No in the text box's default control style.

Once you reset a control's default control style, all subsequent controls of that type that you add to the current form or report will have those property settings. The default control style remains in effect for that form or report until you change it again.

What do you want to do?

For the current form or report only, change a control's default control style

For the current form or report only, change a control's default control style to match an existing control

Change a control's default control style for all forms or all reports


Change the default control style for new controls using the property sheet

1	In the toolbox, click the tool for the type of control that you want to change. For example, if you want to change the default control style for text boxes, click the text box tool.

2	Display the property sheet by clicking  [image]  on the toolbar.

Microsoft Access changes the title bar of the property sheet to indicate that you've opened the default property sheet for that type of control.

3	In the property sheet, change the property settings.


Change the default control style for new controls using an existing control

1	Select the control that has the characteristics that you want to use as defaults.

2	On the Format menu, click Set Control Defaults.

Microsoft Access sets the default properties for that type of control based on the control you selected.

Tip   You can copy formatting characteristics from one control to another by clicking  [image]  on the toolbar. For more information, click  [image].


Copy formatting characteristics from one control to another

1	Click the control that has the formatting characteristics you want to copy.

Note   You can copy characteristics only from a single control.

2	Click  [image]  on the toolbar. If you know that you'll want to use the same formatting characteristics on several controls, double-click the button to lock it down.

If you want to cancel the format copy, press ESC.

3	Click the control that you want to paste the formatting characteristics to. You can click the same type of control, or you can select another type of control. For example, you can copy formatting characteristics from a text box to a list box.

Microsoft Access copies any of the following properties: SpecialEffect, BorderStyle, BorderColor, BorderWidth, BackColor, BackStyle, LineSlant, Visible, DisplayWhen, FontName, FontSize, FontWeight, ForeColor, FontItalic, FontUnderline, LabelAlign, TextAlign, LabelX, and LabelY.

Note   You can't copy properties to or from custom controls.


Change the format of data in a control

Microsoft Access provides predefined formats for fields with the following data types: Number, Currency, Date/Time, and Yes/No.

1	Double-click the control to open its property sheet.

2	In the Format property box, click one of the predefined formatting settings. You can create your own format if a predefined format doesn't meet your needs. For more information, click  [image].

Notes

•	Currency values, dates, times, and numbers are displayed according to the settings in the Regional Settings section of the Windows Control Panel.

•	For controls that display numbers, you may also want to set the DecimalPlaces property.


Display instructions for a control in the status bar

1	Double-click the control to open its property sheet.

2	In the StatusBarText property box, type the message you want to display for the control.

You can enter up to 255 characters, but Microsoft Access can only display as much text as will fit in the status bar. The amount of text that can be displayed varies according to the font you use and whether you resize the Microsoft Access window.

Tip   You can create a tip that pops up when you move the mouse pointer over a control. For more information, click  [image]. You can also create custom Help files and What's This tips. For more information, click  [image].


Disable a control in Form view or make data in a control read-only

1	Double-click the control to open its property sheet.

2	Do one of the following:

•	If you want to disable the control completely so it appears dimmed and can't receive the focus, set the Enabled property to No.

•	If you want to make data in the control readable, but not allow users to change the data, set the Locked property to Yes.

Notes

•	You can use the Enabled property together with the AfterUpdate property to disable a control until a user enters text or makes a selection in another control. For example, you might want to disable a command button until data has been entered in a text box. You can use the AfterUpdate property of the text box to call an event procedure or a macro to enable the command button.

•	For more information on the Enabled and Locked properties and how you can use them together, click  [image].

•	If you just want to keep a control off the tab order, but you want to make it possible to select that control, set the TabStop property for that control to No.


Assign an access key (accelerator key) to a label or button

When you assign an access key to a label or button, you can press ALT + an underlined character to move the focus to the control attached to that label, or to the button.

1	Double-click the label or button you want to assign the access key to.

2	In the Caption property box in the property sheet, type an ampersand (&) immediately before the character you want to use as the access key.


Create a tip that pops up when you move the mouse pointer over a control

1	In form Design view, double-click the control that you want to create a tip for.

2	In the ControlTipText property box in the property sheet, type the message you want to display for the control. You can type to 255 characters.

You can also create a custom Help file or custom What's This tips for your form. For more information, click  [image].


What is a label?

You use labels on a form or report to display descriptive text such as titles, captions, or brief instructions. Labels don't display values from fields or expressions; they're always unbound and they don't change as you move from record to record.

A label can be attached to another control. When you create a text box, for example, it has an attached label that displays a caption for that text box. This label appears as a column heading in the Datasheet view of a form.

When you create a label using the Label tool, the label stands on its own  — it isn't attached to any other control. You use stand-alone labels for information such as the title of a form or report, or for other descriptive text. Stand-alone labels don't appear in Datasheet view.


 Create a label

Use this procedure to create a stand-alone label (a label that isn't attached to another control). To create a label that's attached to a control, just create the control. Microsoft Access automatically attaches a label to the control when you create it.

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to place the label, and then type the text for the label.

Notes

•	If you want to display the text in a label on more than one line, you can resize the label after you enter all the text, or you can press CTRL+ENTER at the end of the first line of text to enter a carriage return. If you insert a carriage return, Microsoft Access automatically wraps subsequent lines as you type. To manually insert a line break on a subsequent line, press CTRL+ENTER again. The maximum width of the label is determined by the length of the first line of text.

•	If you want to use an ampersand (&) in a label, you must type two ampersands. This is because Microsoft Access uses the ampersand in a label or button to define an access key.


Attach a label to a control

1	Click the label that you want to attach to a control.

2	Click  [image]  on the toolbar.

3	Click the control you want to attach the label to.

4	Click  [image]  on the toolbar.


Specify whether attached labels have a colon when you create a type of control

You can use this procedure to change the default control style for the current form or report. If you want to change the default control style for all forms and reports, click  [image].

1	In form or report Design view, click the tool in the toolbox that you want to set defaults for. For example, if you want to remove colons from labels attached to text boxes, click  [image].

2	Click  [image]  on the toolbar to display the property sheet for the tool.

3	In the AddColon property box, click Yes or No.


Specify whether labels are automatically attached to new controls

You can use this procedure to change the default control style for the current form or report. If you want to change the default control style for all forms and reports, click  [image].

1	In form or report Design view, click the tool in the toolbox that you want to set defaults for. For example, if you want to specify whether labels are automatically attached to text boxes, click  [image].

2	Click  [image]  on the toolbar to display the property sheet for the tool.

3	In the AutoLabel property box, click Yes or No.


What is a text box?

You use text boxes on a form or report to display data from a table, query, or SQL statement. This type of text box is called a bound text box because it's bound to data in a field. Text boxes can also be unbound. For example, you can create an unbound text box to display the results of a calculation, or to accept input from a user. Data in an unbound text box isn't stored anywhere.


Create a text box

How you create a text box depends on whether you want it to be bound, unbound, or calculated.

What do you want to do?

Learn more about bound, unbound, and calculated controls

Create a bound text box

Create an unbound text box

Create a calculated text box


Create a bound text box

1	In form or report Design view, click  [image]  on the toolbar to display the field list.

2	Select one or more fields in the field list.

To select	Do this
One field	Click the field.
A block of  fields	Click the first field in the block, hold down the SHIFT key, and then click the last field in the block.
Nonadjacent  fields	Hold down the CTRL key and click the name of each field you want to include.
All fields	Double-click  the field list title bar.
3	Drag the fields from the field list and position them on the form or report.

Note   You must drag the fields from the field list. If you click the fields in the field list and then click the form or report, Microsoft Access won't create the control.

Microsoft Access places one text box on the form or report for each field you select in the field list. Each text box is bound to one field in the form or report's underlying data source. Each text box also has an attached label by default.

4	Size the text boxes so that they're the appropriate size for the data you want to show.

5	Change the label text, if necessary.

6	Switch to Form view, Datasheet view, or Print Preview to test the controls.

Notes

•	Some text boxes (text boxes bound to Memo fields, for example) can contain entries of various lengths. Although you can scroll through them to see all the data in Form view, you probably want the entire value printed when you print the form or report. You can automatically resize the control when you print by setting the CanGrow and CanShrink properties of the text box to Yes. These properties have no effect on the size of the text box when you look at data in Form view.

•	For text boxes on forms that have many lines of text, you may want to add a vertical scroll bar.

How?


Create an unbound text box

1	In form or report Design view, click  [image]  in the toolbox.

2	Click anywhere on the form or report to create a default-sized text box, or drag to create a text box that's the size you want.


Create a check box, toggle button, or option button

How you create a check box, option button, or toggle button depends on whether you want it to be: a stand-alone control that's bound to a Yes/No field; a control that's part of an option group; or an unbound control.

What do you want to do?

Read about check boxes and how they work

Read about toggle buttons and how they work

Read about option buttons and how they work

Read about option groups and how they work

Create a check box, toggle button, or option button that's bound to a Yes/No field

Create an option group and add check boxes, toggle buttons, or option buttons to the option group

Create an unbound check box, option button, or toggle button


What is a check box?

You can use a check box on a form or report as a stand-alone control to display a Yes/No value from an underlying table, query, or SQL statement. For example, the check box in the following illustration is bound to the Discontinued field in the Products table. The data type of the Discontinued field is Yes/No. If the box contains a check mark, the value is Yes; if it doesn't, the value is No.

When you select or clear a check box that's bound to a Yes/No field, Microsoft Access displays the value in the underlying table according to the field's Format property (Yes/No, True/False, or On/Off).

You can also use check boxes in an option group to display values to choose from. For more information on option groups, click  [image].

You can also use an unbound check box in a custom dialog box to accept user input.


Create a check box, toggle button, or option button that's bound to a Yes/No field

1	In form or report Design view, click the appropriate tool in the toolbox. If you're not sure which tool to use, place the pointer over the tool until the ToolTip appears.

2	Click  [image]  on the toolbar to display the field list.

3	Click the appropriate field (a field with a Yes/No data type) in the field list and drag it to the form or report.

Note   You must drag the field from the field list. If you click the field in the field list and then click the form or report, the control won't be bound.

4	Change the label text, if necessary.

5	Switch to Form view, Datasheet view, or Print Preview to test the control.

Tip   If you often display the same Yes/No field as a check box on different forms and reports, you can set the DisplayControl property of the field so that when you drag it from the field list, it automatically creates a check box (you don't have to click the Check Box tool first). For more information, click  [image].


Create an unbound check box, option button, or toggle button

1	In form or report Design view, click the appropriate tool in the toolbox. If you're not sure which tool to use, place the pointer over the tool until the ToolTip appears.

2	On the form or report, click where you want to place the control. If you're placing the control in an option group, Microsoft Access highlights the option group when you move the pointer over it to show that the control will become part of the option group.


What is a toggle button?

You can use a toggle button on a form as a stand-alone control to display a Yes/No value from an underlying table, query, or SQL statement. For example, the toggle button in the following illustration is bound to the Discontinued field in the Products table. The data type of the Discontinued field is Yes/No. When the button is pressed in, the value in the Products table is Yes. When the button isn't pressed in, the value in the Products table is No.

When you click a toggle button that's bound to a Yes/No field, Microsoft Access displays the value in the underlying table according to the field's Format property (Yes/No, True/False, or On/Off).

Toggle buttons are most useful when used in an option group with other buttons. In an option group, you can easily tell whether a button is pressed in. For more information on option groups, click  [image].

You can use pictures on toggle buttons instead of text. For example, instead of displaying the word "Discontinued" on the toggle button in the first example, you could display a picture of a trash can.

You can also use a toggle button in a custom dialog box to accept user input.


What is an option button?

You can use an option button on a form or report as a stand-alone control to display a Yes/No value from an underlying table, query, or SQL statement. For example, the option button in the following illustration is bound to the Discontinued field in the Products table. The data type of the Discontinued field is Yes/No. If the option button is selected, the value is Yes; if not, the value is No.

When you select or clear an option button that's bound to a Yes/No field, Microsoft Access displays the value in the underlying table according to the field's Format property (Yes/No, True/False, or On/Off).

You can also use option buttons in an option group to display values to choose from. For more information on option groups, click  [image].

You can also use an unbound option button in a custom dialog box to accept user input.


What is an option group?

You can use an option group on a form or report to display a limited set of alternatives. An option group makes selecting a value easy since you can just click the value you want. Only one option in an option group can be selected at a time.

An option group consists of a group frame and a set of check boxes, option buttons, or toggle buttons.

If an option group is bound to a field, only the group frame itself is bound to the field, not the check boxes, toggle buttons, or option buttons inside the frame. Instead of setting the ControlSource property for each control in the option group, you set the OptionValue property of each check box, toggle button, or option button to a number that's meaningful for the field the group frame is bound to. When you select an option in an option group, Microsoft Access sets the value of the field to which the option group is bound to the value of the selected option's OptionValue property.

Note   The OptionValue property is set to a number because the value of an option group can only be a number, not text. Microsoft Access stores this number in the underlying table. In this example, if you want to display the name of the shipper instead of a number in the Orders table, you can create a separate table called Shippers that stores shipper names, and then make the ShipVia field in the Orders table a Lookup field that looks up data in the Shippers table. For more information on creating a Lookup field, click  [image].

An option group can also be set to an expression, or can be unbound. You can use an unbound option group in a custom dialog box to accept user input and then carry out an action based on that input.


Create an option group that contains check boxes, toggle buttons, or option buttons

You can create an option group on your own or you can have Microsoft Access create your option group for you using a wizard. A wizard speeds up the process of creating an option group because it does all the basic work for you. When you use a wizard, Microsoft Access prompts you for information and creates an option group based on your answers.

Tip   If you want to present more than a few options, use a list box or a combo box instead of an option group.

What do you want to do?

Read about option groups and how they work

Create an option group with a wizard

Create an option group on my own


Create an option group with a wizard

For best results, create option groups only for fields whose data type is Number (and whose FieldSize property is set to Integer or Long Integer) or Yes/No. For fields with other data types, use a list box or combo box.

1	In form or report Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form or report, click where you want to place the upper-left corner of the option group.

4	Follow the directions in the wizard dialog boxes. In the last dialog box, choose the Finish button to display the option group in Design view.


Create an option group without a wizard

1	In form or report Design view, click  [image]  in the toolbox if it's pressed in. This turns off the wizard.

2	In the toolbox, click  [image].

3	Do one of the following:

•	If you want to create an unbound option group, click where you want to place the group frame.

•	If you want to create a bound option group, click  [image]  on the toolbar to display the field list, and then drag the appropriate field from the field list to the form or report.

Note   You must drag the field from the field list. If you click the field in the field list and then click the form or report, the control won't be bound.

4	In the toolbox, click  [image],  [image], or  [image], and then click inside the group frame where you want the upper-left corner of the option button, check box, or toggle button to appear. When the mouse pointer is over the frame, Microsoft Access highlights the option group to indicate that controls placed within it become part of the option group.

When Microsoft Access creates the first control inside an option group, it sets the control's OptionValue property to 1.

5	Repeat step 4 for each control you add to the option group. Microsoft Access sets the OptionValue property of the second option to 2, the third to 3, and so on.

Notes

•	For information on aligning the controls in the group frame to each other, click  [image]. For information on spacing controls evenly, click  [image].

•	To facilitate data entry, you can make the most commonly chosen option the default.

How?

•	If you create an option button, check box, or toggle button outside an option group and you want to add that control to an option group, you must cut and paste the control into the option group (select the option group frame before you paste). When you cut and paste, Microsoft Access sets the OptionValue property for the control to -1 so you must reset the property to the value you want. If you drag an existing control into a group frame, the control doesn't become part of the option group.


What is a command button?

You use a command button on a form to start an action or a set of actions. For example, you could create a command button that opens another form. To make a command button do something, you write a macro or event procedure and attach it to the button's OnClick property.

Note   You can create over 30 different types of command buttons with the Command Button Wizard. When you use the Command Button Wizard, Microsoft Access creates the button and the event procedure for you.

You can display text on a command button by setting its Caption property, or you can display a picture by setting its Picture property.


Create a command button

You can create a command button on your own or you can have Microsoft Access create your command button for you using a wizard. A wizard speeds up the process of creating a command button because it does all the basic work for you. When you use a wizard, Microsoft Access prompts you for information and creates the command button based on your answers.

You can create over 30 different types of command buttons using the Command Button Wizard. For example, you can create a command button that finds a record, prints a record, or applies a form filter.

It's also a good idea to use the Command Button Wizard if you want to learn how to write event procedures. When Microsoft Access creates a command button with a wizard, it creates an event procedure and attaches it to the button. You can open the event procedure to see how it works and modify it to fit your needs.

What do you want to do?

Create a command button with a wizard

Create a command button on my own


Create a command button with a wizard

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.


Create a command button without a wizard

1	In form Design view, click  [image]  in the toolbox if it's pressed in. This turns off the wizard.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	Double-click the command button to open its property sheet.

5	In the OnClick property box, enter the name of the macro or event procedure that you want to run when the button is clicked, or click the Build button to use the Macro Builder or Code Builder.

6	If you want to display text on the command button, type the text in the Caption property box. If you don't want text on the button, you can use a picture instead.

How?

Tip   You can also create a command button that runs a macro by dragging the macro from the Database window to form Design view.

For an overview of events and event procedures, click  [image].


Create a command button that finds a record

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Record Navigation in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that adds, deletes, duplicates, prints, saves, or undoes a record

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Record Operations in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that edits or applies a filter

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Form Operations in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that opens and synchronizes a form, closes a form, or prints a form

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Form Operations in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that updates form data

If you're using a database that's shared on a network, you can view the latest version of existing records by creating a command button that updates form data. If you want to display all the updated records, including new ones, you can requery the records. For more information about requerying records, click  [image].

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Form Operations in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that prints a report, sends it to a file, or mails it

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Report Operations in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that runs an application or quits an application

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Application in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that prints a table

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Miscellaneous in the Categories box, and then click Print Table in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that runs a query or a macro

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Miscellaneous in the Categories box, and then click the type of button you want to create in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Create a command button that dials a phone number

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Miscellaneous in the Categories box, and then click AutoDialer in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, click the Build button in the OnClick property for the command button.


Add a picture to a command button or a toggle button

1	Double-click the command button or toggle button to open its property sheet.

2	In the Picture property box, type the path and filename for a .bmp, .ico, .dib, .wmf, or .emf file. If you've installed graphics filters for other applications, you can use any file supported by those filters. If you're not sure of the path or filename, click the Build button to open the Picture Builder.

Tip   If you want to add a picture and a caption to a command button, you can create the picture and caption in Windows Paint. To create a picture the size of your button using Paint, draw the picture on a background of any size, and then select only the portion that will fit on your button. On the Edit menu, click Copy To and specify a filename in the Save As dialog box. This creates a file with a picture the exact size that you selected.


Make a command button a Cancel button

1	Double-click the command button to open its property sheet.

2	In the Cancel property box, click Yes.

When a command button's Cancel property is set to Yes and the form is the active form, you can choose the command button by clicking it, by pressing the ESC key, or by pressing ENTER when the command button has the focus. When the Cancel property is set to Yes for one command button, it's automatically set to No for all other command buttons on the form.

Tip   For a form that allows irreversible operations, such as deletions, it's a good idea to make the Cancel button the default command button. To do this, set both the Cancel property and the Default property to Yes.


Make a command button the default button in a form or custom dialog box

1	Double-click the command button to open its property sheet.

2	In the Default property box, click Yes.

When a command button's Default property is set to Yes and the form is the active form, you can choose the command button by clicking it or by pressing ENTER when no other command button has the focus. When the Default property is set to Yes for one command button, it's automatically set to No for all other command buttons on the form.

Tip   For a form that allows irreversible operations, such as deletions, it's a good idea to make the Cancel button the default command button. To do this, set both the Cancel property and the Default property to Yes.


Hide a command button

1	Double-click the command button to open its property sheet.

2	In the Transparent property box, click Yes.

Microsoft Access hides the command button, but it's still active.

Tip   To hide and disable a button, set the Visible property to No. To disable a button without hiding it, set the Enabled property to No. To hide a button only when a form or report is printed, set the DisplayWhen property to Screen Only.


Create a calculated control

1	In form or report Design view, click the tool in the toolbox for the type of control you want to use as the calculated control.

Note   A text box is the most common type of control to use to display a calculated value, but you can use any control that has a ControlSource property.

2	On the form or report, click where you want to place the control.

3	Do one of the following:

•	If the control is a text box, you can type the expression directly in the control.

•	If the control isn't a text box, or if the control is a text box but you want to use the Expression Builder to create the expression, double-click the control to open its property sheet, and then type the expression in the ControlSource property box or click the Build button to open the Expression Builder.

Notes

•	In a calculated control, precede each expression with the = operator.

•	If you need more room to type an expression in the ControlSource property box, press SHIFT+F2 to open the Zoom box.

•	For more information on creating expressions, click  [image].

•	If a form is based on a query, you may want to put the expression in the query instead of in a calculated control. For information on creating a calculated field in a query, click  [image].


Calculate a total for one record in a form

1	In form Design view, click  [image]  in the toolbox.

2	In the form's detail section, click where you want to place the text box.

3	Do one of the following:

•	Place the insertion point in the text box and type an expression that calculates a total. To see examples of expressions you can use to compute values for one record, click  [image].

•	Double-click the text box to open its property sheet, and type the expression in the ControlSource property box. To use the Expression Builder to create the expression, click the Build button next to the ControlSource property box.

Notes

•	If you need more room to type an expression in the ControlSource property box, press SHIFT+F2 to open the Zoom box.

•	For information on creating expressions, click  [image].

•	If a form is based on a query, you may want to put the expression in the query instead of in a calculated control. For information on creating a calculated field in a query, click  [image].


Calculating a total in a subform and displaying it on a form

You can use a form with a subform to calculate a total for a group of records. The main form and the subform are based on tables with a one-to-many relationship. The main form shows records from the "one" side of the relationship; the subform shows records from the "many" side of the relationship. For example, the following illustration shows an Orders form that includes a subform.

To calculate the order subtotal, you add a text box to the form footer of the subform and specify an expression in the ControlSource property box for the text box. The expression uses the Sum function. For example, the following expression calculates the total amount for all the products in the Orders form:

=Sum([Quantity]*[UnitPrice])

To display the order subtotal on the main form, create a text box on the main form that uses an expression to refer to the control on the subform that contains the calculated value. For example, you could specify the following expression in the ControlSource property box of the text box on the main form:

Notes

•	If you want to use the value from a calculated control when computing a total, you can't use the name of the control in the Sum function. For example, if you had a control that calculated quantity * unit price, you'd still have to specify the full syntax =Sum([Quantity]*[UnitPrice]) in the expression. For this reason, when you use an expression that requires an aggregate function such as Sum, it's best to define the expression in the form's underlying query or SQL statement. Then you can use the name of the calculated field in the Sum function. For example, you could define a calculated field such as ExtendedPrice: [Quantity]*[UnitPrice] in an underlying query, and then use the field name in the expression that calculates the sum: =Sum([ExtendedPrice]). For information on creating a calculated field in a query, click  [image].

•	The Orders form in the Northwind sample database has an example of a subform that calculates a subtotal that's displayed on the main form. To view this form, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Forms tab, click Orders, and then click Design. To open the subform in Design view, double-click the subform control in the main form, or open it directly in the Database window. For information on opening Northwind, click  [image].

•	For information on creating subforms, click  [image].


Validate or restrict data in forms

There are many different ways to restrict or validate data in forms. The most obvious way is to create controls that by their nature limit the values that can be entered. For example, you can create a check box that accepts only Yes/No values or a list box that requires you to pick from a list of previously entered values.

You can also limit or restrict data entry by setting control properties and form properties. To see a list of the properties you can set, and where you can set them, click  [image].

In most cases, you set the DefaultValue, ValidationRule, ValidationText, and InputMask properties in table Design view. This way, you only have to set the properties once. Any bound control that you create inherits properties set for the field in table Design view. If the controls on your form are unbound, however, or if you're linking to data in attached tables, you may want to set these properties in the form. You may also want to set the ValidationRule property for a control if a validation rule refers to fields or controls in other forms, or if the validation rule contains domain aggregate functions, aggregate functions, user-defined functions, or the CurrentUser or Eval function.

In most cases, you can validate or restrict data using properties that you set in table Design view or in forms. In certain cases, however, you may need to create macros or event procedures for additional power and flexibility. For example, you may want to display different error messages for different types of errors in a field, or you may want to verify that any two of three fields are filled in before saving a record.

What do you want to do?

Set the ValidationRule, DefaultValue, or InputMask property for the field instead of the control

Assign a default value for a control

Create a validation rule for a control

Read about the order in which different kinds of validation are applied

Create an input mask for a control

Disable or lock a control

Make a form read-only

Specify whether a user can edit saved records with a form

Specify whether a user can add or delete a record with a form

Specify whether a form opens for data entry (blank record) or for editing

Read about complex validation you can do with macros or event procedures


Properties you can use to restrict or validate data in forms

The following table lists properties you can use to restrict or validate data in forms, and where you can set the properties.

Property	Description	Where set
DefaultValue	Enters a default value in a control for new records. For example, you can set the default value of a Date text box to the current date.	In table Design view or in the property sheet for the control
ValidationRule	Specifies a validation rule. If the data entered doesn't satisfy the validation rule, Microsoft Access displays the text specified in the ValidationText property.	In table Design view or in the property sheet for the control
InputMask	Helps you enter data in the correct format. For example, you can create an input mask that displays parentheses, spaces, and hyphens for a phone number field, so you can just fill in the blanks.	In table Design view or in the property sheet for the control
Enabled, Locked	The Enabled property determines whether a control can have the focus in Form view. The Locked property determines whether a control allows changes to data in Form view.	In the property sheet for the control
AllowEdits	Determines whether a user can edit saved records using a form.	In the property sheet for the form
AllowAdditions	Determines whether a user can add a record using a form.	In the property sheet for the form
AllowDeletions	Determines whether a user can delete a record using a form.	In the property sheet for the form
DataEntry	Determines whether a form opens for data entry (blank record) or with all records showing.	In the property sheet for the form


Assign a default value to a control

1	In form or report Design view, double-click the control to open its property sheet.

2	In the DefaultValue property box, type the default value, such as New York, or an expression, such as =Date(). If you need help creating an expression, click the Build button to open the Expression Builder.

Note   If you set the DefaultValue property for a field in table Design view and also set the DefaultValue property for a control bound to that field, the default value set for the control overrides the default value set for the field.


Create a validation rule for a control

1	In form or report Design view, double-click the control to open its property sheet.

2	In the ValidationRule property box, type the validation rule, or click the Build button to use the Expression Builder to create the validation rule.

To see examples of validation rules, click  [image].

3	In the ValidationText property box, type the error message that you want displayed if the text entered violates the validation rule.

Notes

•	If you need more room to type in a property box, press SHIFT+F2 to open the Zoom box.

•	If you set the ValidationRule property for the field in table Design view and also set the ValidationRule property for a control bound to that field, Microsoft Access enforces both rules — the control validation rule doesn't override the field validation rule.

•	Microsoft Access validates a field when you change data and try to leave the field, save the record, switch views, or close the form.


Create an input mask for a control

1	In form or report Design view, double-click the control to open its property sheet.

2	Do one of the following:

•	In the InputMask property box, click the Build button to start the Input Mask Wizard, and then follow the instructions in the wizard dialog boxes.

•	Type the input mask definition. For information on how to define an input mask, click  [image].


Specify whether a user can add or delete a record with a form

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the AllowDeletions and/or the AllowAdditions property boxes, click Yes or No.


Make a form read-only

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the AllowEdits property box, click No.

3	In the AllowAdditions property box, click No.

4	In the AllowDeletions property box, click No.

Note   If you want the form to open for data entry (blank record), set the DataEntry property to Yes.


Disable Form view or Datasheet view for a form

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the ViewsAllowed property box, click Form to disable Datasheet view, or click Datasheet to disable Form view.

Note   You can use this property together with the DefaultView property to determine how users see a form and whether they can see it in different views. To see different combinations of these properties, click  [image].


Specify whether a user can edit saved records with a form

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the AllowEdits property box, click Yes or No.


Specify whether a form opens for data entry only or with all records showing

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the DataEntry property box, click Yes if you want the form to open for data entry (blank record); click No if you want the form to open with all records showing.


What's new in Microsoft Access for Windows 95?

What area do you want to read about?

Getting Help while you work

New wizards, builders, and add-ins

Designing a database

Working in the Database window

Creating and customizing tables

Working with data

Creating and customizing queries

Creating and customizing forms and reports

Printing

Working with other applications

Using and customizing toolbars

Securing and administering a database

Developing applications


What's new with form and report design?

Microsoft Access for Windows 95 provides many new features to make it faster and easier to create great-looking forms and reports.

Creating and Formatting Forms and Reports

•	New Form and Report Wizards. Want to create a multiple-table form or report, but don't want to create a query? With the new Form and Report Wizards, you don't have to create a query beforehand — the field picker in the wizard allows you to select fields from any table in your database. With the new Form Wizard, it's easy to create a form with a subform or link a form to another form. You can even create a form that includes two subforms. You just specify the data that you want and Microsoft Access presents you with the options. Likewise, with the new Report Wizard, it's easy to create reports that group or total data. Just tell the wizard what you want to do and let it do the rest.

•	New Subform/Subreport Wizard. If you want to add a subform to an existing form, or a subreport to an existing report, you can use the new Subform/Subreport Wizard. Just click  [image]  in the toolbox, click your form or report, and away you go. (You can also launch the wizard by dragging a form or report from the Database window to a form or report that's open in Design view.) Or if you're having trouble linking a main form and a subform, or a main report and subreport, use the new Subform/Subreport Field Linker. For more information, click  [image].

•	Inherited Filters. Want to create a form or report from a table or query you've already filtered? With the filtered records displayed, just click the New Object button on the toolbar, and then click one of the form or report options. The new form or report uses the table or query as its record source and inherits the filter. For more information, click  [image].

•	AutoFormat. Don't like the look of your form or report? Change it quickly by clicking the AutoFormat button. When you click  [image], Microsoft Access provides you with a variety of predefined formats to choose from. You can use the AutoFormat button to change the look of your whole form or report or just selected controls. You can also customize the predefined formats or create your own.

•	Background Pictures. Want to add a logo or other picture to the background of your form or report? Just enter a path in the Picture property box for the form or report, or select a picture using the Picture Builder. With Microsoft Access 95, you can also make more controls transparent so your background pictures show through.

•	Formatting Toolbar. The new Formatting toolbar puts many formatting tasks at your fingertips. For example, you can add a background color to a section or apply a special effect to a control with just a few clicks of the mouse.

•	Grouping Records on Reports. When you print a grouped report, the detail records for a group might continue onto another page or column. You can specify whether you want the records in groups kept together by page or by column by using the report's GrpKeepTogether property. You can also repeat a group header at the top of the next page or column by setting the group header's RepeatSection property to Yes.

Creating and Formatting Controls

•	Default Controls for Fields. You can use the new DisplayControl table or query property to specify a default type of control (text box, check box, list box, or combo box) for a field. When you drag that field from the field list, or if you use a wizard to create a form or report, Microsoft Access automatically creates the right type of control.

•	New Lookup Wizard. Need help creating a list on a form that looks up values from another table? Use the new Lookup Wizard. You can run the wizard in table Design view by specifying Lookup Wizard as the data type for the field. Or you can click Lookup Column on the Insert menu in Datasheet view. When you run the wizard, Microsoft Access walks you through the process of creating a lookup list. When you add that field to a form, Microsoft Access automatically creates a list box or combo box (depending on which control you select in the wizard) with the appropriate properties set for you.

•	Improved List Box and Combo Box Wizards. If you want to create a list box or combo box that finds a record, it's easy to do with the improved List Box and Combo Box Wizards. In form Design view, make sure  [image]  is pressed in in the toolbox, click  [image]  or  [image], and then click the location on your form where you want to place the list box or combo box.

•	Change Controls Dynamically. Want to change a text box to a combo box? Or maybe you want to change a check box to an option button? You don't need to delete the control and start over—just click Change To on the Format menu, and click the type of control you want to change it to. Microsoft Access copies the appropriate properties from one control to the other so you don't have to specify them again.

•	Format Painter. Want to copy formatting characteristics from one control to another? Just click the control you want to copy formatting characteristics from, click  [image]  on the toolbar, and then click the control you want to copy them to.

•	ScreenTips. Want to create a custom tip on a form that pops up when you place the mouse pointer over a control? Just enter the message you want to display in the ControlTipText property box for the control. Or you might want to create a custom tip that pops up when you click  [image]  and then click a form, report, or control. For more information, click  [image].

•	New Special Effects. Create great-looking Windows 95 forms and reports with the new settings for the SpecialEffect property. With Microsoft Access 95, you can create etched, shadowed, or chiseled effects in addition to the version 2.0 special effects (flat, raised, and sunken).

•	Page Number or Date/Time Controls. Want to add a control to display a page number or a date? Just click the Page Number command or the Date And Time Command on the Insert menu and specify the options you want.

•	New PivotTable Wizard. With the new PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and calculation method that you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data. (To take advantage of this wizard, you need to have Microsoft Excel installed.) For information on creating a PivotTable, click  [image].

•	Improved Chart Wizard. With the improved Chart Wizard, it's much easier to create a chart for a form or report. For information on creating a chart, click  [image].

•	Drag and Drop Objects. With Microsoft Access 95, you can drag OLE objects to Form view to add a bound object or to form Design view or report Design view to add an unbound object. (The object application you're dragging from must have support for drag and drop.) You can also drag a query or table datasheet from the Database window to a form or report to create a subform or subreport displayed in Datasheet view.

•	Custom Controls. It's easy to add custom controls to your forms and reports with Microsoft Access 95. Just click Custom Controls on the Insert menu, and then click the control you want to insert.

Performance

•	New Image Control. If you want to display unbound pictures on your forms and reports, use an image control. Just click  [image]  in the toolbox, and click the location on the form or report where you want to place the picture. Image controls display pictures much faster than unbound object frames do. However, you can't double-click the picture to edit it if you use an image control.

•	Faster Combo Boxes. You'll notice that combo boxes on forms in Microsoft Access 95 work faster than combo boxes in version 2.0.

•	Faster Report Previewing. Previewing reports is faster because events are triggered only the first time you page through a report.

•	Performance Analyzer. Have Microsoft Access analyze your form's or report's objects (or any other objects) to make sure they're as fast as they can be. To run the Performance Analyzer, point to Analyze on the Tools menu, and then click Performance.

New, Changed, and Deleted Properties and Other Language Elements

For information on new, changed, and deleted form or report properties or other language elements, click  [image].


Example of a multiple-table flat form


Example of a multiple-table hierarchical form


Example of synchronized forms


Example of a modeless pop-up form


Example of a custom dialog box


Sample databases and applications included with Microsoft Access

Microsoft Access provides a sample database and two sample applications that you can use while you're learning Microsoft Access:

•	Northwind Traders sample database. Use this sample database when you're first learning Microsoft Access. The Northwind database contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. By viewing the tables, queries, forms, reports, macros, and modules included in the Northwind database, you can develop ideas for your own Microsoft Access database. You can also use the Northwind data to experiment with Microsoft Access before you enter your own data. For example, you may want to practice designing queries using the Orders table since it contains enough records to produce meaningful results.

•	Orders sample application. The Orders sample application is an instructional aid for Building Applications with Microsoft Access for Windows 95. Use this application with Building Applications to learn how to create a simple application.

Employees at the fictitious Northwind Traders company use the Orders application to enter new orders and print invoices. The application shows several application-building techniques, including: controlling how an application starts; using forms to tie objects together; customizing the user interface with custom menu bars, toolbars, shortcut keys, and error messages; and controlling the tab order at run time.

The Orders application includes a Help file called Show Me that describes how to reproduce the forms and reports included in the application.

•	Solutions sample application. Use this application to learn more complex application-building techniques. The Solutions sample application is a collection of the forms, reports, and interface elements you most commonly use to create applications. You can use the examples in Solutions as templates for the forms and reports you want to create or as ideas for improving your applications. The Solutions application includes a Help file called Show Me that describes how to reproduce the forms and reports included in the application.

For information on opening Northwind, Orders, or Solutions, click  [image].


Open the Northwind, Orders, or Solutions sample databases

1	If you haven't already done so, install the sample database.

Note   If you chose the Typical installation when you installed Microsoft Access, you already have the Northwind database installed on your system. You won't have the Solutions or Orders applications on your system unless you chose the Complete installation and specified these applications. For information on running Setup again to install Northwind, Orders, or Solutions, click  [image].

2	Start Microsoft Access.

3	In the opening dialog box, click Open An Existing Database, and then click OK.

4	In the Open dialog box, use the Look In box to locate the Samples folder. This folder is usually in the MSOffice\Access folder.

5	Double-click the Samples folder, and then double-click Northwind, Orders, or Solutions.

Notes

•	If you already have another database open in Microsoft Access, you can click the Open Database command on the File menu in any window to open a different database. Microsoft Access closes the current database when it opens another database.

•	For information on Northwind, Orders, or Solutions, click  [image].


Rerun the Setup program to add or remove a component

1	Insert Disk 1 of the Microsoft Access disks in your disk drive. (If you purchased the CD-ROM version of Microsoft Access, insert the CD-ROM disc in your CD-ROM drive.)

2	Click the Windows Start button, and then click Run.

3	Type drive:setup.exe, and then click OK. For example, if you inserted Disk 1 in your A drive, type a:setup.exe. If you're installing from a network drive, click the Browse button, and then use the Look In box to locate the Setup file.

4	In the Setup program, click the Add/Remove button, and then click the component you want to add or remove.


Disable the Close button on a form

1	In form Design view, double-click the form selector to open the property sheet.

2	In the CloseButton property box, click No.

Notes

•	When you set the CloseButton property to No, Microsoft Access disables the Close button and removes the Close command from the Control menu.

•	If you want to remove the Close button completely, you may want to use the BorderStyle property. For more information, click  [image].


Hide section divider lines in a form

1	In form Design view, double-click the form selector to open the property sheet.

2	In the DividingLines property box, click No.


 Hide record divider lines in a continuous form

1	In form Design view, double-click the form selector to open the property sheet.

2	In the DividingLines property box, click No.


Hide a section or control on a form or report

1	In form or report Design view, double-click the section selector or the control to open the property sheet for the section or control.

2	In the Visible property box, click No.

Notes

•	To hide or unhide a control in response to an event, you can use a macro or event procedure to set the Visible property. Attach the macro or event procedure to the OnCurrent property of a form or the OnFormat property of a report. For example, you can show or hide a congratulatory message next to a salesperson's monthly sales total in a sales report, depending on the sales total.

•	For form sections, the Visible property has no effect on a column in Datasheet view. To specify whether a column is visible in Datasheet view, use the ColumnHidden property.

•	To hide an object on a form only when printing, use the DisplayWhen property.


Move two or more controls at the same time

1	Select the controls by holding down the SHIFT key as you click each control. (You can also drag over adjacent controls to select them.)

2	Pass the pointer over the border (not the move handle) of any selected control until it turns into an open hand, and then drag the controls to a new position.


Should I use a bitmap or a metafile to display a picture on a form or report?

You can use bitmap files (.bmp or .dib extensions) or metafiles (.wmf or .emf extensions) to display background pictures or pictures in bound or unbound object frames or image controls.

When to use metafiles

•	If you need to adjust the size of your picture, it's better to use a metafile. Metafiles scale better than bitmaps because they're made up of collections of lines rather than patterns of individual dots.

•	Metafiles are usually much smaller than bitmaps, so if you need to conserve disk space, use a metafile.

Many graphics programs allow you to save files as metafiles. See the documentation that came with your graphics program for details. Note that if you paste a bitmap into a graphics program and save it as a metafile, it will still be a bitmap—it's just embedded in the metafile. You must create the graphic in the graphics program and save it as a metafile.

When to use bitmaps

•	If scaling and disk space aren't concerns, or if you don't have access to a tool that creates metafiles, use a bitmap.

•	If you want to create a tiled background picture, a bitmap will work well since it won't be scaled.

•	If you want to be able to make small changes to the picture, use a bitmap. With bitmaps you have pixel-level control, so you can make very small adjustments to the picture.

Note   If you need to adjust the size of a picture, set the PictureSizeMode property (background pictures) or the SizeMode property (bound object frames, unbound object frames, and image controls) to Zoom. When you set the PictureSizeMode or SizeMode property to Zoom, Microsoft Access retains the proportions of the picture when you size the form or control.


Example of changing the color of a control based on the value entered in the control

The Edit Products form in the Solutions sample application has an example of changing the color of a control based on the value entered in the control. This example uses event procedures. You can copy these event procedures to your database and customize them to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Work with forms and controls. In the lower list box, click the entry that reads: Change the color in a control based on the value in the control.

For information on opening the Solutions sample application, click  [image].


Example of changing the color of a section and control at run time

The Enter or Edit Products form in the Solutions sample application has an example of changing the color of a section and control at run time. This example uses a user-defined function and an event procedure. You can copy this function and event procedure to your database and customize them to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Work with forms and controls. In the lower list box, click the entry that reads: Change the color of a section and control at run time.

For information on opening the Solutions sample application, click  [image].


Example of a form that switches between editing and data entry modes

The Enter or Edit Products form in the Solutions sample application is an example of a form you can use to switch between editing and data entry modes. The form includes toolbar buttons that you can use to switch modes.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Work with forms and controls. In the lower list box, click the entry that reads: Create a form in which you can enter or edit data.

For information on opening the Solutions sample application, click  [image].


Example of updating (requerying) a list to display the most current data

The Edit Products form in the Solutions sample application has an example of updating a list to display the most current data. This example uses an event procedure. You can copy this event procedure to your database and customize it to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Work with forms and controls. In the lower list box, click the entry that reads: Update a list to show current data.

For information on opening the Solutions sample application, click  [image].


Example of a list box that allows you to select more than one entry

The Limit List Contents form in the Solutions sample application has an example of a multiple-selection list box. This example uses event procedures. You can copy these event procedures to your database and customize them to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Create a list box that allows you to select and manipulate multiple objects.

For information on opening the Solutions sample application, click  [image].


Open the Macro or Module window from a form or report

1	In form or report Design view, do one of the following:

•	Double-click the form selector or report selector to open the property sheet for the form or report.

•	Double-click the section selector to open the property sheet for the section.

•	Double-click a control to open a property sheet for the control.

2	Click the Build button next to the appropriate event property. For example, if you want to create a macro or event procedure that will run when you click a command button, click the Build button next to the command button's OnClick event property.

3	Click Macro Builder to open the Macro window or Code Builder to open the Module window.

Note   If you want to be able to view all the code behind a form or report, click Code on the View menu.


Have Microsoft Access automatically dial a selected phone number

You must have a working Hayes or Hayes-compatible modem to use this procedure.

1	On the View menu, click Toolbars.

2	In the Toolbars dialog box, click the Customize button.

3	In the Customize Toolbars dialog box, click Records in the Categories list.

4	Drag  [image]  to the Form View or Datasheet View toolbar, or to a custom toolbar.

5	Click Close.

6	In the form or datasheet, select the phone number you want to dial.

7	Click  [image]  on the toolbar.

8	Check to see that the phone number is entered correctly, and then click OK.

Notes

•	If you use a prefix to connect to an outside line, type the prefix in the Prefix box, and select the Use Prefix check box.

•	You can change your modem options by clicking Setup in the AutoDialer.


Create a datasheet subform that includes headers and footers

1	In Design view of the form that you want to use as the subform, add the fields that you want to display in the subform.

2	Size the detail section of the form to the size of one row in a datasheet.

3	Double-click the form selector to open the property sheet for the form.

4	In the DefaultView property box, click Continuous Forms.

Note   Don't select the Datasheet setting if you want to display a header and footer in a subform. When you select the Datasheet setting, Microsoft Access hides the header and footer when you display the form in Form view. When you set the DefaultView property to Continuous Forms and size the form to display just one row, the form looks like a datasheet, but it can display headers and footers.

To see an example of this type of form, see the Quarterly Orders form and subform in the Northwind sample database. For information on opening the Northwind database, click  [image].


Optimizing form and subform performance

There are several things you can do to make your forms run faster. In addition to the tips listed below, you can use the Performance Analyzer to analyze specific forms in your database. For information on using the Performance Analyzer, click  [image].

Performance Tips

•	Avoid overlapping controls.

•	Use bitmaps and other graphic objects sparingly.

•	Convert unbound object frames that display graphics to image controls.

•	Use black-and-white rather than color bitmaps.

•	Close forms that aren't being used.

•	If the underlying record source includes many records and you want to use the form primarily to enter new records, set the DataEntry property of the form to Yes so that the form opens to a blank record. If you open a form with all records showing, Microsoft Access has to read in each record before it can display the blank record at the end of the recordset. If the form is already open, you can click Data Entry on the Records menu to switch to Data Entry mode.

•	Base subforms on queries rather than on tables, and include only fields from the record source that are absolutely necessary. Extra fields can decrease subform performance.

•	Index all the fields in the subform that are linked to the main form.

•	Index any subform fields that are used for criteria.

•	Set the subform's AllowEdits, AllowAdditions, and AllowDeletions properties to No if the records in the subform aren't going to be edited. Or set the RecordsetType property to Snapshot.


Optimizing list box or combo box performance

There are several things you can do to make your list boxes and combo boxes run faster:

•	Base the list box or combo box on a saved query instead of an SQL statement. If you use a wizard to create the list box or combo box, Microsoft Access automatically sets the RowSource property of the control to an SQL statement. To change the RowSource property to a saved query, click the Build button next to the RowSource property box. In the SQL Builder window, click Save on the File menu, and type a name for the query. When you close the SQL Builder window, click Yes when Microsoft Access asks if you want to update the property.

•	In the query specified in the RowSource property box, include only fields that are absolutely necessary. Extra fields can decrease performance.

•	Index the first field displayed in the combo box or list box.

•	Index any fields used for criteria.

•	In combo boxes, set the AutoExpand property to No if you don't need the fill-in-as-you-type feature.

•	If the AutoExpand property is set to Yes, the first nonhidden column in a combo box should have a Text data type instead of a Number data type. In order to find a match in the list, Microsoft Access converts a numeric value to text. If the data type is text, Microsoft Access doesn't have to do this conversion.

•	Don't create list boxes or combo boxes based on linked data if the data won't change. It's better to import the data into your database, in this case.


Register a custom control

If you select the Microsoft OLE controls check box in the Setup program when you install Microsoft Access, the custom controls included in Microsoft Access will automatically be registered. Use this procedure to register a custom control that isn't included with Microsoft Access.

1	Add the files for the control to your hard disk. See the documentation that came with the custom control for information.

2	On the Microsoft Access Tools menu, click Custom Controls.

3	In the Custom Controls dialog box, click Register, specify a path to the control in the Add Control dialog box, and then click OK.

4	Click Close.


List boxes - What they are and how they work
List boxes — What they are and how they work

In many cases, it's quicker and easier to select a value from a list than to remember a value to type. A list of choices also helps to ensure that the value that's entered in a field is correct.

The list in a list box consists of rows of data. Rows can have one or more columns, which can appear with or without headings.

If a multiple-column list box is bound, Microsoft Access stores the values from one of the columns.

You can use an unbound list box to store a value that you can use with another control. For example, you could use an unbound list box to limit the values in another list box or in a custom dialog box. You could also use an unbound list box to find a record based on the value you select in the list box.

If you don't have room on your form to display a list box, or if you want to be able to type new values as well as select values from a list, use a combo box instead of a list box. For more information on combo boxes, click  [image].


Combo boxes - What they are and how they work
Combo boxes — What they are and how they work

In many cases, it's quicker and easier to select a value from a list than to remember a value to type. With a combo box, you can do either without using too much space on a form. A combo box is like a text box and a list box combined.

When you enter text or select a value in a combo box, if the combo box is bound, the entered or selected value is inserted into the field that the combo box is bound to.

The list in a combo box consists of rows of data. Rows can have one or more columns, which can appear with or without headings.

If a multiple-column combo box is bound, Microsoft Access stores the values from one of the columns.

You can use an unbound combo box to store a value that you can use with another control. For example, you could use an unbound combo box to limit the values in another combo box or in a custom dialog box. You could also use an unbound combo box to find a record based on the value you select in the combo box.

Combo boxes have a LimitToList property that you can use to control whether any value can be entered in the list or only text that matches one of the values in the list.

If you have room on your form and you want a list to appear at all times, or if you always want to limit data entries to values in the list, you might want to use a list box instead of a combo box. For more information on list boxes, click  [image].


Should I create a list box or a combo box?

To decide whether to create a list box or combo box, think about how you want the control to appear on your form and how you expect people to use it. Each control offers advantages:

•	Advantages of a list box — the list appears at all times and the value of the control is limited to the set of alternatives in the list. To move quickly to the first value starting with a particular letter, you can type that letter. When you're using the form to enter or edit data, you can't add a value that's not in the list. For more information on list boxes and how they work, click  [image].

•	Advantages of a combo box — since the list isn't displayed until you open it, the control uses less room on the form. You can type the first few characters of a value in the combo box to quickly find that value. Also, you can control whether any value can be entered in the list or only text that matches one of the values in the list. For more information on combo boxes and how they work, click  [image].


Create a list box or combo box that looks up values

To create a list box or combo box that looks up values, you need to decide two things:

•	Where will the rows for the list come from?

•	Will you store entries selected in the list in a table?

The rows for a list box or combo box can come from a fixed list of values that won't be stored in a table (use when the list won't change very often), or they can come from a table or query (use when you'll frequently update the list). For example, you could use a fixed list for a list box containing entries for Mr., Mrs., or Ms. If, on the other hand, you have a Products form and you want to display a combo box that lists product suppliers that will change frequently, base the combo box on a table or query. The table or query looks up values in the Suppliers table and displays the supplier name on the Products form.

If you want to store an entry selected in a list box or combo box in a table, you need to create a bound list box or combo box. If you want to use the entry selected in the list to determine the value of another control on the form, create an unbound list box or combo box. For example, you could use an unbound combo box to limit the values you see in another combo box on the same form. You could also use an unbound list box or combo box to find a record on a form.

What do you want to do?

Create a bound list box or combo box that displays fixed values

Create a bound list box or combo box that displays values from a table or query

Create an unbound list box or combo box that displays fixed values

Create an unbound list box or combo box that displays values from a table or query


Create a bound list box or combo box that displays fixed values

1	Create a Lookup field in table Design view.

How?

Note   You can create a lookup list box or combo box without creating a Lookup field, but if you create a Lookup field using the Lookup Wizard, you only need to create the list box or combo box once. Then you can use the same lookup list on any form. If you don't plan to use the same lookup list in more than one form, you can use the List Box Wizard or Combo Box Wizard in form Design view.

2	Do one of the following:

•	Create a new form based on a record source that includes the Lookup field you created in step 1. Microsoft Access automatically creates the lookup list box or combo box.

•	Open an existing form based on a record source that includes the Lookup field you created in step 1. In form Design view, click  [image]  on the toolbar to display the field list, and then drag the Lookup field from the field list to the form. Microsoft Access automatically creates the lookup list box or combo box.

3	Switch to Form view to test the list box or combo box.

Notes

•	For information on properties that determine how a list box or combo box works, click  [image].

•	For more information on Lookup fields and how they work, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].


Create a bound list box or combo box that displays values from a table or query

1	Create a Lookup field in table Design view.

How?

Note   You can create a lookup list box or combo box without creating a Lookup field, but if you create a Lookup field using the Lookup Wizard, you only need to create the list box or combo box once. Then you can use the same lookup list on any form. If you don't plan to use the same lookup list in more than one form, you can use the List Box Wizard or Combo Box Wizard in form Design view.

2	Do one of the following:

•	Create a new form based on a record source that includes the Lookup field you created in step 1. Microsoft Access automatically creates the lookup list box or combo box.

•	Open an existing form based on a record source that includes the Lookup field you created in step 1. In form Design view, click  [image]  on the toolbar to display the field list, and then drag the Lookup field from the field list to the form. Microsoft Access automatically creates the lookup list box or combo box.

3	Switch to Form view to test the list box or combo box.

Notes

•	For information on properties that determine how a list box or combo box works, click  [image].

•	For more information on Lookup fields and how they work, click  [image].

•	When you use a wizard to create a list box or combo box based on a table or query, Microsoft Access creates an SQL statement based on the fields you select and sets the RowSource property for the control to that SQL statement. If the list box or combo box isn't sorted the way that you want, you can modify the SQL statement by clicking the Build button next to the RowSource property. For information on specifying a sort order in the SQL Statement Builder, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].


Create an unbound list box or combo box that displays fixed values

1	In form Design view, make sure that  [image]  is pressed in.

2	Click  [image]  or  [image]  in the toolbox.

3	On the form, click where you want to place the list.

4	Follow the instructions in the wizard dialog boxes. When the wizard asks how you want to get the values for the list, select the option that says you'll type in the values that make up the list. When the wizard asks whether you want to store the value or remember it for later use, select the option that says you'll remember it for later use.

Notes

•	For information on properties that determine how a list box or combo box works, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].


 Create an unbound list box or combo box that displays values from a table or query

1	In form Design view, make sure that  [image]  is pressed in.

2	Click  [image]  or  [image]  in the toolbox.

3	On the form, click where you want to place the list.

4	Follow the instructions in the wizard dialog boxes. When the wizard asks how you want to get the values for the list, select the option that says you want the combo box or list box to look up values in a table or query. When the wizard asks whether you want to store the value or remember it for later use, select the option that says you'll remember it for later use.

Notes

•	For information on properties that determine how a list box or combo box works, click  [image].

•	When you use a wizard to create a list box or combo box based on a table or query, Microsoft Access creates an SQL statement based on the fields you select and sets the RowSource property for the control to that SQL statement. If the list box or combo box isn't sorted the way that you want, you can modify the SQL statement by clicking the Build button next to the RowSource property. For information on specifying a sort order in the SQL Statement Builder, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].


Create a list box or combo box that displays field names from a table or query

You can use this type of list box or combo box to take an action based on a field name selected in a list. For example, you could create a combo box for a Customers form that lists all the fields in the Customers form. When you select a field name from the list, you can run a macro or event procedure that sorts data in the form by that field.

1	In form Design view, make sure  [image]  isn't pressed in.

2	Click  [image]  or  [image]  in the toolbox.

3	On the form, click where you want to place the list box or combo box.

4	Double-click the combo box or list box to open its property sheet.

5	In the RowSourceType property box, select the Field List setting.

6	In the RowSource property box, specify the name of the table or query that has the fields you want to display in the list box or combo box. For example, specify Customers to fill the list box with fields from the Customers table.

7	Set other properties, as necessary. For information on properties that you can use to customize a list box or combo box, click  [image].

Notes

•	If you know the names of the fields you want to display in the list, it might be easier to enter them as fixed values instead. For more information on creating a list box or combo box that displays fixed values, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].


Use an SQL statement as the row source for a list box or combo box

You might want to use an SQL statement instead of a saved query for the row source of a list box or combo box, so the query doesn't show up in the Database window. List boxes and combo boxes based on SQL statements are slower than list boxes and combo boxes based on saved queries, however.

1	In form Design view, double-click the list box or combo box to open its property sheet.

2	Click the Build button next to the RowSource property to open the Query Builder.

3	In the Query Builder, click SQL on the View menu.

4	In the SQL window, select the entire SQL statement, and then press CTRL+C to copy it. Close the Query Builder.

5	Click in the RowSource property box, and press CTRL+V to paste the SQL statement into the property box.

6	Delete the original query in the Database window.

Notes

•	For information on properties that you can use to customize a list box or combo box, click  [image].

•	For information on troubleshooting list boxes and combo boxes, click  [image].

•	If you create a list box or combo box with a wizard, Microsoft Access uses an SQL statement as the row source for the list box or combo box.


Create a list box or combo box that gets its rows from a Visual Basic function

You may want to use this procedure when the values in a list are constantly changing, or if the values aren't stored in a database. For example, you could write a function that fills a list box with a list of dates, each one a specific number of days after the current date.

1	Create the function. For information on creating the function, click  [image].

2	Create the list box or combo box and open its property sheet.

3	In the RowSourceType property box, enter the name of the function. Don't put an equal sign before the function name.

4	Leave the RowSource property box blank.


Properties you can use to create or modify list boxes, combo boxes, and lookup lists

When you use a wizard to create a list box or combo box, Microsoft Access sets certain properties for the control. You can work with these properties directly if you don't want to use a wizard to create the control, or you can use a wizard to create the control and then modify these properties to make the control work just the way you want. To find out more about any of the following properties, click the property in the property sheet and press F1.

Note   If you're creating or modifying a bound list box or combo box, you can set most of these properties in table Design view instead of using the control's property sheet. This way, you can specify the properties once. When you add the field to which the list box or combo box is bound to a form, Microsoft Access automatically creates the control based on the properties you specified.

Property	Description
RowSourceType	Works together with the RowSource property. You specify the type of row source (table/query, value list, field list, or Visual Basic function) using this property and then specify the actual row source in the RowSource property.
RowSource	Specifies the name of the table, query, or SQL statement if RowSourceType is set to Table/Query. Specifies the entries in the list, separated by semi-colons, if RowSourceType is set to Value List. Specifies the name of the table or query if RowSourceType is set to Field List. Is blank if RowSourceType is set to a function name.
BoundColumn	In a bound multiple-column list box or combo box, specifies which column is bound to the underlying field specified in the ControlSource property. Data in that column will be stored in the field when you select that item in the list. This data may be different from the data displayed in the list if you hide the column.
ColumnCount	Specifies the number of columns in a list box or combo box. You can include a column but not display it in a list by setting the ColumnWidths property. You might want to do this if you have a list that looks up values from a table or query. You could include an ID field but hide it in the list. In a combo box, the first visible column in the list is displayed in the text box portion of the combo box.
ColumnWidths	Specifies the width of each column, separated by semi-colons. Enter 0 to hide a column. Enter a semi-colon without a measurement to use the default (about 1" or 2.5 cm, depending on the unit of measurement set in the Windows Control Panel).
ColumnHeads	Determines whether the field names from the underlying row source for a combo box or list box are used as column headings in the combo box or list box. Headings appear in combo boxes only when the list is dropped down.
ListWidth	Specifies the width of the list box portion of a combo box.
ListRows	Specifies the maximum number of rows to display in the list box portion of a combo box.
LimitToList	Determines whether a combo box accepts any entered text or only text that matches one of the values in the list. If you want to allow a new value that a user enters to be added to the list, set the property to No and attach an event procedure to the OnNotInList property.
OnNotInList	Runs the attached event procedure when the NotInList event occurs. You can use this property to automatically add a new value to a list. This property isn't available on the Lookup tab in table Design view.
AutoExpand	Specifies whether Microsoft Access automatically fills in a value that matches the characters that you type in a combo box. This property isn't available on the Lookup tab in table Design view.
DisplayControl	Specifies the type of control (combo box or list box) that Microsoft Access creates by default when you add a Lookup field to a form. This property is available only on the Lookup tab in table Design view.


Bind a column from a list box or combo box

1	In form Design view, double-click the list box or combo box to open its property sheet.

2	In the BoundColumn property box, specify a number that corresponds to the placement of the column in the list box or combo box. For example, type 1 to bind the first column in the list box or combo box to the underlying field specified in the ControlSource property. Include hidden columns when you count columns.

Notes

•	You can specify the number of a hidden column in the BoundColumn property. For more information on hiding a column in a multiple-column list box or combo box, click  [image].

•	If you set the BoundColumn property to 0, Microsoft Access saves the list index instead of a value from one of the columns. This is useful if you want to store a sequence of numbers instead of the list value.

•	For more information on the BoundColumn property, click  [image].


Add column headings to a list box or combo box

1	In form Design view, double-click the list box or combo box to open its property sheet.

2	In the ColumnHeads property, select Yes to display column headings.

If the combo box or list box is based on a table, query, or SQL statement, Microsoft Access uses the field names from the table, query, or SQL statement as the column headings. If the combo box or list box is based on a fixed value list, Microsoft Access uses the first x items of data from the value list (RowSource property) as the column headings, where x = the number set in the ColumnCount property.

Notes

•	Headings in combo boxes appear only when the list is dropped down.

•	For more information on creating fixed value lists using the RowSource property, click  [image].


Creating a multiple-column list box or combo box

You can use a wizard to create a multiple-column list box or combo box. When you use a wizard, you can drag the columns in the list box or combo box to make them look just the way you want. If you want to customize a list box or combo box created with a wizard, however, or if you want to create a multiple-column list box or combo box on your own, you can set the following properties. For more information on any of these properties, click the property in the property sheet and press F1.

Note   If you're creating or modifying a bound list box or combo box, you can set these properties in table Design view instead of using the control's property sheet. This way, you can specify the properties once. When you add the field to which the list box or combo box is bound to a form, Microsoft Access automatically creates the control based on the properties you specified.

Property	Description
BoundColumn	Specifies which column is bound to the underlying field specified in the ControlSource property. Data in that column will be stored in the field when you select that item in the list. This data may be different from the data displayed in the list if you hide the column.
ColumnCount	Specifies the number of columns. You can include a column but not display it in a list by setting the ColumnWidths property. You might want to do this if you have a list that looks up values from a table or query. You could include an ID field but hide it in the list. In a combo box, the first visible column in the list is displayed in the text box portion of the combo box.
ColumnWidths	Specifies the width of each column, separated by semi-colons. Enter 0 to hide a column. Enter a semi-colon without a measurement to use the default (about 1" or 2.5 cm, depending on the unit of measurement set in the Windows Control Panel).
ColumnHeads	Determines whether the list box or combo box has column headings. If the combo box or list box is based on a table, query, or SQL statement, Microsoft Access uses the field names from the table, query, or SQL statement as the column headings. If the combo box or list box is based on a fixed value list, Microsoft Access uses the first x items of data from the value list (RowSource property) as the column headings, where x = the number set in the ColumnCount property. Headings appear in combo boxes only when the list is dropped down.
Note   If you want to display all the columns in a multiple-column list box (instead of scrolling horizontally to view them), size the control to fit the column widths.


Set the maximum number of rows to display for a combo box

1	In form Design view, double-click the combo box to open its property sheet.

2	In the ListRows property box, enter a number.

If the actual number of rows exceeds the number specified in the ListRows property, a vertical scroll bar is displayed in the combo box.


Set the width of the list box portion of a combo box

1	In form Design view, double-click the combo box to open its property sheet.

2	In the ListWidth property box, enter the desired width using the current unit of measurement (set in the Windows Control Panel). To use a unit of measurement other than the default, include a measurement indicator. For example, enter 2".

Notes

•	The list box portion of the combo box can be wider than the text box portion, but it can't be narrower. The default setting (Auto) makes the list box the same width as the text box portion of the combo box.

•	When designing a combo box, leave enough space for a scroll bar.


Turn off the fill-in-as-you-type feature of a combo box

1	In form Design view, double-click the combo box to open its property sheet.

2	In the AutoExpand property box, click No.

When the AutoExpand property is set to No, you must select a value from the list or type the entire value.


Limit combo box entries to items in the list

1	In form Design view, double-click the combo box to open its property sheet.

2	In the LimitToList property box, click Yes.

Notes

•	If the first column displayed in a combo box is not the bound column, Microsoft Access limits the entries to the list even if the LimitToList property is set to No.

•	If the LimitToList property is set to No, when you enter an entry that isn't in the list, if the combo box is bound, the entry is stored in the underlying field, but it isn't added to the list. To add new entries to the list, use the OnNotInList property and the NotInList event. For more information, click  [image].


Hide a column in a list box or combo box

1	In form Design view, double-click the list box or combo box to open its property sheet.

2	In the ColumnWidths property box, enter 0 for the column(s) you want to hide.

For example, suppose you have a bound two-column combo box that has a SupplierID column and a SupplierName column. The SupplierID column is the first column in the list. To hide the SupplierID column, set the ColumnWidths property as shown in the following illustration.

Note   In a combo box, the first visible column is displayed in the text box portion of the combo box when the list isn't displayed. For example, the SupplierName column in the previous example would be displayed since the SupplierID column is hidden. If the SupplierID column wasn't hidden, only it would be displayed.


Example of synchronizing a combo box with another combo box

The Edit Products form in the Solutions sample application has an example of using a combo box to limit the contents of another combo box. This example uses an event procedure. You can copy this event procedure to your database and customize it to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Limit the contents of one list based on the value selected in another.

For information on opening the Solutions sample application, click  [image].


Example of adding "(all)" to a combo box list

The Add All To List form in the Solutions sample application has an example of adding "(all)" to a combo box list. This example uses a Visual Basic function. You can copy this function to your database and customize it to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Add "(all)" to a list.

For information on opening the Solutions sample application, click  [image].


Example of adding a new record to a combo box list

The Enter Or Edit Products form in the Solutions sample application has an example of adding a new record to a combo box list. This example uses an event procedure. You can copy this event procedure to your database and customize it to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Add a new record to a list.

For information on opening the Solutions sample application, click  [image].


Example of limiting a list box based on the value selected in an option group

The Limit List Contents form in the Solutions sample application has an example of limiting the contents of a list box based on the value selected in an option group. This example uses an event procedure. You can copy this event procedure to your database and customize it to fit your needs.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Limit the contents of a list based on the value selected in an option group.

For information on opening the Solutions sample application, click  [image].


Should I choose a table or query when I use a wizard to create a list or combo box?

In most cases, you can use a table as the row source for a list box or combo box when you create the list box or combo box with a wizard. Use a query in the following cases:

•	If you want to include calculated fields in the list box or combo box. For example, you could concatenate a first name and a last name using the following expression: Name: [FirstName] & " "& [LastName]. You could define this calculated field in a query and then include this field in the list box or combo box.

•	If you want to include fields from more than one table in the list box or combo box.

When you select fields from a table or query with a wizard, Microsoft Access creates an SQL statement based on the fields that you select and sets the RowSource property of the list box or combo box to that SQL statement.


Sort records in a list box or combo box

If you use a wizard to create the list box or combo box, Microsoft Access automatically sorts the rows that make up the list by the first visible column. If you want to specify a different sort order, or if you're using a saved query as the row source for the list box or combo box, you can use this procedure.

1	In form Design view, double-click the list box or combo box to open its property sheet.

2	In the RowSource property box, click the Build button to open the Query Builder or SQL Statement Builder.

3	Specify the sort order.

How?


 Draw a rectangle on a form or report

1	In form or report Design view, click  [image]  in the toolbox.

2	Click anywhere on the form or report to create a default-sized rectangle, or drag to create a rectangle that's the size you want.

Note   To change the thickness of a rectangle's border, click the rectangle, click the arrow next to  [image]  on the Formatting toolbar, and then click the thickness you want. To change the line style (dots, dashes, and so on) of a rectangle, double-click the rectangle to open the property sheet, and then click a border style in the BorderStyle property box.


Draw a line on a form or report

1	In form or report Design view, click  [image]  in the toolbox.

2	Click anywhere on the form or report to create a default-sized line, or click and drag to create a line that's the size you want.

Notes

•	To draw horizontal or vertical lines, click  [image], hold down the SHIFT key, and then drag to create the line.

•	To make small adjustments to the length or angle of a line, select the line, hold down the SHIFT key, and press one of the arrow keys. To make small adjustments in the placement of a line, hold down the CTRL key and press one of the arrow keys.

•	To change the thickness of a line, click the line, click the arrow next to  [image]  on the Formatting toolbar, and then click the line thickness you want. To change the line style (dots, dashes, and so on) of a line, double-click the line to open the property sheet, and then click a border style in the BorderStyle property box.


Add a background picture to a form

By adding a background picture to a form, you can simulate a watermark.

1	In Design view, double-click the form selector to open the property sheet.

2	In the Picture property box, type the path and filename for a .bmp, .ico, .dib, .wmf, or .emf file. If you've installed graphics filters for other applications, you can use any file supported by those filters. If you're not sure of the path or filename, click the Build button.

3	In the PictureType property box, specify whether you want the picture to be embedded or linked. When you embed a picture, it's stored in the database file. If you embed the same picture in another form or report, it's added to the database file again. When you link a picture, you don't store it in the database file, but you must keep a copy of it on your hard disk. If you want to use your hard disk space efficiently, specify the Linked setting.

4	After you add the picture to the form, you can size or clip it by clicking one of the following settings in the PictureSizeMode property box.

Setting	Description
Clip	Displays the picture at actual size. If the picture is larger than the Form window, the image is cut off.
Stretch	Sizes the picture to fit the Form window. This setting may distort the image.
Zoom	Sizes the picture to fill either the height or width of the Form window. This setting won't clip the picture or distort its proportions.
4	If you want to change the alignment of the picture, click one of the settings in the PictureAlignment property box.

Note   If you want to center the background picture and you want the background picture to resize when you size the window, click the Center setting. If you don't want the background picture to resize when you size the window, click the Form Center setting.

5	If you want to repeat the picture across the background of the form, set the PictureTiling property to Yes. Tiling starts at the position specified in the PictureAlignment setting.

Note   Set the PictureSizeMode property to Clip if you want to tile the background picture. The background picture will not be tiled if the PictureSizeMode property is set to Zoom or Stretch.

Notes

•	If the colors in your picture don't look the same as the original colors, you can specify that Microsoft Access use the colors from the application you used to create the picture.
How?

•	If you're creating your own background pictures and you have access to a graphics program that creates metafiles, you may want to use a metafile as a background picture rather than a bitmap. For more information, click  [image].


Change the font of text in a control

1	Click the control that contains the text you want to change.

2	In the Font Name box on the Formatting toolbar, click the font you want to apply.

When you change the font, the change applies to the entire contents of the control. You can't change individual characters in a control.

Tip   If you want to resize the control to fit the new font, point to Size on the Format menu, and then click To Fit.


Change the font size of text in a control

1	Click the control that contains the text you want to change.

2	In the Font Size box on the Formatting toolbar, enter the font size you want to use.

When you change the font size, the change applies to the entire contents of the control. You can't change individual characters in a control.

Tip   If you want to resize the control to fit the new font size, point to Size on the Format menu, and then click To Fit.


Make text in a control bold, italic, or underlined

1	Click the control that contains the text you want to change.

2	On the Formatting toolbar, click  [image]  to make the text bold,  [image]  to make the text italic, or  [image]  to make the text underlined.

When you make the text bold, italic, or underlined, the change applies to the entire contents of the control. You can't change individual characters in a control.

Tip   If you want to resize the control to fit the text, point to Size on the Format menu, and then click To Fit.


Change the default alignment of text in attached labels

Changes made using this procedure only affect new controls on the current form or report. If you want to change the default control style for all forms and reports, click  [image].

1	In form or report Design view, click the tool in the toolbox for the type of control that has the attached label. For example, if you want to change the default alignment of text in labels attached to text boxes, click  [image]  in the toolbox.

2	Click  [image]  on the toolbar to display the property sheet.

Microsoft Access changes the title bar of the property sheet to indicate that you're setting default properties for that type of control.

3	In the LabelAlign property box, click Left, Center, or Right.

For information about how the LabelAlign property interacts with the LabelX and LabelY properties, click  [image].


Change the default placement of new attached labels

Changes made using this procedure only affect new controls on the current form or report. If you want to change the default control style for all forms and reports, click  [image].

1	In form or report Design view, click the button in the toolbox for the type of control that has the attached label. For example, if you want to change the default placement of labels attached to text boxes, click  [image]  in the toolbox.

2	Click  [image]  on the toolbar to display the property sheet.

Microsoft Access changes the title bar of the property sheet to indicate that you're setting default properties for that type of control.

3	In the LabelX property box (horizontal axis), type a positive or negative number that specifies the starting point of the label text relative to the upper-left corner of the control the label is attached to. A negative number places the label to the left of the control. A positive number places the label to the right of the control.

4	In the LabelY property box (vertical axis), type a number. A negative number places the label above the control. A positive number places the label below the control.

Tip   To use a unit of measure different from the setting specified in the regional settings properties in the Windows Control Panel, specify that type of measurement after the number (for example, 1.5 in or 2 cm).

For information about how the LabelX and LabelY properties interact with the LabelAlign property, click  [image].


Change the default alignment of text in new controls

Changes made using this procedure only affect new controls on the current form or report. If you want to change the default control style for all forms and reports, click  [image].

1	In form or report Design view, click the appropriate tool in the toolbox. For example, if you want to change the default alignment of text in a text box, click  [image]  in the toolbox.

2	Click  [image]  on the toolbar to display the property sheet.

Microsoft Access changes the title bar of the property sheet to indicate that you're setting default properties for that type of control.

3	In the TextAlign property box, click General, Left, Center, or Right. If you click General, Microsoft Access aligns text to the left and numbers and dates to the right.


Change the alignment of text in a control

1	Click the control that contains the text you want to change.

2	On the Formatting toolbar, click  [image]  to center the text,  [image]  to align the text to the right, or  [image]  to align the text to the left.

Note   If you don't select any of the alignment buttons, the control has general alignment — text is aligned to the left and numbers are aligned to the right.


Change the color of a control's border

1	Click the control you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click a color in the palette.

Notes

•	If you want to use the same color for another control, you can just click  [image]  (you don't have to click the arrow next to the button and pick the color again from the palette). If you want to set different colors for several controls at once, you can click the border of the color palette and drag it to another location. This way you don't need to click  [image]  each time you want to apply a color.

•	If the SpecialEffect property for the control is set to Raised, Sunken, Etched, or Chiseled, Microsoft Access changes the setting to Flat when you change the border color.


Make a control's border transparent

1	Click the control you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click the Transparent button at the bottom of the palette.

Note   If the SpecialEffect property for the control is set to Raised, Sunken, Etched, or Chiseled, Microsoft Access changes the setting to Flat when you make the border transparent.


Make a control transparent

When a control is transparent, the color displayed in the control is the color of the control, section, or form behind it.

1	Click the control that you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click the Transparent button at the bottom of the palette.

Note   You can make any control transparent except list boxes and toggle buttons. Option groups are transparent by default.


Change the background color of a control or section

1	Click the control or section that you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click a color in the palette.

Notes

•	If you want to use the same color for another control or section, you can just click  [image]  (you don't have to click the arrow next to the button and pick the color again from the palette). If you want to set different colors for several controls at once, you can click the border of the color palette and drag it to another location. This way you don't need to click  [image]  each time you want to apply a color.

•	If the palette doesn't include the color that you want, you can create your own custom colors.

How?


Change the color of text in a control

1	Click the control that contains the text you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click a color in the palette.

Tip   If you want to use the same color for another control, you can just click  [image]  (you don't have to click the arrow next to the button and pick the color again from the palette). If you want to set different colors for several controls at once, you can click the border of the color palette and drag it to another location. This way you don't need to click  [image]  each time you want to apply a color.


Change the width of a control's border

1	Click the control that you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click the border width you want.

Notes

•	If you want to use the same border width for another control, you can just click  [image]  (you don't have to click the arrow next to the button and pick the width again from the list).

•	If the SpecialEffect property for the control is set to Raised, Sunken, Etched, or Chiseled, Microsoft Access changes the setting to Flat when you change the border width.


Make a control's border dotted, dashed, or solid

1	Double-click the control to display the control's property sheet.

2	In the BorderStyle property box, click the border style you want to apply.

Note   If the SpecialEffect property for the control is set to Raised, Sunken, Etched, or Chiseled, you can't change the border style of the control.


Add a special effect to a control to make it appear raised, sunken, shadowed, chiseled, or etched

1	Click the control that you want to change.

2	On the Formatting toolbar, click the arrow next to  [image].

3	Click the effect you want to apply. The following illustration shows what each effect looks like.

Notes

•	If you want to use the same special effect for another control, you can just click  [image]  (you don't have to click the arrow next to the button and pick the effect again from the list).

•	You can adjust the thickness of the shadow by clicking  [image]  on the Formatting toolbar.

•	If you click Raised, Sunken, Etched, or Chiseled, Microsoft Access overrides any settings for the BorderColor, BorderWidth, and BorderStyle properties. If you click Etched, Microsoft Access also sets the BackStyle property for text boxes and combo boxes to Transparent, and the BackColor property for list boxes to the section's BackColor property.

•	If you choose a raised or sunken appearance but the three-dimensional look doesn't appear in your form, double-click the Display icon in the Windows Control Panel, click the Appearance tab, and then click Windows Standard in the Scheme box.


Create custom colors for a section or control on a form or report

If the palette doesn't have the color you need, you can create your own custom colors.

1	Double-click the section or control to open its property sheet.

2	Click the ForeColor (for text in a control), BackColor, or BorderColor property.

3	Click the Build button next to the property box to open the Color dialog box.

4	Click Define Custom Colors to expand the dialog box.

5	Click one of the Custom Color boxes on the left side of the dialog box.

6	Click anywhere in the color refiner box. The color refiner box displays all of the available nonsolid colors.

7	Drag the arrow beside the luminosity bar to define the brightness of the color selected in the color refiner box.

Microsoft Access displays the color you create in the left side of the Color/Solid box. If you want to see the solid color most closely resembling the one you've created, double-click the right side of the Color/Solid box.

8	Click Add To Custom Colors.

Microsoft Access displays the custom color you created in the Custom Color box.

Note   You can also create a color by typing numbers in the Red, Green, Blue, Hue, Sat (saturation), and Lum (luminosity) boxes.


Set color properties to Microsoft Windows system colors

Using the BackColor, BorderColor, and ForeColor properties, you can create a color scheme in Microsoft Access that matches the color scheme used in other Windows applications. This is particularly useful if you're developing an application that you want to distribute to multiple users. Setting color properties to Windows system colors enables you to specify a single setting that can display different colors on different users' computers, depending on the colors they've chosen in the Windows Control Panel.

1	In form Design view, double-click the section or control whose color properties you want to set.

2	In the property sheet, click the BackColor, BorderColor, or ForeColor property.

3	In the property box, type one of the numbers listed in the following table. For example, if you want the background of your form to display the same color that you or another user uses for the Windows background color, set the BackColor property to -2147483643, the value for Window.

Screen element	Value
Scroll bar	-2147483648
Desktop	-2147483647
Active window title bar	-2147483646
Inactive window title bar	-2147483645
Menu bar	-2147483644
Window	-2147483643
Window frame	-2147483642
Menu text	-2147483641
Window text	-2147483640
Title bar text	-2147483639
Active window border	-2147483638
Inactive window border	-2147483637
Application background	-2147483636
Highlight	-2147483635
Highlight text	-2147483634
3-D face	-2147483633
3-D shadow	-2147483632
Dimmed (disabled) text	-2147483631
Button text	-2147483630
Inactive window title bar text	-2147483629
3-D highlight	-2147483628
3-D dark shadow	-2147483627
3-D light	-2147483626
ToolTip text	-2147483625
ToolTip background	-2147483624
Notes

•	The Windows system color value refers only to the color of the screen element listed — not to the type of object it can be assigned to. For example, you could set the BackColor property for a text box to the Windows system color for scroll bars, the desktop, or any other screen element.

•	The values for the Windows screen elements are always the same, regardless of the user's color settings.

•	You can also set the BackColor, BorderColor, and ForeColor properties to a Windows system color using Visual Basic for applications.


Use custom colors from another application

When you want to display graphics in the colors available in the application used to create them, you can specify a custom palette for a form or report. The custom palette replaces the Microsoft Access default palette only for that form or report.

1	In form or report Design view, double-click the form selector or the report selector to open the property sheet.

2	In the PaletteSource property box, type the path and filename of one of the following types of files:

•	.dib (device-independent bitmap file)

•	.pal (Microsoft Windows palette file)

•	.ico (Windows icon file)

•	.bmp (Windows bitmap file)

•	.wmf (Windows metafile)

•	.emf (enhanced metafile)

•	Any other file types supported by graphic filters that you have installed

Note   To display pictures and charts in their original colors, the display driver currently loaded in your system must support the palette you specify in the PaletteSource property box. For example, if you specify C:\Windows\256Color.bmp, the currently loaded display driver must support 256 colors.


Add a page break to a form

1	In form Design view, click  [image]  in the toolbox.

2	Click the form where you want to place the page break. Place the page break above or below a control to avoid splitting data in that control.

Microsoft Access marks the page break on the left border of the form with a short dotted line. You can move between pages of the form by pressing the PAGE UP and PAGE DOWN keys.

Notes

•	A page break is active in Form view only when the DefaultView property of the form is set to Single Form.

•	For forms used in Form view, a page break marks where the form will scroll to when PAGE UP or PAGE DOWN is pressed. For printed forms, a page break marks the start of a new page within a section. To start a page at the beginning of a section, use the section's ForceNewPage property.

•	If you want each page to be the same size, and each window to show only one page at a time, design the form so that each page break is an equal distance from the other. You can do this by positioning the page break controls with the vertical ruler.


Change tab order in a form

1	Open the form in Design view.

2	On the View menu, click Tab Order.

3	Under Section, click the section you want to change.

4	Do one of the following:

•	If you want Microsoft Access to create a left-to-right and top-to-bottom tab order, click Auto Order.

•	If you want to create your own custom tab order, click the selector for the control you want to move. (Click and drag to select more than one control at a time.) Click the selector again and drag the control to the desired location in the list.

5	Click OK.

6	Switch to Form view to test the tab order. (In Design view, the tab order is always the order in which you created the controls.)

Notes

•	If you want to be able to select a control on a form, but you don't want to include that control in the tab order, set its TabStop property to No.

•	You can also specify which record or page to move the focus to when you press the TAB key in the last field in the current record.

How?


Remove a button or other control from the tab order

There are two ways to remove a button or other control from the tab order. If you want to remove the control from the tab order, but you want to be able to select the control, you can set the TabStop property to No for that control.

If you want to disable the control until a certain condition is met, you can use the Enabled property together with the AfterUpdate property.

What do you want to do?

Remove the control from the tab order but don't disable it

Disable the control


Remove a control from a form's tab order

1	Double-click the control to open its property sheet.

2	In the TabStop property box, click No.

Note   As long as a control's Enabled property is set to Yes, you can click the control to select it even if its TabStop property is set to No.


Change the tab behavior for the last field in a record on a form

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the Cycle property box, click one of the following settings.

Setting	Description
All records	When you press TAB in the last field in the record, the focus moves to the first field in the next record.
Current record	When you press TAB in the last field in the record, the focus moves back to the first field in the current record.
Current page	When you press TAB in the last field in the form page, the focus moves back to the first field in the current page.


Add or remove a form header and footer or a page header and footer

Form headers and footers appear at the top and bottom of a form in Form view and at the beginning and end of a printed form. Page headers and footers appear at the top and bottom of each printed page — they don't appear in Form view.

•	In form Design view, click Form Header/Footer or Page Header/Footer on the View menu.

Notes

•	If you remove a header and footer, Microsoft Access deletes the controls in the header and footer.

•	You can only add a header and footer as a pair. If you don't want both a header and a footer, you can size the one you don't want so that it has no height, or you can set its Visible property to No. You can also set the DisplayWhen property of a form header and footer to specify when you want the header and footer to be displayed — always, in print only, or on the screen only.

•	For an example of using different types of sections in forms, click  [image].


Set the opening view of a form to one record, more than one record, or Datasheet view

1	In form Design view, double-click the form selector to open the form's property sheet.

2	In the DefaultView property box, click one of the following settings.

Setting	Description
Single Form	Displays one complete record at a time. (Form view only)
Continuous Forms	Displays as many complete records as will fit in the detail section of the form. (Form view only)
Datasheet	Displays records arranged as rows and columns. Records may scroll off the screen.
Note   If you want to disable Form view or Datasheet view, you can set the ViewsAllowed property.


Add or remove scroll bars for a form or text box

1	In form Design view, double-click the text box or form selector to open the property sheet.

2	In the ScrollBar property box, click one of the settings.


Add a picture or other object to a Microsoft Access form or report

You can add objects that you've created in other applications to a Microsoft Access form or report. For example, you can add a picture you created with Microsoft Paint, a worksheet you created with Microsoft Excel, or a Word document you created with Microsoft Word. You can add all the information in a file or just selected information.

How you add a picture or object depends on whether you want the object to be bound or unbound. A bound object is stored in a table. When you move to a new record, the object displayed in the form or report changes. For example, you might want to store a picture for each employee in your company. An unbound object, on the other hand, is stored in the design of the form or report. When you move to a new record, the object doesn't change. For example, you might want to add a logo that you created with Microsoft Paint to a form or report.

What do you want to do?

Add an unbound picture

Add an unbound object (for example, a WordArt or Microsoft Excel document)

Add a bound object (for example, a picture or a Word or Microsoft Excel document)


 Add an unbound picture to a form or report

How you add an unbound picture depends on whether you want it to appear as a background picture (watermark) that covers the entire window or a picture that appears in the foreground as a control. If you want to add a background picture, you use the Picture property of the form or report. If you want to add a picture that appears in the foreground, you use an image frame or an unbound object frame.

Whether you use an image frame or an unbound object frame for a foreground picture depends on whether you want to be able to edit the picture directly from the form or report. If you won't need to update the picture, you can add the picture using an image control. If you will need to update the picture frequently, you can add the picture using an unbound object frame. Then if you want to edit the picture, you can double-click the object from the form or report to open the application used to create the object. For most unbound pictures displayed in the foreground, you'll probably want to use an image control since image controls load much faster than unbound object frames.

For background pictures and unbound object frames, you have a choice of embedding or linking the picture. When you embed a picture in a form or report, Microsoft Access stores the picture in your database file. An embedded object is always available. If you modify the picture from your form or report, the picture is changed in your database.

When you link to a picture, you can look at the picture and make changes to it from your form or report, but the changes are stored in the object file, not in your database file. You can also modify the object file separately and have the latest changes appear the next time you open the form or report. Linking to a picture is useful for large files that you don't want to include in your database file, and for files that you want to use in several forms and reports, but if a linked object file is moved, you have to reconnect the link.

What do you want to do?

Add a background picture to a form

Add a background picture to a report

Add a picture using an image control

Create and embed a picture using an unbound object frame

Embed an existing picture using an unbound object frame

Link to an existing picture using an unbound object frame

Embed part of an existing picture using an unbound object frame

Link to part of an existing picture using an unbound object frame

See examples of when to use unbound, bound, embedded, and linked objects


Add an unbound object to a form or report

You can add an unbound object to a form or report as an embedded object or as a linked object.

When you embed an object in a form or report, Microsoft Access stores the object in your database file. If you modify the object from your form or report, the object is changed in your database. For this reason, an embedded object is always available.

When you link to an object, you can look at the object and make changes to it from your form or report, but the changes are stored in the object file, not in your database file. You can also modify the object file separately and have the latest changes appear the next time you open the form or report. Linking to an object is useful for very large files that you don't want to include in your database file, and for files that you want to use in several forms and reports, but if a linked object file is moved, you have to reconnect the link.

What do you want to do?

Create and embed an object

Embed an existing object

Link to an existing object

Embed part of an existing object

Link to part of an existing object

See examples of when to use unbound, bound, embedded, and linked objects


Add a bound object to a form or report

You can add a bound object to a form or report as an embedded object or as a linked object.

When you embed an object in a form or report, Microsoft Access stores the object in your database file. If you modify the object from your form or report, the object is changed in your database file. For this reason, an embedded object is always available.

When you link to an object, you can look at the object and make changes to it from your form or report, but the changes are stored in the object file, not in your database file. You can also modify the object file separately and have the latest changes appear the next time you open the form or report. Linking to an object is useful for very large files that you don't want to include in your database file, and for files that you want to use in several forms and reports, but if a linked object file is moved, you have to reconnect the link.

What do you want to do?

Create and embed an object

Embed an existing object

Link to an existing object

Embed part of an existing object

Link to part of an existing object

See examples of when to use unbound, bound, embedded, and linked objects


Add an unbound picture using an image control

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to place the picture.

3	In the Insert Picture dialog box, click the filename for the picture that you want to add. You may need to use the Look In box to specify the drive and/or folder where the picture is located.

4	Click OK.

Microsoft Access creates an image control and displays the picture in the control.

Notes

•	You can adjust the size and proportions of the object after you paste it.
How?

•	When you add a picture to an image control, Microsoft Access embeds the picture by default. When a picture is embedded, it becomes part of the database file. If you plan to use the same picture on several forms and reports, you may want to link to the picture instead of embedding it. When you link a picture, you only store the picture once. To link to a picture, set the PictureType property for the image control to Linked.


Create and embed an unbound object

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to embed the object.

3	In the Insert Object dialog box, click Create New if it's not already selected, and then click the object type you want to create in the Object Type box.

4	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

5	Click OK.

6	Create the object using the application you chose in step 3.

7	After you've created the object, click Exit on the File menu to return to Microsoft Access.

Microsoft Access creates an unbound object frame and displays the object in the frame.

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	In many cases, you'll edit an unbound object from form or report Design view. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.


Embed an existing unbound object

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to embed the object.

3	In the Insert Object dialog box, click Create From File, and then specify a path to the file. If you don't know the path, you can click Browse.

4	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

5	Click OK.

Microsoft Access creates an unbound object frame and displays the object in the frame.

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	In many cases, you'll edit an unbound object from form or report Design view. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.


Link to an existing unbound object

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to place the object.

3	In the Insert Object dialog box, click Create From File, and then specify a path to the file. If you don't know the path, you can click Browse.

4	Select the Link check box.

5	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

6	Click OK.

Microsoft Access creates an unbound object frame and displays the object in the frame.

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	In many cases, you'll edit an unbound object from form or report Design view. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.

•	When you link to an object, the link is automatic by default. This means that if the object is updated outside Microsoft Access, the changes will automatically appear in the form or report. If you want to control when the link is updated, you can change the link from automatic to manual.

How?


Embed part of an existing unbound object

You can use this procedure if the application you're copying from has OLE support for copying part of an existing document.

1	Open the file in the application you used to create it and select the information you want to embed. For example, open Microsoft Excel and select a range of cells.

2	On the Edit menu, click Copy.

3	Switch to Microsoft Access.

4	In form or report Design view, click  [image]  on the toolbar.

Note   If you want to display the object as an icon or if you want to specify what type of object to paste as, click Paste Special on the Edit menu. For information on Paste Special options, click  [image].

Microsoft Access creates an unbound object frame and displays the object in the frame.

Notes

•	If the application you're copying from supports OLE drag-and-drop editing, you may be able to drag selected information from that application to the Design view of a Microsoft Access form or report. When you do this, Microsoft Access creates an unbound object frame and embeds the selected information in the frame.

•	You can adjust the size and proportions of the object after you paste it.

How?

•	In many cases, you'll edit an unbound object from form or report Design view. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.


Link to part of an existing unbound object

You can use this procedure if the application you're linking to has OLE support for linking to part of an existing document.

1	Open the file in the application you used to create it and select the information you want to link to. For example, open Microsoft Excel and select a range of cells.

2	On the Edit menu, click Copy.

3	Leave the application open, and switch to Microsoft Access.

4	In form or report Design view, click Paste Special on the Edit menu.

5	In the Paste Special dialog box, click Paste Link, and then click the type of object to paste as in the As list. For more information on these options, click  [image].

6	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

7	Click OK.

Microsoft Access creates an unbound object frame and displays the object in the frame.

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	In many cases, you'll edit an unbound object from form or report Design view. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.

•	When you link an object, the link is automatic by default. This means that if the object is updated outside Microsoft Access, the changes will automatically appear in the form or report. If you want to control when the link is updated, you can change the link from automatic to manual.

How?


Paste Special options

When you copy a selection from another application and click Paste Special on the Edit menu, Microsoft Access displays the Paste Special dialog box. The following table describes the entries in the As list in the Paste Special dialog box.

Click this entry  in the As box	If you want to
Application name (for example, Microsoft Excel 7.0 Worksheet)	Display the object in an unbound object frame. You can edit the object directly from the form or report if you click this entry.
Picture or Bitmap	Display the object in an image control. Click one of these entries if you want to optimize the performance of your form or report. You can't edit the object from the form or report if you click one of these entries.
Text	Display the text you copy (for example, the text in a Microsoft Excel cell) in a label if the object is embedded, or a text box if the object is linked. When you link an object this way, Microsoft Access creates a DDE link in the text box. When you switch to Form view or Print Preview, you'll see the actual linked text.


Create and embed a bound object

1	If you haven't already done so, create a bound object frame on a form.

How?

2	Switch to Form view or Datasheet view.

3	Move to the record in which you want to embed the object and click the OLE Object field.

4	On the Insert menu, click Object.

5	In the Insert Object dialog box, click Create New if it's not already selected, and then click the kind of object you want to create in the Object Type box.

6	Select the Display As Icon check box if you want the object to appear as an icon instead of the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

7	Click OK.

8	Create the object using the application you chose in step 5.

9	After you've created the object, click Exit on the File menu of the object application to return to Microsoft Access.

If you're in Form view, Microsoft Access displays the object. If you're in Datasheet view, Microsoft Access displays the name of the object, for example, "Paintbrush Picture."

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	You can also insert a bound object in a table or query datasheet. Just select the field that you want to insert the object into (it must be an OLE Object field), and then follow steps 4 through 9. To see the object, you must create a bound object frame on a form or report.


Add a bound object frame to a form or report

1	If you haven't already done so, create a field in a table and set the field's data type to OLE Object.

How?

2	Create a form or report (or open an existing form or report) that includes the OLE Object field in its record source.

3	In form or report Design view, click  [image]  on the toolbar to display the field list.

4	Drag the OLE Object field from the field list to the form or report.

Microsoft Access creates a bound object frame that's bound to the OLE Object field.

Note   If you've already created the bound object frame, you can bind it to a field in an underlying record source by setting the ControlSource property for the bound object frame to the name of the field.


Embed an existing bound object

1	If you haven't already done so, create a bound object frame on a form.

How?

2	Switch to Form view or Datasheet view.

3	Move to the record in which you want to embed the object and click the OLE Object field.

4	On the Insert menu, click Object.

5	In the Insert Object dialog box, click Create From File, and then specify a path to the file. If you don't know the path, you can click Browse.

6	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

7	Click OK.

If you're in Form view, Microsoft Access displays the object. If you're in Datasheet view, Microsoft Access displays the name of the object, for example, "Paintbrush Picture."

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	You can also insert a bound object in a table or query datasheet. Just select the field that you want to insert the object into (it must be an OLE Object field), and then follow steps 4 through 7. In order to see the object, you must create a bound object frame on a form or report.


Link to an existing bound object

1	If you haven't already done so, create a bound object frame on a form.

How?

2	Switch to Form view or Datasheet view.

3	Move to the record in which you want to link the object and click the OLE Object field.

4	On the Insert menu, click Object.

5	In the Insert Object dialog box, click Create From File, and then specify a path to the file. If you don't know the path, you can click Browse.

6	Select the Link check box.

7	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

8	Click OK.

If you're in Form view, Microsoft Access displays the object. If you're in Datasheet view, Microsoft Access displays the name of the object, for example, "Paintbrush Picture."

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	You can also insert a bound object in a table or query datasheet. Just select the field that you want to insert the object into (it must be an OLE Object field), and then follow steps 4 through 8. In order to see the object, you must create a bound object frame on a form or report.

•	When you link an object, the link is automatic by default. Microsoft Access automatically updates the object when you move to the field. If you want to control when the link is updated, you can change the link from automatic to manual.

How?


Embed part of an existing bound object

You can use this procedure if the application you're copying from has OLE support for copying part of an existing document.

1	If you haven't already done so, create a bound object frame on a form.

How?

2	Switch to the application you used to create the object and select the information you want to embed. For example, open Microsoft Excel and select a range of cells.

3	On the Edit menu, click Copy.

4	Switch back to Microsoft Access, switch to Form view or Datasheet view, move to the record you want to paste the object into, and click the OLE Object field.

5	Click  [image]  on the toolbar.

Note   If you want to display the object as an icon or if you want to specify what type of object to paste as, click Paste Special on the Edit menu. For information on Paste Special options, click  [image].

If you're in Form view, Microsoft Access displays the object. If you're in Datasheet view, Microsoft Access displays the name of the object, for example "Microsoft Excel 7.0 Worksheet."

Notes

•	If the application you're copying from supports OLE drag-and-drop editing, you may be able to drag selected information from that application to the OLE Object field in Form view.

•	You can adjust the size and proportions of the object after you paste it.

How?

•	You can also insert a bound object in a table or query datasheet. Just select the field that you want to insert the object into (it must be an OLE Object field), and then click  [image]  on the toolbar. To see the object, you must create a bound object frame on a form or report.


Link to part of an existing bound object

You can use this procedure if the application you're linking to has OLE support for linking to part of an existing document.

1	If you haven't already done so, create a bound object frame on a form.

How?

2	Switch to the application you used to create the object and select the information you want to link. For example, open Microsoft Excel and select a range of cells.

3	On the Edit menu, click Copy.

4	Leave the application open, and switch back to Microsoft Access. Switch to Form view or Datasheet view, move to the record you want to paste the object into, and click the OLE Object field.

5	On the Edit menu, click Paste Special.

6	In the Paste Special dialog box, click Paste Link, and then click the type of object to paste as in the As box. For more information on these options, click  [image].

7	Select the Display As Icon check box if you want the object to appear as an icon instead of as the object itself. Displaying an object as an icon can be helpful when an object contains supplementary information that doesn't have to be displayed.

8	Click OK.

If you're in Form view, Microsoft Access displays the object. If you're in Datasheet view, Microsoft Access displays the name of the object, for example "Microsoft Excel 7.0 Worksheet."

Notes

•	You can adjust the size and proportions of the object after you paste it.

How?

•	You can also insert a bound object in a table or query datasheet. Just select the field that you want to insert the object into (it must be an OLE Object field), and click Paste Special on the Edit menu. Then follow steps 6 through 8 above. In order to see the object, you must create a bound object frame on a form or report.

•	When you link an object, the link is automatic by default. Microsoft Access automatically updates the object when you move to the field. If you want to control when the link is updated, you can change the link from automatic to manual.

How?


Which type of object frame should I use and should I embed or link my object?

Example object	Type of  control to use	Embedded  or linked?
A logo on an invoice report that you don't need to update	Image control	Not applicable
A picture on a form or report that you expect to update frequently	Unbound object frame	Embedded
Part of a Microsoft Excel worksheet in a sales report	Unbound object frame	Linked
A picture for each employee to be stored in an Employees table	Bound object frame	Embedded
Employee résumés (created and stored in a Word document) available from an Employees form	Bound object frame	Linked, and displayed as an icon


Edit a bound picture or other object on a Microsoft Access form

1	Open the form in Form view (or open a datasheet).

2	Go to the record that contains the object you want to edit.

3	Double-click the object.

Microsoft Access opens the application used to create the object if it's available. The application may open in a separate window (for applications that don't support OLE in-place editing), or you may be able to edit the object in place.

Note   When you double-click a sound or video object, Microsoft Access plays the object. To open these types of objects for editing, point to the appropriate Object command on the Edit menu instead of double-clicking. For example, point to the Media Clip Object command, and then click the Open or Edit command on the submenu.

4	Make the changes you want and then do one of the following:

•	If you're editing in-place, click the form outside the bound object frame. If you mistakenly click Exit on the File menu, you'll quit Microsoft Access.

•	If you're editing the object in a separate window, click Exit on the File menu of the object application. If you're prompted to update the document, click OK.

Notes

•	To edit an object in a bound object frame, the Enabled property for the bound object frame must be set to Yes and the Locked property must be set to No.

•	You can define the action taken when you double-click an object by setting the Verb and AutoActivate properties for the bound object frame. For more information on the Verb property, click  [image]. For more information on the AutoActivate property, click  [image].


Edit an unbound picture or other object on a Microsoft Access form or report

1	In form or report Design view, double-click the object.

Microsoft Access opens the object application if it's available.

Note   When you double-click a sound or video object, Microsoft Access plays the object. To open these types of objects for editing, point to the appropriate Object command on the Edit menu instead of double-clicking. For example, point to the Media Clip Object command, and then click the Open or Edit command on the submenu.

2	Make the changes you want, and then click Exit on the File menu of the object application. If you're prompted to update the document, click OK.

Notes

•	You can define the action taken when you double-click an object by setting the Verb and AutoActivate properties for the unbound object frame. For more information on the Verb property, click  [image]. For more information on the AutoActivate property, click  [image].

•	In most cases, you'll edit an unbound object from the Design view of a form or report. If you want to be able to edit the object from Form view also, set the Enabled property of the unbound object frame to Yes and the Locked property to No.


Adjust the size and proportions of a picture displayed in an image control or object frame

1	In form or report Design view, click the bound object frame, the image control, or the unbound object frame.

2	Click  [image]  on the toolbar to display the property sheet.

3	In the SizeMode property box, click one of the following settings:

Setting	Description
Clip	Displays the picture at actual size. If the picture is larger than the area within the control, the image is cut off.
Stretch	Sizes the picture to fit the area within the control. This setting may distort the image.
Zoom	Displays the picture in its entirety after sizing it to fill either the height or width of the area within the control. This setting won't distort the image.


Convert a bound picture or other object on a Microsoft Access form or report to an image
Convert a bound picture or other object in a Microsoft Access form to an image

Use this procedure to either convert a bound object so it can't be edited from a form or make the form open faster.

1	In Form view, click the picture or other object and then click  [image]  on the toolbar.

2	On the Edit menu, click Paste Special.

3	In the As list, click Picture, or one of the bitmap choices, depending on whether you want to create a metafile or a bitmap.

Microsoft Access converts the object to an image. The bound object frame remains on the form, but you can't open the object application from the form. If the object is a sound object, just the icon remains. If it's a video object, just the first frame of the video remains. Note that you can no longer play the sound or video object.

Notes

•	When you make any changes to an object in a bound object frame, you are changing the object only for the current record. To make a change in a different record, move to that record and repeat the process.

•	If you want to prevent users from editing an object in Form view, you can set the object frame's Locked property to Yes and the Enabled property to No.


Convert an unbound object so it can't be edited from a Microsoft Access form or report

1	In form or report Design view, click the picture or object.

2	On the Format menu, point to Change To, and then click Image.

Microsoft Access converts the object frame to an image control. The object remains on the form or report, but you can't open the object application from the form or report. If the object is a sound object, just the icon remains. If it's a video object, just the first frame of the video remains. Note that you can no longer play the sound or video object.


Change the type of link for a picture or other object on a Microsoft Access form or report

When you link to an object created in another application, Microsoft Access creates an automatic link by default. You can change the type of link to manual, or vice versa.

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, click OLE/DDE Links.

3	In the Links box, click the link you want to change. To select multiple links, hold down the CTRL key while you click each link.

4	Click Automatic or Manual.

Note   When you make any changes to a link for a bound object frame, you are changing the link only for the current record. To make a change in a different record, move to that record and repeat the process.


Update a manual link to a picture or other object on a Microsoft Access form or report

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, click OLE/DDE links.

3	In the Links box, click the link you want to update. To select multiple links, hold down the CTRL key while you click each link.

4	Click Update Now.


Break a link to a picture or other object on a Microsoft Access form or report

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, click OLE/DDE links.

3	In the Links box, click the link you want to break. To select multiple links, hold down the CTRL key while you click each link.

4	Click Break Link.

Notes

•	Breaking a link has the same effect as changing an object to an image so it can't be edited.

•	When you make any changes to a link for a bound object frame, you are changing the link only for the current record. To make a change in a different record, move to that record and repeat the process.


Reconnect or change the link for a picture or other object on a Microsoft Access form or report

You may lose a link to an object if you rename or move the linked object.

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, click OLE/DDE links.

3	In the Links box, click the link you want to reconnect or change.

4	Click Change Source.

5	In the Change Source dialog box, select the new filename. You may need to switch to a different drive and/or directory to find the appropriate file.

6	Click OK to close the Change Source dialog box, and then click Close in the Links dialog box.

Notes   When you make any changes to a link for a bound object frame, you are changing the link only for the current record. To make a change in a different record, move to that record and repeat the process.


Copy a link to a picture or other object on a Microsoft Access form or report

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	Click  [image]  on the toolbar.

3	Do one of the following:

•	If you want the object to be unbound, switch to the form or report you want to copy the link to, and in form or report Design view, click  [image]  on the toolbar.

•	If you want the object to be bound, open a form in Form view (or open a datasheet), find the record you want to copy the link to, click the appropriate field, and then click  [image]  on the toolbar.

Microsoft Access copies the OLE object and its link.


Delete a picture or other object on a Microsoft Access form or report

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

Note   If you want to delete the bound object frame and all the objects stored in the underlying field, delete the bound object frame in Design view.

2	Press the DEL key.

If the object is bound, Microsoft Access removes it from the bound object frame and the underlying record source, but the bound object frame remains on the form or report. If the object is unbound, Microsoft Access removes the object and the unbound object frame.


Add a custom control to a form or report

1	In form or report Design view, click Custom Control on the Insert menu.

2	Click the control you want in the list.

Note   If the custom control you want to use isn't in the list, you may need to run the Setup program again.

3	On the form or report, click where you want to place the control.

4	Use the right mouse button to click the control, and then point to the appropriate Object command (for example, the SpinButton Object command), and then click Properties to open the custom control property sheet.

Note   You can also set properties for a custom control in the Microsoft Access property sheet. Microsoft Access displays custom control properties at the bottom of the property sheet. If a Build button appears next to a custom control property, you can click it to open the custom control property sheet.

5	Set properties as necessary.

Note   To get Help on any property, click the property in the custom control property sheet and press F1.

Notes

•	For more information on using custom controls, see Chapter 15, "Using OLE Custom Controls," in Building Applications with Microsoft Access for Windows 95.

•	Additional custom controls are available through the Microsoft Access Developer's Toolkit. For information on what's included in the Developer's Toolkit, click  [image].


Convert an OLE object on a Microsoft Access form or report to a later version of that OLE object

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, point to the appropriate Object command (for example, point to Worksheet Object for a Microsoft Excel object), and then click Convert.

3	In the Convert dialog box, click the type of object you want to the object convert to. For example, you could convert a Graph 3.0 object to a Graph 5.0 object.


Display a picture or other object on a Microsoft Access form or report as an icon

1	Do one of the following:

•	If the object is unbound, click the object in form or report Design view.

•	If the object is bound, open the form in Form view (or open a datasheet), find the record you want to change, and click the object.

2	On the Edit menu, point to appropriate Object command (for example, point to Worksheet Object for a Microsoft Excel object), and then click Convert.

3	In the Convert dialog box, select the Display As Icon check box.


Use a wizard to create a Microsoft Excel PivotTable and place it on a form

1	On the toolbar, click the arrow next to the New Object button, and then click New Form.

2	In the New Form dialog box, click PivotTable Wizard, and then click OK.

3	Follow the instructions in the wizard.

For more information on PivotTables and how they work, click  [image].

Notes

•	The Sales Analysis form in the Northwind sample database contains a PivotTable. To view this PivotTable, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Forms tab, click Sales Analysis, and then click Open. For information on opening Northwind, click  [image].

•	The source data that the PivotTable uses isn't automatically saved with the PivotTable or form. Instead, you must update the PivotTable with the most current data each time you want to use it, which means you'll need access to the location where the data is stored. If you know that you'll need to edit the PivotTable later on when you won't have access to the data, save a copy of the data with the PivotTable. For more information, click  [image].

•	While you're working in Microsoft Excel, you can get help on PivotTables by clicking Microsoft Excel Help Topics on the Help menu. If you don't find the answer you need, click Microsoft Access Help Topics on the Help menu in Microsoft Access.


Save a copy of a PivotTable's data

Save a copy of the data with a PivotTable if you know that you'll need to edit the PivotTable later on when you won't have access to the data. Note that doing this can significantly increase the size of the form, so make sure that you have enough disk space available.

1	With the form containing the PivotTable open in Form view, click the Edit PivotTable button.

2	On the Data menu in Microsoft Excel, click Refresh Data.

3	On the Data menu, click PivotTable to restart the PivotTable Wizard.

4	Click Next to advance to the last screen, click Save Data With Table Layout, and then click Finish.

5	Continue working with the PivotTable, or close it and return to the form in Microsoft Access by clicking Exit on the File menu.

Note   The changes you make to data saved with a PivotTable apply only to that PivotTable; they don't affect data in the underlying table.


What is a PivotTable?

A PivotTable is an interactive table that performs the calculations you choose, such as sums (the default for numeric fields) and counts (the default for text fields), based on how the data is arranged in the PivotTable. For example, a PivotTable can display a field's values horizontally or vertically, and then calculate the total of the row or column. It can also use a field's values as row or column headings, calculating individual amounts at the intersection of each row and column heading, and then calculating subtotals and grand totals. For example, to analyze sales by product category for each employee, you can list employee names as column headings across the top of the PivotTable, product categories as row headings down the side of the PivotTable, and the sales amount calculated by product category for each employee at the intersection of each row and column.

You can limit the records that the PivotTable uses by designating a field as a page field — which becomes a drop-down list above the PivotTable that works like a filter. The value you select from the list determines which records are included in the PivotTable. For example, you could use the City field from the Employees table as a page field to view the sales performance by product category of just the sales representatives in London. You can see an example of a PivotTable in the Northwind sample database. To view this PivotTable, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Forms tab, click Sales Analysis, and then click Open. For information on opening Northwind, click  [image].

It's called a PivotTable because you can dynamically change its layout to analyze the data in different ways. You can rearrange row headings, column headings, and page fields until you achieve the desired layout. Each time you change the layout, the PivotTable immediately recalculates the data based on the new arrangement. In addition, as source data changes, you can update the PivotTable.

You create a PivotTable in Microsoft Access by using the PivotTable wizard. The wizard uses Microsoft Excel to create the PivotTable and Microsoft Access to create a form where it embeds the PivotTable. For information on using the wizard, click  [image].

Each time you open a form containing a PivotTable, the PivotTable shows you the data that was current the last time you activated the PivotTable. To display the most current data in the PivotTable, you need to update the data. For more information, click  [image].


Edit a PivotTable

Because a PivotTable is an embedded Microsoft Excel object, you modify it by starting and using Microsoft Excel from the Microsoft Access form where the PivotTable is embedded.

1	With the form containing the PivotTable open in Form view, click the Edit PivotTable button.

Note   If you prefer to use in-place editing instead of editing the PivotTable in a separate Microsoft Excel window, point to Worksheet Object on the Edit menu in Microsoft Access, and then click Edit.

2	On the Data menu in Microsoft Excel, click Refresh Data.

3	Make the changes you want to the PivotTable.

Note   For help on specific ways you can modify or otherwise work with the PivotTable, click Microsoft Excel Help Topics on the Help menu.

4	When you're done editing the PivotTable, click Exit on the File menu in Microsoft Excel.

Notes

•	If you don't find the answer you need in the Microsoft Excel Help topics, click Microsoft Access Help Topics on the Help menu in Microsoft Access. If you're using in-place editing, you must first click any place on the form outside the PivotTable to get help.

•	The source data that the PivotTable uses isn't automatically saved with the PivotTable or form. Instead, you must update the PivotTable with the most current data each time you want to use it, which means you'll need access to the location where the data is stored. If you know that you'll need to edit the PivotTable later on when you won't have access to the data, save the data with the PivotTable and form. For more information, click  [image].


Troubleshoot a PivotTable on a Microsoft Access form

What do you need help with?

Some of the data in the PivotTable is cut off and there aren't any scroll bars to see the rest of the data.

I clicked the button to edit the PivotTable, but Microsoft Excel won't let me make any modifications.

The data in the PivotTable isn't current. How do I update it?

If I open Microsoft Excel without going through the form containing the PivotTable, I can't find the PivotTable.


Some of the data in the PivotTable is cut off and there aren't any scroll bars to see the rest of the data.

•	To scroll through the data in the PivotTable, click the Edit PivotTable button, which opens Microsoft Excel. You can then see the entire PivotTable and scroll through the data.


I clicked the button to edit the PivotTable, but Microsoft Excel won't let me make any modifications.

Before you can modify a PivotTable, you need to update the data that's displayed in it.

1	With the form containing the PivotTable open in Form view, click the Edit PivotTable button.

2	On the Data menu in Microsoft Excel, click Refresh Data.

You should now be able to modify the PivotTable.


Update the data in a PivotTable

1	With the form containing the PivotTable open in Form view, click the Edit PivotTable button.

2	On the Data menu in Microsoft Excel, click Refresh Data.


If I open Microsoft Excel without going through the form containing the PivotTable, I can't find the PivotTable.

Because the PivotTable is an embedded object, it's stored in Microsoft Access. This means you must go through the Microsoft Access form to edit the PivotTable. However, when you start Microsoft Excel from the Microsoft Access form, you can save the PivotTable worksheet in Microsoft Excel. If you do this, note that the PivotTable in Microsoft Excel and the one on the Microsoft Access form aren't linked. This means that if you change the PivotTable in one application, the changes won't be reflected in the other application, and the data will be inconsistent.


Subforms - What they are and how they work
 Subforms — What they are and how they work

A subform is a form within a form. The primary form is called the main form and the form within the form is called the subform. A form/subform combination is often referred to as a hierarchical form, a master/detail form, or a parent/child form.

Subforms are especially effective when you want to show data from tables or queries with a one-to-many relationship. For example, you could create a form with a subform to show data from a Categories table and a Products table. The data in the Categories table is the "one" side of the relationship. The data in the Products table is the "many" side of the relationship — each category can have more than one product.

The main form and subform in this type of form are linked so that the subform displays only records that are related to the current record in the main form. For example, when the main form displays the Beverages category, the subform displays only the products in the Beverages category.

When you use a form with a subform to enter new records, Microsoft Access saves the current record in the main form when you enter the subform. This ensures that the records in the "many" table will have a record in the "one" table to relate to. It also automatically saves each record as you add it to the subform.

A subform can be displayed as a datasheet, as in the preceding illustration, or it can be displayed as a single or continuous form. A main form can only be displayed as a single form. To see examples of different types of subforms, click  [image].

A main form can have any number of subforms if you place each subform on the main form. You can also nest up to two levels of subforms. This means you can have a subform within a main form, and you can have another subform within that subform. For example, you could have a main form that displays customers, a subform that displays orders, and another subform that displays order details.


Types of subforms

When you create a subform, you can design it to be displayed: in Datasheet view only; in Form view only as a single or continuous form; or in either view. Subforms displayed as a single or continuous form can be simple or they can be customized extensively to include headers, footers, and so on.

For information on creating this type of subform, click  [image].

For information on subforms and how they work, click  [image].


Create a subform

How you create a subform depends on whether you want to create a main form and a subform at the same time, create a subform and add it to an existing form, or add an existing form to another existing form to create a form with a subform.

What do you want to do?

Create a form and a subform at the same time

Create a subform and add it to an existing form

Add an existing form to another existing form to create a form with a subform


Create a form and a subform at the same time

Before using this procedure, make sure you've set up your table relationships correctly. For more information, click  [image].

1	In any Microsoft Access window, click the arrow next to the New Object button, and then click New Form.

2	In the New Form dialog box, double-click Form Wizard in the list.

3	In the first wizard dialog box, select a table or query from the list. For example, to create a Categories form that displays products for each category in a subform, select the Categories table (the "one" side of the one-to-many relationship).

Note   It doesn't matter which table or query you choose first.

4	Click the fields you want to include from this table or query.

5	In the same wizard dialog box, select another table or query from the list. Using the same example, select the Products table (the "many" side of the one-to-many relationship in the Categories form example).

6	Click the fields you want to include from this table or query.

7	When you click Next, if you set up the relationships correctly before starting the wizard, the wizard asks which table or query you want to view by. Using the same example, to create the Categories form, click By Categories.

8	In the same wizard dialog box, select the Form/Subform option.

9	Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft Access creates two forms, one for the main form and subform control, and one for the subform.

Notes

•	For information on changing the layout of a subform that the wizard creates, click  [image].

•	For information on calculating a total in a subform and displaying that total on a main form, click  [image].

•	For information on troubleshooting subforms, click  [image].


Create a subform and add it to an existing form

Before using this procedure, make sure you've set up your table relationships correctly. For more information, click  [image].

1	In Design view of the form you want to add the subform to, make sure  [image]  in the toolbox is pressed in.

2	Click  [image]  in the toolbox.

3	On the form, click where you want to place the subform.

4	Follow the directions in the wizard dialog boxes.

5	When you click Finish, Microsoft Access adds a subform control to your form. It also creates a separate form that the subform control uses to display the subform.

Notes

•	For information on changing the layout of a subform that the wizard creates, click  [image].

•	For information on calculating a total in a subform and displaying that total on a main form, click  [image].

•	For information on troubleshooting subforms, click  [image].


Add an existing form to another existing form to create a form with a subform

Before using this procedure, make sure you've set up your table relationships correctly. For more information, click  [image].

1	Open the form that you want to use as the main form in Design view. This is usually a form based on a table or query on the "one" side of a one-to-many relationship.

2	Make sure  [image]  is pressed in.

3	Press F11 to switch to the Database window.

4	Drag a form or datasheet from the Database window to the main form.

Microsoft Access adds a subform control to the form. If you dragged a form displayed in Form view, Microsoft Access displays the subform in that view. If you dragged a datasheet, Microsoft Access displays the subform as a datasheet.

Notes

•	For information on changing the layout of a subform, click  [image].

•	For information on calculating a total in a subform and displaying that total on a main form, click  [image].

•	For information on troubleshooting subforms, click  [image].


Understanding how main forms and subforms are linked

You usually use a subform to display data from tables or queries that have a one-to-many relationship. For example, a Categories table and a Products table have a one-to-many relationship — each category can have more than one product.

When you create a form and subform based on tables that have a one-to-many relationship, the main form shows the "one" side of the relationship and the subform shows the "many" side of the relationship. The main form is synchronized with the subform so that the subform shows only records related to the record in the main form. If you use a wizard to create a subform, or if you drag a form or datasheet from the Database window to another form to create a subform, Microsoft Access automatically synchronizes the main form with the subform if both of the following are true:

•	The tables you select have relationships that you've set in the Relationships window. This is usually a one-to-many relationship. If you select a query or queries, Microsoft Access automatically synchronizes the form and subform if the tables underlying the query or queries meet these conditions. For example, you might use a query based on a single table to calculate a value in a field. As long as this underlying table is correctly related to the other underlying table or query, Microsoft Access automatically synchronizes the form and subform.

•	The main form is based on a table with a primary key and the subform is based on a table that contains a field with the same name as that primary key and with the same or a compatible data type. For example, if the primary key of the main form is AutoNumber and the FieldSize property for the field is set to Long Integer, the corresponding field in the subform should be a Number field and the FieldSize property for that field should be set to Long Integer. If you select a query or queries, the underlying tables for the query or queries must meet these conditions.

Notes

•	Microsoft Access uses the LinkMasterFields and LinkChildFields properties of the subform control to link the main form and subform. If, for some reason, Microsoft Access doesn't link the form and subform, you can set these properties directly.

How?

•	For information on setting up relationships, click  [image].

•	For information on creating a primary key, click  [image].


Link a main form and a subform

If you create a subform with the Form Wizard or the Subform Wizard, Microsoft Access automatically links the main form with the subform under certain conditions. For more information, click  [image].  If your main form and subform don't meet these conditions, you can use this procedure to link them.

1	In Design view of the main form, click the subform control.

2	Click  [image]  on the toolbar to display the property sheet for the subform control.

3	In the LinkChildFields property box, enter the name of the linking field in the subform. If you're unsure what the linking field is, click the Build button to open the Subform/Subreport Field Linker. To enter more than one linking field, separate field names with semi-colons. If you enter more than one linking field, you must enter the fields in the same order in the LinkChildFields and LinkMasterFields properties.

Note   You can't use the name of a control in the LinkChildFields property.

4	In the LinkMasterFields property box, enter the name of the linking field in the main form. If you're unsure what the linking field is, click the Build button to open the Subform/Subreport Field Linker. To enter more than one linking field, separate field names with semi-colons. If you enter more than one linking field, you must enter the fields in the same order in the LinkChildFields and LinkMasterFields properties.

Notes

•	The linking fields don't have to appear in the main form or the subform, but they must be included in the underlying record source. If you use the Form Wizard to create the subform, Microsoft Access automatically includes the linking fields in the underlying record source even if you don't pick them in the wizard.

•	The linking fields must contain the same kind of data and have the same or a compatible data type or field size. For example, an AutoNumber field is compatible with a Number field whose FieldSize property is set to Long Integer.

•	For information on troubleshooting subforms, click  [image].


Create a form with two subforms

Before using this procedure, make sure you've set up your table relationships correctly. For more information, click  [image].

You can use this procedure to create a form and two subforms that have a one-to-many-to-many relationship. The main form has a one-to-many relationship with the first subform, and the first subform has a one-to-many relationship with the second subform.

1	In any Microsoft Access window, click the arrow next to the New Object button, and then click New Form.

2	In the New Form dialog box, double-click Form Wizard in the list.

3	In the first wizard dialog box, select the table or query for the main form. For example, suppose you want to create a Customers form that has two subforms — an Orders subform and an Order Details subform. Select the Customers table (the "one" side of the table from the first one-to-many relationship).

Note   It doesn't matter which table or query you choose first.

4	Click the fields you want to include from this table or query.

5	In the same wizard dialog box, select the table or query for the first subform. Using the same example, select the Orders table (the "many" side of the first one-to-many relationship), and then click the fields you want to include from this table or query.

6	In the same wizard dialog box, select the table or query for the second subform. Using the same example, select the Order Details table (the "many" side of the second one-to-many relationship), and then click the fields you want to include from this table or query.

7	When you click Next, if you set up the relationships correctly before starting the wizard, the wizard asks which table or query you want to view by. Using the same example, to create the Customers form, click By Customers.

8	In the same wizard dialog box, select the Form/Subform option.

9	Follow the directions in the remaining wizard dialog boxes. When you click Finish, Microsoft Access creates a form with two subform controls. It also creates two other forms, one for each subform.

Notes

•	When you use a wizard to create a form with two subforms, Microsoft Access synchronizes the subforms by attaching an event procedure to the OnCurrent property of the first subform. You can copy and modify this event procedure if you want to synchronize more subforms on the same form. To see this event procedure, open the first subform in Design view, double-click the form selector, and then click the Build button next to the OnCurrent property.

•	For information on changing the layout of a subform that the wizard creates, click  [image].

•	For information on troubleshooting subforms, click  [image].


Create a form with a subform that contains another subform

Before using this procedure, make sure you've set up your table relationships correctly. For more information, click  [image].

You can use this procedure to create a form and two levels of subforms that have a one-to-many-to-many relationship. The main form has a one-to-many relationship with the first subform, and the first subform has a one-to-many relationship with the second subform.

1	Create a form with a subform.

How?

Note   Make sure to select the Tabular (the equivalent of Form view) option when the wizard asks what layout you want for the subform. If you select the Datasheet option, you won't be able to insert a subform inside the subform.

2	In Design view of the main form, make sure the subform control isn't selected.

3	Double-click inside the subform control.

Microsoft Access opens the subform in Design view.

4	Do one of the following:

•	Use the Subform Wizard to create the second subform.
  How?

•	Drag a form or datasheet from the Database window to the subform.

Microsoft Access creates another subform inside the first subform.

5	Save and close the subforms.

6	Switch to Form view to see the form and subforms.

Notes

•	For information on changing the layout of a subform, click  [image].

•	For information on troubleshooting subforms, click  [image].


Switch between Datasheet view and Form view in a subform

1	Open the main form in Form view.

2	Click anywhere in the subform.

3	On the View menu, click Subform Datasheet.

Note   The ViewsAllowed property for the subform must be set to Both in order to switch views.


Move between a main form and a subform in Form view

Using the TAB key

•	To move from the last field in the main form to the first field in the subform, press TAB.

•	To move from the first field in the subform back to the last field in the main form, press CTRL+SHIFT+TAB.

•	To move from the last field in the subform to the first field in the next record of the main form, press CTRL+TAB.

Using the mouse

•	To switch from the main form to the subform, click anywhere in the subform.

•	To switch from the subform back to the main form, click a control on the main form (not the background of the main form).


Change the layout of a subform

How you change the layout of a subform depends on whether the subform is displayed in Datasheet view or in Form view as a single or continuous form.

What do you want to do?

Change the layout of a subform displayed in Datasheet view

Change the layout of a subform displayed as a single or continuous form

Change the view that the subform is displayed in


Change the layout of a subform displayed as a single or continuous form

1	In Design view of the main form, make sure the subform control isn't selected.

2	Double-click inside the subform control.

Microsoft Access opens the subform in Design view.

3	Make changes to the design.

4	Save and close the subform.

5	Switch to Form view to see the changes.

Notes

•	If you change the width of a form displayed as a subform, you must also adjust the width of the subform control on the main form.

•	You can also change the layout of the subform by opening the subform directly from the Database window.


Change the layout of a subform displayed in Datasheet view

In Form view of the main form, you can do any of the following in the subform:

•	To change the width of a column, drag the right edge of the column selector. To automatically size the column to fit its data, double-click the right edge of the column selector.

•	To change the order of columns, click a column heading to select the column. Then click the column heading again, hold down the mouse button, and drag the column to a new location.

•	To change the height of all the rows, drag the bottom edge of the row selector.

•	To hide a column, click anywhere in the column, and then click Hide Columns on the Format menu.

•	To freeze a column, click anywhere in the column, and then click Freeze Columns on the Format menu.

Note   If you need to adjust the size of the subform itself, size the subform control in Design view of the main form.


Specify the view (datasheet, single form, or continuous forms) for a subform

If you use the Form Wizard or the Subform Wizard to create a subform, Microsoft Access sets the DefaultView property of the subform according to the choices you make in the wizard dialog boxes. Use this procedure if you're creating a subform on your own or if you want to change the view you specified in the wizard.

1	In Design view of the main form, make sure the subform control isn't selected.

2	Double-click inside the subform control.

Microsoft Access opens the subform in Design view.

3	Double-click the form selector to open the subform's property sheet.

4	In the DefaultView property box, click Single Form, Continuous Forms, or Datasheet.

5	In the ViewsAllowed property box, click the Form setting if you don't want to be able to switch to Datasheet view. Click the Datasheet setting if you don't want to be able to switch to Form view. If you want to be able to switch back and forth between Datasheet and Form views, click the Both setting.

Notes

•	To see examples of different types of subforms, click  [image].

•	You can also change the layout of the subform by opening the subform directly from the Database window.


Example of synchronizing a combo box and two subforms

The Sales Totals form in the Solutions sample application has an example of synchronizing a combo box and two subforms.

To view this form, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Use two subforms on a form.

For information on opening the Solutions sample application, click  [image].


 Troubleshoot forms

What do you need help with?

I don't understand how forms work. Please give me an overview.

My form is blank. Why can't I see my data?

Why can't I edit data in my form?

I can see data from only one table. How can I see data from other tables?

My form is too slow. What can I do to improve its performance?

I need help troubleshooting problems with controls on my form.

I need help troubleshooting problems with a combo box or list box on my form.

I need help troubleshooting problems with a subform on my form.

I need help troubleshooting problems with an option group on my form.

I need help troubleshooting problems with pictures or other OLE objects on my form.


My form is blank. Why can't I see my data?

A form may appear blank for any of the following reasons:

•	The form may not be bound to an underlying record source (table, query, or SQL statement). To bind a form to an underlying record source, open the form in Design view, and then double-click the form selector to open the property sheet. In the RecordSource property box, click a record source in the list or click the Build button to open the Query Builder.

•	The form may be bound to an underlying record source that doesn't have any data. Check the underlying record source to make sure that it has data.

•	The form may be based on a query that doesn't return any data. To see if the query returns data, double-click the form selector to open the form's property sheet, click the Build button next to the RecordSource property box to open the Query Builder, and then click  [image]  in the Query Builder.

•	The form may be open in Data Entry mode. When a form is open in Data Entry mode, it displays a blank record so that you can add data. To show all the records, click the Remove Filter/Sort command on the Records menu.

•	The form header or form footer may be so large that there's no room for the detail section.


Why can't I edit data in my form?

You may not be able to edit data in a form for any of the following reasons:

•	The form was created as a read-only form. If the AllowDeletions, AllowAdditions, and AllowEdits properties of the form are set to No, you won't be able to make changes to the underlying data.

•	Someone else may be using the form at the same time, and the RecordLocks property for the form is set to All Records or Edited Record. You'll see  [image]  in the record selector if this is the case. Wait a while, and try again.

•	You may be trying to edit data in a calculated control. A calculated control displays the result of an expression. The data displayed in a calculated control isn't stored, so it can't be edited.

•	The underlying query or SQL statement for the form may not be updatable. For more information on which types of queries are updatable, click  [image].


I can see data from only one table. How can I see data from other tables?

To see data from more than one table, you must base your form on a query that brings the data from the tables together. To create a multiple-table query without closing the form, do the following:

1	In form Design View, double-click the form selector to open the form's property sheet.

2	Click in the RecordSource property box, and then click the Build button next to the property box to open the Query Builder.

3	In the Query Builder, add the tables and fields you want to include in the underlying query, and then close the Query Builder.

Microsoft Access updates the RecordSource property to use the query you created.

For information on adding tables in the Query Builder, click  [image]. For information on adding fields in the Query Builder, click  [image].

Note   You can also create a multiple-table form by using a wizard. For more information, click  [image].


Troubleshoot problems with controls

What do you need help with?

#Error? or #Name? appears in the control.

I can't edit the data in a control.


#Error? or #Name? appears in the control.

#Error? or #Name? may appear in a control for a number of reasons. To correct the problem, do the following:

•	Make sure that the field specified in the control's ControlSource property hasn't been removed from the underlying table, query, or SQL statement.

•	Check the spelling of the field name in the control's ControlSource property.

•	If you specified an expression in the control's ControlSource property, make sure that there is an equal sign preceding the expression.

•	Make sure that there are brackets around references in expressions to control or field names that include spaces. For example, to subtract a Shipped Date field from a Required Data field, enter the following expression: =[Required Date]-[Shipped Date].

•	If you are using one of the built-in functions, make sure that you're using the right number of arguments, that the arguments are in the right order, and that you haven't left out any necessary punctuation. To determine the correct syntax to use, see the Help topic for the function you're using.

•	If you are referring to another control, make sure that you're using the correct syntax. For more information on referring to controls, click  [image].

•	Make sure that there isn't a circular reference to a control. For example, if you specify MyControl in the Name property of a control, and then type =[A]+[B]+[MyControl] in the ControlSource property box for the control, Microsoft Access can't process the expression.


I can't edit the data in a control.

You may not be able to edit the data in a control for any of the following reasons:

•	The form was created as a read-only form, so you can't use any of the controls on the form to edit data. If the AllowDeletions, AllowAdditions, and AllowEdits properties of the form are set to No, you won't be able to make changes to the underlying data.

•	The Locked property for the control is set to Yes.

•	Someone else may be using the form at the same time, and the RecordLocks property for the form is set to All Records or Edited Record. You'll see  [image]  in the record selector if this is the case. Wait a while, and try again.

•	You may be trying to edit data in a calculated control. A calculated control displays the result of an expression. The data displayed in a calculated control isn't stored, so it can't be edited.

•	The underlying query or SQL statement for the form may not be updatable. For more information on which types of queries are updatable, click  [image].


Troubleshoot list boxes and combo boxes

I don't understand how list boxes work. Please give me an overview.

I don't understand how combo boxes work. Please give me an overview.

The list box or combo box isn't sorted the way I want.

The text displayed in the combo box is from the wrong column. How do I display data from another column?

When I select a value in a list, it disappears or gives me an error message.

I can't select a value in the list box or combo box.

#Error? appears in the combo box or the combo box is blank.

I want to refer to a column in the list box or combo box other than the bound column.

I can't type a new value in the combo box.

Why isn't a value that I type in the combo box added to the list?

My list box or combo box is too slow. What can I do to speed it up?


The text displayed in the combo box is from the wrong column. How do I display data from another column?

In a multiple-column combo box, the text box portion of the combo box displays data from the first visible column in the list. You use the ColumnWidths property to determine which columns are visible. For example, if you have a combo box based on a query that includes the SupplierID field and the SupplierName field, in that order, Microsoft Access displays the SupplierID field in the text box portion of the combo box unless you hide it using the ColumnWidths property. For more information on hiding a column in a list box or combo box, click  [image].


When I select a value in a list, it disappears or gives me an error message.

You may have specified the wrong column in the BoundColumn property box. The BoundColumn property determines which column's data is stored in the field specified in the ControlSource property box. For example, if you have a combo box that has a SupplierID column and a SupplierName column, the bound column would be the SupplierID column (the foreign key field) even if the SupplierName column is the only visible column.


I can't select a value in the list box or combo box.

You may have misspelled the field name in the ControlSource property box. You use the RowSource property to specify the items that make up the list. When you click an item in the list, Microsoft Access needs to know where to store the value you selected. You use the ControlSource property to specify where the values are stored.


#Error? appears in the combo box or the combo box is blank.

You probably entered an inappropriate setting in one of the following properties: RowSource, ControlSource, BoundColumn, ColumnWidths, ColumnCount. To read about these and other properties you can use in a list box or combo box, click  [image].


I want to refer to a column in the list box or combo box other than the bound column.

To refer to a column other than the bound column, use the Column property. The Column property is zero-based. For example, to refer to the second column in the combo box called SuppliersCombo on the Products form, use this syntax:

Forms![Products]![SuppliersCombo].Column(1)


I can't type a new value in the combo box.

The LimitToList property is set to Yes. Set the LimitToList property to No so that you can type new values in the combo box. If the column displayed in the text box portion of the combo box isn't the bound column, Microsoft Access automatically sets the LimitToList property to Yes.


Why isn't a value that I type in the combo box added to the list?

To automatically add a value to the list, you need to write an event procedure and attach it to the combo box's OnNotInList property. The Solutions sample application has an example of using the NotInList event. To see this example, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Get more mileage from combo boxes, list boxes, subforms, and subreports. In the lower list box, click the entry that reads: Add a new record to a list.

For information on opening the Solutions sample application, click  [image].

Note   You must set the LimitToList property to Yes to use the NotInList event.


Specify a default value that is automatically entered in a combo box

1	In form Design view, double-click the combo box to open its property sheet.

2	In the DefaultValue property box, type [comboboxname].ItemData(n) where n is the row that you want to use as the default. The ItemData method is zero-based, so type ItemData(0) if you want to make the first row in the list the default. For example, to specify the first row of the SupplierCombo combo box as the default for the combo box, type [SupplierCombo].ItemData(0) in the DefaultValue property box.

Note   If you want to specify a default value for a lookup combo box in table Design view, enter a default value in the DefaultValue property for the foreign key field. For example, if you have a SupplierID foreign key field in a Products table, click the SupplierID field, and enter a valid supplier ID number in the DefaultValue property box in the lower portion of the window. The next time you add this field to a form, Microsoft Access automatically sets the default value for the field.


Troubleshoot subforms

I don't understand how subforms work. Please give me an overview.

All of my records show up in my subform — they don't change when I move from record to record in the main form.

I get #Error? or #Name? when I try to display data from my subform on my main form.

Why can't I display form headers and form footers in my subform datasheet?

My subform is too slow. What can I do to speed it up?


All of my records show up in my subform-they don't change when I move from record to record in the main form.
All of my records show up in my subform — they don't change when I move from record to record in the main form.

You need to link your main form and subform using the LinkChildFields and LinkMasterFields properties. For information on linking a main form and a subform, click  [image].

If you've already set the LinkChildFields and LinkMasterFields properties and the subform still doesn't work, make sure that you aren't using fields that have been renamed or deleted. Also make sure that you've spelled the field names correctly and that you're using the actual field names, not the control names specified in the Name property.

Note   Under certain circumstances, Microsoft Access will automatically link a main form and a subform when you use a wizard to create the subform. For more information, click  [image].


I get #Error? or #Name? when I try to display data from my subform on my main form
I get #Error? or #Name? when I try to display data from my subform on my main form.

To display a value from a subform on a main form, create a calculated control that refers to the subform control using the following syntax:

=Forms![formname]![subformname].Form![controlname]

For example, suppose you have an Orders form and an Orders Subform. In the form footer of the subform, you have a text box named OrderSubtotal that sums the records in the subform. To display the value of this control on the main form, use the following expression:

=Forms![Orders]![Orders Subform].Form![OrderSubtotal].

To learn more about calculating a total for a group of records on a form, click  [image].

If you're already using this syntax and you still get an error, check to make sure that the form, subform, and control names are correct. Make sure that the names you're referring to are the names specified in the Name property for each object. Also make sure that you're including the exclamation point in the right places.

You can also use the Expression Builder to help you refer to other controls. For information on using the Expression Builder, click  [image].


Why can't I display form headers and form footers in my subform datasheet?

Although subforms with their DefaultView property set to Datasheet view can have a form header and form footer, Microsoft Access displays the header and footer only in Design view. You can display a form header and footer in a subform and make it look like a datasheet by sizing the detail section of the form to the size of a single row and setting the DefaultView property of the subform to Continuous Form. For more information, click  [image].


Troubleshoot pictures and other OLE objects on Microsoft Access forms and reports

I don't understand the difference between unbound and bound, embedded and linked objects. Please give me an overview.

When I double-click a linked or embedded object, I get an error saying the file can't be opened.

I want to see the content of my object in my form or report, but I see an icon instead.

My picture becomes distorted when I size it.

Why do the colors in my picture look so bad?


When I double-click a linked or embedded object, I get an error saying the file can't be opened.

Microsoft Access displays this message when it can't open the source file for an OLE object. Check to make sure that:

•	The application needed to edit the file is installed on your computer.

•	You have enough memory to run the source application. Close other applications to free up memory.

•	If the application you're trying to open is already running, make sure that it doesn't have any open dialog boxes.

•	If it's a linked object, make sure that someone else doesn't already have it open.

•	If it's a linked object, make sure that the name of the source file hasn't changed or that the source file hasn't been moved. To see the name of the original file, click the object, and then click OLE/DDE Links on the Edit menu. The original filename appears in the Links box. If the file has been renamed or moved, click the link in the Links box, and then click Change Source to reconnect the link.


My picture becomes distorted when I size it.

To keep a picture's proportions when you size it, use the PictureSizeMode property (for background pictures) or the SizeMode property (for bound object frames, unbound object frames, and image controls). If the picture is a bitmap, it's best to use the Zoom setting rather than the Stretch setting. You should also consider using a metafile rather than a bitmap since you can size metafiles without causing distortions. For information on using metafiles rather than bitmaps, click  [image].


Why do the colors in my picture look so bad?

If the picture you're displaying was created on a computer that has more colors than the computer you're displaying the picture on, Microsoft Windows substitutes colors to match the original colors. This process is known as dithering. For example, you may be trying to display a picture created with 256 colors on a computer that only displays 16 colors (standard VGA). If your computer can display more colors, you can specify that Microsoft Access use the color palette used to create the picture. For more information, click  [image].


Troubleshoot option groups

I don't understand how option groups work. Please give me an overview.

I added a check box, toggle button, or option button to an option group, but the option group doesn't work.


I added a check box, toggle button, or option button to an option group, but the option group doesn't work.

You may have placed the control outside the option group. When you add a check box, toggle button, or option button to an option group, Microsoft Access highlights the option group to show that the control will become part of the option group. If the option group isn't highlighted, you're probably placing the control too close to the edge of the option group.


I want to see the content of my object in my form or report, but I see an icon instead.

1	Open the form or report in Design view.

2	Click the icon.

3	On the Edit menu, point to the appropriate Object command (for example, point to Worksheet Object for a Microsoft Excel object), and then click Convert.

4	In the Convert dialog box, clear the Display As Icon check box.


Add a new chart to a form or report

To add a chart, you must have Microsoft Graph 5.0 installed. Microsoft Access does not install Microsoft Graph by default in a Typical setup.

1	If any of the tables that you need to create the chart are in another database or application, import or link them to your Microsoft Access database.

  How?

2	Decide which table or query will supply the data for the chart. If you're going to use a query, create the query, and include these fields:

•	The fields containing the data that will be charted. At least one of these fields must have a Number, Currency, or AutoNumber field data type.

•	The fields containing the labels you want to display in the chart.

•	The linking fields, if you want the chart to change from record to record. The values in the linking field must match record for record the values in a field in the underlying table or query for the form or report. For example, suppose the form's underlying table includes the ProductID field. You want to link your chart on this field, so you include the ProductID field in the chart's underlying query.

3	In form or report Design view, click Chart on the Insert menu.

Tip   If you create a lot of charts, you may want to add [image]  to the toolbar.

How?

4	On the form or report, click where you want to place the chart.

5	Follow the directions in the Chart Wizard.

Notes

•	For information about customizing a chart, click  [image].

•	The Chart Wizard creates a RowSource query, which reflects the data restrictions that you specified when you filled out the Chart Wizard dialog boxes. If the chart doesn't look the way you want it to look, click  [image].


Add an existing chart to a form or report

The best way to add a chart to your database is to create a new one using the Chart Wizard. This way, the chart will automatically be updated when your data changes. If you want to copy or move a chart you created with the Chart Wizard from one form or report to another in the same database, simply copy and paste it. For information on creating a new chart, click  [image].

You can use this procedure to add an existing chart that was created in another Microsoft Access database or another program. When you do this, you will not be able to change the chart by changing data in your database.

1	In form or report Design view, click  [image]  in the toolbox.

2	On the form or report, click where you want to place the chart.

3	In the Insert Object dialog box, click Create From File, and then specify a path to the file. If you don't know the path, click Browse.

4	If you want to link rather than embed the chart, select the Link check box.

5	Select the Display As Icon check box if you want the chart to appear as an icon.

6	Click OK.


Link an existing chart to a specific record

In most cases, the Chart Wizard will determine from the data you specify whether it should display data from all fields in one chart, or whether it is more appropriate to show a different chart for each record, so that when you move from record to record you see a chart that represents only the data in the current record. However, if the Chart Wizard creates one global chart, and you want a record-bound chart, you can link the chart to a specific record by following this procedure.

1	In form or report Design view, click the chart.

2	On the View menu, click Properties.

3	In the LinkChildFields and LinkMasterFields property boxes, type the name of a field that appears in the RowSource property box and uniquely identifies each record, such as a primary key.

The values in these property boxes must match record for record the values in a field in the underlying table or query for the form or report. For example, suppose the form's underlying table includes the ProductID field. You want to link your chart on this field, so you type ProductID in the LinkChildFields and LinkMasterFields property boxes.

4	To see whether your chart displays only the data for the current record, display the form in Form view, or look at the report in Print Preview.


Change the size of a chart

1	In form or report Design view, click the chart.

2	Move the mouse pointer over any of the sizing handles until the pointer becomes a double-headed arrow.

3	Drag the handle to where you want the edge of the object to be, and then release the mouse button.


Edit a chart

The method you use to edit a chart depends on what you want to change.

To change the appearance of a chart, including the location of its parts, the text format, the colors and patterns, and the axis scaling, use Microsoft Graph.

If you want to change the data in a chart, the method you use depends on where the data came from.

When you use the Chart Wizard to create a chart that displays data from Microsoft Access, you choose the table or query that includes the fields that are displayed in the chart. This underlying table or query contains the data, such as sales figures or customer lists. After you have finished making selections in the Chart Wizard, Microsoft Access creates a query called a RowSource query, which is based on the underlying table or query. The RowSource query reflects the choices you made in the Chart Wizard to restrict the data, such as a range of dates or orders from a specific region.

The data you want to change may be stored in the underlying table or query, or in the RowSource query.

For example, if you notice that the sales figures in your chart are wrong, the problem may be in the data stored in the underlying table, or in the design of the underlying query. In this case, correct the underlying table or query. However, if you left out a field that you want to appear in your chart, you can either use the Chart Wizard to create the chart again, or you can edit the RowSource query.

What do you want to do?

Change the appearance of the chart

Change the underlying table or query

Change the RowSource query

Re-create the chart using the Chart Wizard


 Change the appearance of a chart

1	In form or report Design view, double-click the chart to open Microsoft Graph.

2	Make the changes you want.

For information about customizing a chart, see  [image].

For information about using Microsoft Graph, press F1 to open Microsoft Graph Help.

3	When you finish editing, click Exit or Exit And Return on the Microsoft Graph File menu.

4	When the application prompts you to update the object, click Yes.

Note  Although you can change the data that appears in your chart by editing the datasheet in Microsoft Graph, changes to the data as well as some formatting changes will be overwritten by Microsoft Access. To change the data that is displayed in your chart, you should change the underlying table or query, or the RowSource query. For information on changing the RowSource query, click  [image].


Change the underlying table or query for a chart

To change the underlying table

•	Open the underlying table in Datasheet view and then edit the data.

To change the underlying query

•	Open the underlying query in Design view and then edit the query.

When you have changed the underlying table or query, you must reopen the form or report that contains the chart to see the changes.

If changing the underlying table or query doesn't work, you can try changing the RowSource query. For information on changing the RowSource query, click  [image].


Change the RowSource query for a chart

1	In form or report Design view, click the chart.

2	On the View menu, click Properties.

3	Click in the RowSource property box, and then click the Build button to the right of the RowSource property box to open the Query Builder.

The Query Builder displays the RowSource query in Design view.

4	Change the query.

To preview your changes, click Datasheet on the View menu.

5	Close the Query Builder.

6	To see the changes to the chart in a form, open the form in Form view , or open the report in Print Preview.

When you have changed the RowSource query, you must reopen the form or report that contains the chart to see the changes.

If changing the RowSource query doesn't work, you can try changing the underlying table or query. For information on changing the underlying table or query, click  [image].


Convert a chart to a picture to save disk space

When you add a chart to your database, you can open Microsoft Graph directly from Microsoft Access by double-clicking the chart. This makes it easy to edit the appearance of the chart. If you need to save disk space, you can convert the chart to a picture, as long as the chart isn't a record-bound chart. However, if you do this, you can't edit the chart.

1	In form or report Design view, click the chart.

2	On the Format menu, point to Change To, and then click Image.


Troubleshoot charts

What do you need help with?

I change my chart, but the changes aren't retained.

I get the message "Can't bind name name" when trying to display a chart.

My chart appears dimmed or blank.

I can't change the format of the labels on my chart.

I can't put the columns on my chart in the order I want.


I change the chart, but the changes aren't retained.
I change my chart, but the changes aren't retained.

A chart is made up of information from the following places, in order of precedence:

•	The data in the underlying table or query

•	The contents of the chart's RowSource property

•	The Microsoft Graph application

Microsoft Access regenerates the chart each time you print or preview the chart, or switch to Form view. Therefore, changes that you make using Microsoft Graph might be overwritten by the underlying data or the RowSource property.

Keep the following in mind when you change your chart:

•	Changes to the underlying data (such as the format of the data) have precedence over other changes. However, if the RowSource property setting contains a calculated field, such as =Format([StartDate],"MMM"), the format is determined by the result of the calculation, not by the underlying data.

•	Changes in the RowSource property, such as changes to the chart's title and labels, can be overwritten by changes in the underlying data.

•	Changes you make using Microsoft Graph, such as changes based on the data, can be overwritten by changes you make in the underlying table or query or in the RowSource property.

For information about the RowSource property, click  [image].


My chart appears dimmed or blank.

If the RowSource property for a chart is invalid, the chart will be dimmed or blank.

1	Open the form that contains the chart in Design view.

2	Click the chart.

3	On the View menu, click Properties.

4	Make sure the RowSource property box contains a valid value.

For information about the RowSource property, click  [image].

5	Close the form and save the changes.

6	Switch to Form view or Print Preview to view the changes.


I can't change the format of the labels on my chart.

If you use Microsoft Graph to change the format of labels on your chart's axes, the changes are overwritten when the chart is updated. To make these changes permanent, you must modify the chart's RowSource query.

1	Open the form or report that contains the chart in Design view.

2	Click the chart.

3	On the View menu, click Properties.

4	Click the Build button to the right of the RowSource property box.

5	In the query, replace the name of the field you want to format with the field name and the Format function.

For example, if a field is ([OrderDate]), you can change it to Format([OrderDate],"YY") to change how the date appears on your chart. For more information about the Format function, click  [image].

6	Close the query and save the changes.

7	Switch to Form view or Print Preview to view the changes.

Note   Not all Microsoft Access custom formats work with Microsoft Graph.


I can't put the columns on my chart in the order I want.

To make your data appear in a different order, you can modify the query specified by the chart's RowSource property.

1	Open the form or report that contains the chart in Design view.

2	Click the chart.

3	On the View menu, click Properties.

4	Click the Build button to the right of the RowSource property box.

5	In the query, put the fields you want sorted in the order, left to right, that you want them sorted, and make sure the Sort cell for those fields has the value you want.

For more information about sorting fields in a query, click  [image].

6	Close the query and save the changes.

7	Switch to Form view or Print Preview to view the changes.


Work in the Database window by using the keyboard

What do you want to do?

Navigate in the list of database objects

Open an object in the Database window

Move between open database object windows


Navigate in the list of database objects by using the keyboard

To move	Press
Down one line	DOWN ARROW
Down one window	PAGE DOWN
To the last object	END
Up one line	UP ARROW
Up one window	PAGE UP
To the first object	HOME


Open objects in the Database window by using the keyboard

To	Press
Open the selected table or query in Datasheet view, or form in Form view	ENTER
Open the selected report in Print Preview	ENTER
Run the selected macro	ENTER
Open the selected table, query, form, report, macro, or module in Design view	CTRL+ENTER or ALT+D


Move between open database object windows by using the keyboard

To	Press
Bring the Database window to the front	F11 or ALT+F1
Cycle between open windows	CTRL+F6


Enter and edit data by using the keyboard

What do you want to do?

Enter data in Datasheet or Form view

Copy, move, or delete text

Undo changes

Select the current field or display the insertion point

Move the insertion point within a field


Enter data in Datasheet or Form view by using the keyboard

To	Press
Insert the current date	CTRL+SEMICOLON (;)
Insert the current time	CTRL+COLON (:)
Insert the default value for a field	CTRL+ALT+SPACEBAR
Insert the value from the same field in the previous record	CTRL+APOSTROPHE (')
Add a new record	CTRL+PLUS SIGN (+)
Delete the current record	CTRL+MINUS SIGN (-)
Save changes to the current record	SHIFT+ENTER
Toggle between the values in a check box or option button	SPACEBAR


Copy, move, or delete text by using the keyboard

To	Press
Copy the selection onto the Clipboard	CTRL+C
Paste the contents of the Clipboard at the insertion point	CTRL+V
Cut the selection and copy it onto the Clipboard	CTRL+X
Delete the selection or the character to the left of the insertion point	BACKSPACE
Delete the selection or the character to the right of the insertion point	DEL


Undo changes by using the keyboard

To undo	Press
Typing	CTRL+Z
Changes in the current field or current record; if both have been changed, press ESC twice to undo changes first in the current field and then in the current record	ESC


Select the current field by using the keyboard

•	Press F2.


Move the insertion point within a field by using the keyboard

If the insertion point isn't visible, press F2 to display it.

To move	Press
One character to the right	RIGHT ARROW
One word to the right	CTRL+RIGHT ARROW
To the end of the field, in single-line fields	END
To the end of the field, in multiple-line fields	CTRL+END
One character to the left	LEFT ARROW
One word to the left	CTRL+LEFT ARROW
To the beginning of the field, in single-line fields	HOME
To the beginning of the field, in multiple-line fields	CTRL+HOME


Select text by using the keyboard

What do you want to do?

Select text within a field

Select a field or cancel a selection

Select a record

Select a column

Extend a selection


Select text within a field by using the keyboard

To extend the selection one	Press
Character to the right	SHIFT+RIGHT ARROW
Word to the right	CTRL+SHIFT+RIGHT ARROW
Character to the left	SHIFT+LEFT ARROW
Word to the left	CTRL+SHIFT+LEFT ARROW
To cancel a selection, use the opposite arrow key.


Select a field or cancel a selection by using the keyboard

To	Press
Select the current field or cancel the selection	F2
Select the next field	TAB


Select a record in Datasheet view by using the keyboard
Select a record by using the keyboard

To	Press
Toggle between selecting the current record and the first field of the current record, in Navigation mode only; if you're not in Navigation mode, press F9	SHIFT+SPACEBAR
Extend selection to the previous record, if the current record is selected	SHIFT+UP ARROW
Extend selection to the next record, if the current record is selected	SHIFT+DOWN ARROW
All records	CTRL+A


Select a column in Datasheet view by using the keyboard

To select the	Press
Current column or cancel the column selection, in Navigation mode only	CTRL+SPACEBAR
Column to the right, if the current column is selected	SHIFT+RIGHT ARROW
Column to the left, if the current column is selected	SHIFT+LEFT ARROW


Extend a selection by using the keyboard

You can use shortcut keys to extend a selection by entering Extend mode. Once you're in Extend mode, you can use arrow keys to extend a selection. You must cancel Extend mode to use arrow keys to navigate normally.

To	Press
Turn on Extend mode; pressing F8 repeatedly extends the selection to the word, the field, the record (in Datasheet view only), and all records; you can tell you're in Extend mode because EXT appears in the lower right corner of the window	F8
Extend a selection to adjacent rows in Datasheet view	UP ARROW OR DOWN ARROW
Undo the previous extension	SHIFT+F8
Cancel Extend mode	ESC


Navigate in Datasheet view by using the keyboard

What do you want to do?

Go to a specific record

Navigate between fields and records

Navigate to another screen of data


Go to a specific record in Datasheet or Form view by using the keyboard

1	Press F5 to move to the record number box.

2	Type the number of the record you want to go to and press ENTER.


Navigate between fields and records in Datasheet view by using the keyboard

To move to the	Press
Next field	TAB
Last field in the current record, if a field is already selected	END
Previous field	SHIFT+TAB
First field in the current record, if a field is already selected	HOME
Current field in the next record	DOWN ARROW
Current field in the last record, if a field is already selected	CTRL+DOWN ARROW
Last field in the last record, if a field is already selected	CTRL+END
Current field in the previous record	UP ARROW
Current field in the first record, if a field is already selected	CTRL+UP ARROW
First field in the first record, if a field is already selected	CTRL+HOME


Navigate to another screen of data in Datasheet view by using the keyboard

To move	Press
Down one screen	PAGE DOWN
Up one screen	PAGE UP
Right one screen	CTRL+PAGE DOWN
Left one screen	CTRL+PAGE UP


Navigate in Form view by using the keyboard

What do you want to do?

Navigate between sections of a record

Navigate in forms with more than one page

Go to a specific record

Navigate between fields and records

Navigate in a combo box or list box


Navigate between sections of a record in Form view by using the keyboard

To cycle	Press
Forward through sections	F6
Back through sections	SHIFT+F6


Navigate in forms with more than one page in Form view by using the keyboard

To move	Press
Down one page; at the end of the record, moves to the equivalent page on the next record	PAGE DOWN
Up one page; at the end of the record, moves to the equivalent page on the previous record	PAGE UP


Navigate between fields and records in Form view by using the keyboard

To	Press
Move to the next field	TAB
Move to the previous field	SHIFT+TAB
Move to the last field in the current record, if a field is already selected	END
Move to the last field in the last record, if a field is already selected	CTRL+END
Move to the first field in the current record, if a field is already selected	HOME
Move to the first field in the first record, if a field is already selected	CTRL+HOME
Move to the current field in the next record	CTRL+PAGE DOWN
Move to the current field in the previous record	CTRL+PAGE UP
For information on moving between a main form and a subform, click  [image].


Navigate in a combo box or list box by using the keyboard

To	Press
Open a combo box	F4 or ALT+DOWN ARROW
Move down one line	DOWN ARROW
Move down one page	PAGE DOWN
Move up one line	UP ARROW
Move up one page	PAGE UP
Exit the combo box or list box	TAB


Use shortcut keys

What do you want to do?

Use shortcut keys that are global in Microsoft Access

Use shortcut keys in Design view

Use shortcut keys in Datasheet view and Form view

Use shortcut keys in the Module window


Use shortcut keys that are global in Microsoft Access

To	Press
Open a new database	CTRL+N
Open an existing database	CTRL+O
Display context-sensitive Help about the selected menu command, dialog box option, property, control, action, Visual Basic keyword, or window	F1
Display context-sensitive Help using the question mark pointer; after pressing SHIFT+F1, move the pointer to the item you want help on (such as a toolbar), and click	SHIFT+F1
Cycle between open windows	CTRL+F6
Bring the Database window to the front	F11 or ALT+F1
Display the Control menu	ALT+SPACEBAR
Copy the selection onto the Clipboard	CTRL+C
Cut the selection and copy it onto the Clipboard	CTRL+X
Paste the contents of the Clipboard at the insertion point	CTRL+V
Open the Find dialog box	CTRL+F
Open the Replace dialog box	CTRL+H
Undo typing	CTRL+Z
Open the Save As dialog box	F12 or ALT+F2
Save a database object	SHIFT+F12 or ALT+SHIFT+F2
Close the active window	CTRL+F4
Quit Microsoft Access or close a dialog box	ALT+F4


Use shortcut keys in Design view

To	Press
Switch between Edit mode (with insertion point displayed) and Navigation mode	F2
Switch between the upper and lower portions of a window (Design view of tables, macros, and queries and the Advanced Filter/Sort window)	F6


Use shortcut keys in Datasheet view and Form view

To	Press
Switch between Edit mode (with insertion point displayed) and Navigation mode	F2
Open the Zoom box for entering expressions and other text in small input areas more conveniently	SHIFT+F2
Open a combo box or list box	F4
Find the next occurrence of the text specified in the Find or Replace dialog box when the dialog box is closed	SHIFT+F4
Move to the record number box	F5
Cycle forward through sections of a record	F6
Cycle back through sections of a record	SHIFT+F6
Check spelling	F7
Turn on Extend mode; pressing F8 repeatedly extends the selection to the word, the field, the record (in Datasheet view only), and all records	F8
Cancel Extend mode	ESC
Reverse the F8 selection	SHIFT+F8
Recalculate the fields in the window	F9
Requery the underlying tables; in a subform, this requeries the underlying table for the subform only	SHIFT+F9
Add a new record	CTRL+PLUS SIGN (+)
Delete the current record	CTRL+MINUS SIGN (-)
Save changes to the current record	SHIFT+ENTER
Undo changes in the current field or current record; if both have been changed, press ESC twice to undo changes first in the current field and then in the current record	ESC


Use shortcut keys in the Module window

To	Press
Halt the execution of code or a macro	CTRL+BREAK
Display the Debug window	CTRL+G
Display the Calls dialog box	CTRL+L
Indent selected lines	CTRL+M
Remove indentation from selected lines	CTRL+SHIFT+M
Cut the current line and copy it to the Clipboard	CTRL+Y
Display the previous procedure	CTRL+UP ARROW
Display the next procedure	CTRL+DOWN ARROW
Display context-sensitive Help about the keyword containing the insertion point, or the selected menu command or dialog box option	F1
Display the Object Browser	F2
View procedure definition	SHIFT+F2
View last position	CTRL+F2
Find the next occurrence of the text specified in the Find or Replace dialog box when the dialog box is closed	F3
Find the previous occurrence of the text specified in the Find or Replace dialog box when the dialog box is closed	SHIFT+F3
Continue execution of code or macro	F5
Reset execution of code or macro	SHIFT+F5
Switch between the upper and lower panes (if you have split the window)	F6
Step into (single step)	F8
Step over (procedure step)	SHIFT+F8
Toggle a breakpoint at the selected line	F9
Create instant watch for selected expression	SHIFT+F9
Clear all breakpoints	CTRL+SHIFT+F9


Use the keyboard in Print Preview

What do you want to do?

Display the Print dialog boxes or Zoom window in Print Preview

View different pages in Print Preview

View different parts of the Zoom window


Display the Print dialog boxes or Zoom window in Print Preview by using the keyboard

To	Press
Open the Print dialog box	P
Open the Page Setup dialog box	S
Zoom in or out on a part of the page	Z
Cancel Print Preview	C or ESC


View different pages in Print Preview by using the keyboard

To move to the	Press
Page number box; then type the page number you want to go to and press ENTER	F5
Next page	PAGE DOWN or DOWN ARROW
Previous page	PAGE UP or UP ARROW


View different parts of the Zoom window by using the keyboard

To	Press
Scroll down in small increments	DOWN ARROW
Scroll down one full screen	PAGE DOWN
Move to the bottom of the page	CTRL+DOWN ARROW
Scroll up in small increments	UP ARROW
Scroll up one full screen	PAGE UP
Move to the top of the page	CTRL+UP ARROW
Scroll to the right in small increments	RIGHT ARROW
Move to the right edge of the page	END or CTRL+RIGHT ARROW
Move to the lower-right corner of the page	CTRL+END
Scroll to the left in small increments	LEFT ARROW
Move to the left edge of the page	HOME or CTRL+LEFT ARROW
Move to the upper-left corner of the page	CTRL+HOME


 Create a macro

1	In the Database window, click the Macros tab.

2	Click New.

3	In the Action column, click in the first cell and then click the arrow to display the action list.

4	Click the action you want to use.

5	Type a comment (optional) for the action.

6	In the lower part of the window, specify arguments for the action, if any are required. For tips on setting action arguments, click  [image].

7	To add more actions to the macro, move to another action row, and repeat steps 3 through 6. Microsoft Access carries out the actions in the order you list them.

Tip   To quickly create a macro that carries out an action on a specific object, drag the object from the Database window to an action row in the Macro window. For example, you can create a macro that opens a form by dragging the form to an action row. To do this, click Tile on the Windows menu to position the Macro window and Database window so that they're both visible on your screen; then click the tab in the Database window for the type of object you want to drag, click the object, and drag it to an action row. Dragging a macro adds an action that runs the macro, while dragging other objects (tables, queries, forms, reports, or modules) adds an action that opens the object.


Tips on setting action arguments in a macro

After you add an action to a macro, you set the arguments for the action in the lower portion of the Macro window. These arguments give Microsoft Access additional information on how to carry out the action.

Here are some tips on setting action arguments:

•	You can type a value in an argument box, or in many cases you can select a setting from a list.

•	In general, it's a good idea to set action arguments in the order they're listed, because choices for one item may determine those for items that follow.

•	If you add an action to your macro by dragging an object from the Database window, Microsoft Access automatically sets appropriate arguments for that action.

•	If an action has an argument that calls for the name of a database object, you can set the argument and the corresponding object type argument automatically by dragging the object from the Database window to the argument box.

•	You can use an expression preceded by an equal sign to set any action's arguments except the ones listed in the following table.


Enter an expression in a macro action argument

•	Type = (equal sign) followed by the expression. For example, the following expression sets the action argument to the value of the CompanyPickList control:

=[CompanyPickList]

There are two exceptions: the Expression argument of the SetValue action, and the Repeat Expression argument of the RunMacro action. If you precede an expression in these arguments with an equal sign, Microsoft Access evaluates the expression twice, which can cause unexpected results.

Tip   You can also click the Build button next to the argument box to use the Expression Builder, which guides you through the process of creating an expression. For more information on the Expression Builder, click  [image].

For more information on setting action arguments in a macro, click  [image].


Add an action to a macro

1	In the Macro window, click the first empty row in the Action column. If you want to insert an action between two action rows, click the selector for the action row just below where you want to insert the new action, and then press the INS key.

2	In the Action column, click the arrow to display the action list.

3	Click the action you want to use.

4	Type a comment (optional) for the action.

5	In the lower part of the window, specify arguments for the action, if any are required.  For tips on setting action arguments, click  [image].

Tip   For many action arguments whose settings are an object name, you can set the argument by dragging the object from the Database window to the action's Object Name argument box. For example, you can set the SelectObject action's Object Name argument to the name of a form by dragging the form to the argument box. To do this, click Tile on the Windows menu to position the Macro window and Database window so that they're both visible on your screen; then click the tab in the Database window for the type of object you want to drag, click the object, and drag it to the argument box. For more information on the arguments you can set by dragging an object from the Database window, click  [image].


Macro action arguments that you can set by dragging an object from the Database window

For many action arguments whose settings are an object name, you can set the argument by dragging the object from the Database window to the action's Object Name argument box. Dragging the object also sets the action's Object Type argument. The following table lists the action arguments you can set by dragging an object from the Database window.

For this action	Drag this object	To set this argument
AddMenu	Macro	Menu Macro Name
ApplyFilter	Query	Filter Name
Close	Any object	Object Type, Object Name
CopyObject	Any object	Source Object Type, Source Object Name
DeleteObject	Any object	Object Type, Object Name
GoToRecord	Table, Query, Form	Object Type, Object Name
OpenForm	Form	Form Name
OpenModule	Module	Module Name
OpenQuery	Query	Query Name
OpenReport	Report	Report Name
OpenTable	Table	Table Name
OutputTo	Any object except a macro	Object Type, Object Name
Rename	Any object	Object Type, Old Name
RepaintObject	Any object	Object Type, Object Name
RunMacro	Macro	Macro Name
Save	Any object	Object Type, Object Name
SelectObject	Any object	Object Type, Object Name
SendObject	Any object except a macro	Object Type, Object Name


Move an action in a macro

1	In the Macro window, click the selector for the action row.

2	Click the selector again and drag the row to a new position.


Make a macro run under certain conditions
Make a macro run under specific conditions

1	In the Macro window, click  [image]  on the toolbar.

2	In the Condition column, type a conditional expression in the row where you want to set the condition.

3	In the Action column, enter the action you want Microsoft Access to perform when the condition is true.

When you run the macro, Microsoft Access evaluates each conditional expression. If the condition is true, Microsoft Access carries out the action in that row and all of the immediately following actions that are preceded by an ellipsis (...) in the Condition column. For example, the following macro carries out the MsgBox and StopMacro actions only when there is no value in the SupplierID field (when the value is Null).

Microsoft Access then runs any additional actions in the macro that have a blank Condition column until it reaches another expression, a macro name, or the end of the macro.

If the condition is false, Microsoft Access ignores the action and any immediately following actions that are preceded by an ellipsis in the Condition column and moves to the next action row that contains an expression or a blank Condition column.

For examples of macro conditions, click  [image]. For information on creating expressions, click  [image].


Examples of macro conditions

Use this expression	To carry out the action if
[City]="Paris"	The City value on the form from which the macro was run is Paris.
DCount("[OrderID]", "Orders")>35	There are more than 35 entries in the OrderID field of the Orders table.
DCount("*", "Order Details", "[OrdID]=Forms![Orders]![OrdID]")>3	There are more than 3 entries in the Order Details table where the OrdID field of the table matches the OrdID field on the Orders form.
[ShippedDate] Between #2-Feb-1995# And #2-Mar-1995#	The value of the ShippedDate field on the form from which the macro is run is no earlier than 2-Feb-1995 and no later than  2-Mar-1995.
Forms![Products]![UnitsInStock]<5	The value of the UnitsInStock field on the Products form is less than 5.
IsNull([FirstName])	The FirstName value on the form from which the macro is run is Null (has no value). This expression is equivalent to [FirstName] Is Null.
[Country]="UK" And Forms![SalesTotals]![TotalOrds]>100	The value in the Country field on the form from which the macro is run is UK, and the value of the TotalOrds field on the SalesTotals form is greater than 100.
[Country] In ("France", "Italy", "Spain") And Len([PostalCode])<>5	The value in the Country field is France, Italy, or Spain, and the postal code isn't five characters long.
MsgBox("Confirm changes?",1)=1	You click OK in a dialog box that the MsgBox function displays. If you click Cancel in the dialog box, Microsoft Access ignores the action.
Tip   To cause Microsoft Access to temporarily ignore an action, enter False as a condition. Temporarily ignoring an action can be helpful when you are trying to find problems in a macro.


Why use conditions in a macro?

In some cases, you may want to carry out an action or series of actions in a macro only if a particular condition is true. For example, if you're using a macro to validate data in a form, you might want to display one message in response to one set of values entered in a record and another message in response to a different set of values. In cases like these, you can use conditions to control the flow of the macro.

For example, the following macro carries out the StopMacro action when there is no value in the Country field (when the value is Null). It carries out one of several pairs of MsgBox and CancelEvent actions if the length or form of the PostalCode value isn't appropriate for the country in the Country field.

A condition is a logical expression. The macro follows different paths depending on whether the condition is true or false. To see examples of macro conditions, click  [image].

You enter conditions in the Condition column in the Macro window. If a condition is true, Microsoft Access carries out the action in that row. You can have Microsoft Access carry out a series of actions if the condition is true by typing an ellipsis (...) in the Condition column of the actions that immediately follow the condition.


Create a macro group

If you want to group several related macros in one place rather than keeping track of them separately, you can organize them as a macro group.

1	In the Database window, click the Macros tab.

2	Click New.

3	Click  [image]  on the toolbar.

4	In the Macro Name column, type a name for the first macro in the macro group.

5	Add the actions you want the macro to carry out.

How?

6	Repeat steps 4 and 5 for any other macros you want to include in the macro group.

Note   When you save the macro group, the name you specify is the name of the group of macros. This name is displayed in the list of macros and macro groups in the Database window. Whenever you refer to a macro in a macro group, use this syntax:

macrogroupname.macroname

For example, Buttons.Products refers to the Products macro in the Buttons macro group. In a list of macros, such as the Macro Name argument list for the RunMacro action, Microsoft Access displays the Products macro as Buttons.Products.


Show and hide macro names and conditions in the Macro window

•	Click  [image]  on the toolbar to show or hide the Macro Name column, or click  [image]  to show or hide the Condition column.

To change whether Microsoft Access displays these columns when you first open the Macro window, click Options on the Tools menu, click the View tab, and select or clear the Names Column and Conditions Column check boxes under Show In Macro Design.


Run a macro or event procedure in response to an event on a form, report, or control

Microsoft Access responds to many types of events on forms, reports, and controls, including mouse clicks, changes in data, and forms or reports being opened or closed.

1	Open the form or report in Design view.

2	Create a macro or add Visual Basic code to the appropriate event procedure. For example, you can create a macro or event procedure that displays a message when you click a command button.

3	Set the appropriate event property of the form, report, or control to the name of the macro, or to [Event Procedure] if you're using an event procedure.

For example, to use a macro to display a message when you click a command button, set the command button's OnClick property to the name of a macro that displays the message. To use an event procedure, add Visual Basic code to the button's Click event procedure, and then set the OnClick property to [Event Procedure].

Notes

•	For information on creating a macro, click  [image].

•	For information on adding Visual Basic code to an event procedure, click  [image].

•	For information on when events occur, click  [image].


Find out when events occur

A single action, such as moving from one control to another, can trigger several different events, which occur in a particular sequence. Knowing when events occur and in what order they occur is important because it can affect how and when your macros or event procedures run. For example, if you have two event procedures that are to be run in a certain order, you want to make sure that the events they're associated with occur in that order.

What do you want to do?

See the order of events for controls on forms

See the order of events for records on forms

See the order of events for opening and closing, moving within, and moving between forms

See the order of events for keystrokes and mouse clicks

See the order of events for reports and report sections

Tip   You can see the order in which events occur on a form by opening the ShowEvents form in the Orders sample application. When events occur on the ShowEvents form — for example, when you open the form or move to a new record — the EventHistory form lists the events in the order they occur.


Order of events for controls on forms

Events occur for controls on forms when you move the focus to a control, and when you change and update data in a control.

Moving the focus to a control

When you move the focus to a control on a form — for example, by opening a form that has one or more active controls or by moving to another control on the same form — the Enter and GotFocus events occur in this order:

Enter ⇒ GotFocus

If you are opening a form, these events occur after the events associated with opening the form (such as Open, Activate, and Current), as follows:

Open (form) ⇒ Activate (form) ⇒ Current (form) ⇒ Enter (control) ⇒ GotFocus (control)

When the focus leaves a control on a form — for example, when you close a form that has one or more active controls or move to another control on the same form — the Exit and LostFocus events occur in this order:

Exit ⇒ LostFocus

If you are closing a form, the Exit and LostFocus events occur before the events associated with closing the form (such as Unload, Deactivate, and Close), as follows:

Exit (control) ⇒ LostFocus (control) ⇒ Unload (form) ⇒ Deactivate (form) ⇒ Close (form)

Changing and updating data in a control

When you enter or change data in a control on a form and then move the focus to another control, the BeforeUpdate and AfterUpdate events occur:

BeforeUpdate ⇒ AfterUpdate

The Exit and LostFocus events for the changed control occur after the BeforeUpdate and AfterUpdate events:

BeforeUpdate ⇒ AfterUpdate ⇒ Exit ⇒ LostFocus

When you change the text in a text box or in the text box portion of a combo box, the Change event occurs. This event occurs whenever the contents of the control change, but before you move to a different control or record (and thus, before the BeforeUpdate and AfterUpdate events occur). The following sequence of events occurs for each key you press in a text box or in the text box portion of a combo box:

KeyDown ⇒ KeyPress ⇒ Change ⇒ KeyUp

The NotInList event occurs after you enter a value in a combo box that isn't in the combo box list and then attempt to move to another control or record. It occurs after the keyboard events and the Change events for the combo box, but before any other control or form events. If the LimitToList property of the combo box is set to Yes, the Error event for the form occurs immediately after the NotInList event:

KeyDown ⇒ KeyPress ⇒ Change ⇒ KeyUp ⇒ NotInList ⇒ Error

For more information on events, click  [image].


Order of events for records on forms

Events occur for records on forms when you move the focus to a record, update data in a record, delete an existing record or records, or create a new record.

Moving the focus to records and updating data in records

When you move the focus to an existing record on a form, enter or change data in the record, and then move the focus to another record, the following sequence of events occurs for the form:

Current (form) ⇒ BeforeUpdate (form) ⇒ AfterUpdate (form) ⇒ Current (form)

When you leave the record whose data has changed, but before you enter the next record, the Exit and LostFocus events occur for the control with the focus. These events occur after the BeforeUpdate and AfterUpdate events for the form, as follows:

BeforeUpdate (form) ⇒ AfterUpdate (form) ⇒ Exit (control) ⇒ LostFocus (control) ⇒ Current (form)

As you move the focus among the controls on a form, events occur for each control. For example, the following sequences of events occur when you:

•	Open a form and change data in a control:

Current (form) ⇒ Enter (control) ⇒ GotFocus (control) ⇒ BeforeUpdate (control) ⇒ AfterUpdate (control)

•	Move the focus to another control:

Exit (control1) ⇒ LostFocus (control1) ⇒ Enter (control2) ⇒ GotFocus (control2)

•	Move the focus to another record:

BeforeUpdate (form) ⇒ AfterUpdate (form) ⇒ Exit (control2) ⇒ LostFocus (control2) ⇒ Current (form)

For more information on the order of events for controls on forms, click  [image].

Deleting records

When you delete a record, the following events occur for the form, and Microsoft Access displays a dialog box asking you to confirm the deletion:

Delete ⇒ BeforeDelConfirm ⇒ AfterDelConfirm

If you cancel the Delete event, the BeforeDelConfirm and AfterDelConfirm events don't occur and the dialog box isn't displayed.

Creating a new record

When you move the focus to a new (blank) record on a form and then create a new record by typing in a control, the following sequence of events occurs:

Current (form) ⇒ Enter (control) ⇒ GotFocus (control) ⇒ BeforeInsert (form) ⇒ AfterInsert (form)

The BeforeUpdate and AfterUpdate events for the controls on the form and for the new record occur after the BeforeInsert event and before the AfterInsert event.

For more information on events, click  [image].


Order of events for forms

Events occur for forms when you open or close a form, move between forms, or work with data on a form.

Opening and closing a form

When you open a form, the following sequence of events occurs for the form:

Open ⇒ Load ⇒ Resize ⇒ Activate ⇒ Current

If there are no active controls on the form, the GotFocus event also occurs for the form after the Activate event but before the Current event.

When you close a form, the following sequence of events occurs for the form:

Unload ⇒ Deactivate ⇒ Close

If there are no active controls on the form, the LostFocus event also occurs for the form after the Unload event but before the Deactivate event.

Moving between forms

When you switch between two open forms, the Deactivate event occurs for the first form, and the Activate event occurs for the second form:

Deactivate (form1) ⇒ Activate (form2)

The Deactivate event for a form also occurs when you switch from the form to another window in Microsoft Access. However, the Deactivate event doesn't occur when you switch to a dialog box, to a form whose PopUp property is set to Yes, or to a window in another application.

Note   An Open event doesn't occur if you move to a form that is already open, even if you've moved to the form by carrying out an OpenForm action.

Working with data on a form

Form and control events occur as you move between records in the form and change data. For example, when you first open a form, the following sequence of events occurs:

Open (form) ⇒ Load (form) ⇒ Resize (form) ⇒ Activate (form) ⇒ Current (form) ⇒ Enter (control) ⇒ GotFocus (control)

Similarly, when you close a form, the following sequence of events occurs:

Exit (control) ⇒ LostFocus (control) ⇒ Unload (form) ⇒ Deactivate (form) ⇒ Close (form)

If you've changed data in a control, the BeforeUpdate and AfterUpdate events for both the control and the form occur before the Exit, LostFocus, Unload, Deactivate, and Close events. For more information on the order of events for controls on forms, click  [image].

Working with subforms

When you open a form containing a subform, the subform and its records are loaded before the main form. Thus, the events for the subform and its controls (such as Open, Current, Enter, and GotFocus) occur before the events for the form. The Activate event doesn't occur for subforms, however, so opening a main form triggers an Activate event only for the main form.

Similarly, when you close a form containing a subform, the subform and its records are unloaded after the form. The Deactivate event doesn't occur for subforms, so closing a main form triggers a Deactivate event only for the main form.

The events for the controls, form, and subform occur in the following order:

1.  Events for the subform's controls (such as Exit and LostFocus)

2.  Events for the form's controls (including the subform control)

3.  Events for the form (such as Deactivate and Close)

4.  Events for the subform

For more information on events, click  [image].


Order of events for keystrokes and mouse clicks

Keyboard events occur for forms and controls when you press keys or send keystrokes while the form or control has the focus. Mouse events occur for forms, form sections, and controls on forms when you press the mouse buttons while the mouse pointer is on a form, section, or control, or when you move the mouse pointer over a form, section, or control.

Keyboard events

When you press and release a key while a control on a form has the focus (or use the SendKeys action or statement to send a keystroke), the following sequence of events occurs:

KeyDown ⇒ KeyPress ⇒ KeyUp

When you press a key or send a keystroke in the ANSI character set key, the KeyDown, KeyPress, and KeyUp events all occur. For lists of characters in the ANSI character set, click  [image]  and  [image].

If you press and hold down a non-ANSI key, the KeyDown event occurs repeatedly until you release the key; then the KeyUp event occurs. If you press and hold down an ANSI key, the KeyDown and KeyPress events alternate repeatedly (KeyDown, KeyPress, KeyDown, KeyPress, and so on) until you release the key; then the KeyUp event occurs.

If pressing a key triggers another event for a control, the other event occurs after the KeyPress event but before the KeyUp event. For example, if a keystroke changes text in a text box, triggering a Change event, the following sequence of events occurs:

KeyDown ⇒ KeyPress ⇒ Change ⇒ KeyUp

If a keystroke causes the focus to move from one control to another control, the KeyDown event occurs for the first control, while the KeyPress and KeyUp events occur for the second control. For example, if you change data in a control and then press TAB to move to the next control, the following sequences of events occur:

•	First control:

KeyDown ⇒ BeforeUpdate ⇒ AfterUpdate ⇒ Exit ⇒ LostFocus

•	Second control:

Enter ⇒ GotFocus ⇒ KeyPress ⇒ KeyUp

Mouse events

When you press and release a mouse button while the mouse pointer is on a control on a form, the following sequence of events occurs for the control:

MouseDown ⇒ MouseUp ⇒ Click

If a control has the focus and you click another control to move the focus to this second control, the following sequences of events occur:

•	First control:

Exit ⇒ LostFocus

•	Second control:

Enter ⇒ GotFocus ⇒ MouseDown ⇒ MouseUp ⇒ Click

If you move to another record and then click a control, the Current event for the form also occurs before the Enter event for the control.

Double-clicking a control causes both DblClick and Click events to occur. For example, when you double-click a control other than a command button, the following sequence of events occurs for the control:

MouseDown ⇒ MouseUp ⇒ Click ⇒ DblClick ⇒ MouseUp

When you double-click a command button, a second Click event occurs after the second MouseUp event.

The MouseMove event for a form, section, or control occurs when you move the mouse pointer over the form, section, or control. This event is independent of the other mouse events.

For more information on keyboard events, click  [image].

For more information on mouse events, click  [image].


Order of events for reports and report sections

Events occur for reports and report sections when you open a report to print or preview it, or close a report.

Events for reports

When you open a report to print or preview it and then later close the report or move to another window in Microsoft Access, the following sequence of events occurs for the report:

Open ⇒ Activate ⇒ Close ⇒ Deactivate

When you switch between two open reports, the Deactivate event occurs for the first report, and the Activate event occurs for the second report:

Deactivate (report1) ⇒ Activate (report2)

The Deactivate event for a report also occurs when you switch from the report to another window in Microsoft Access. However, the Deactivate event doesn't occur when you switch to a dialog box, to a form whose PopUp property is set to Yes, or to a window in another application.

When you open a report that is based on a query, Microsoft Access triggers the Open event before running the underlying query. As a result, you can set the criteria for the report using a macro or event procedure that responds to the Open event. For example, the macro or event procedure could open a custom dialog box in which you enter the report criteria.

Events for report sections

When you print or preview a report, the Format and Print events occur for the report sections after the Open and Activate events for the report and before the report's Close or Deactivate events:

Open (report) ⇒ Activate (report) ⇒ Format (report section) ⇒ Print (report section) ⇒ Close (report) ⇒ Deactivate (report)

In addition, the following events can occur during or after formatting but before the Print event:

•	The Retreat event occurs when Microsoft Access returns to a previous section during report formatting.

•	The NoData event occurs if there are no records displayed by the report.

•	The Page event occurs after formatting but before printing. You can use this event to customize the appearance of the printed report.

For more information on events, click  [image].


 Add custom commands to menus

You can create custom menu bars with your own sets of menus and commands to replace the built-in menus for forms and reports, or you can create a global menu bar that replaces the built-in menus in all Microsoft Access windows (except in forms or reports that have their own custom menu bar).

You can create a custom menu bar using the Menu Builder, or you can create it on your own with macros. Using the Menu Builder is the easiest way to create a custom menu bar. However, if you want custom commands to carry out actions other than the DoMenuItem, RunMacro, or RunCode actions, you must edit the macros created by the Menu Builder, or create them from scratch.

Tip   After you've created a custom menu bar, you can switch between the built-in menu bar and the custom menu bar by pressing CTRL+F11.

What do you want to do?

Create a custom menu bar for a form or report using the Menu Builder

Create a custom menu bar without using the Menu Builder

Create a global menu bar


Create a custom menu bar for a form or report using the Menu Builder

1	In form or report Design view, open the form or report's property sheet.

2	In the property sheet, click the MenuBar property, and then click the Build button to the right of the property box.

3	In the Menu Builder, click <Empty Menu Bar>, and then complete the boxes in the upper half of the window to create, change, or delete menus, submenus, and commands, which are shown in the lower half of the window. Use the buttons in the middle to indent or move the items in the lower half of the window.

Tip   If you haven't used the Menu Builder before, you may want to look at a menu bar template to see what a menu bar looks like in the Menu Builder.


Create a custom menu bar without using the Menu Builder

To create custom menus on your own, you first create macro groups that define each menu and its commands. You then create a menu bar macro that adds the menus to a menu bar. Finally, you attach the menu bar to the form or report, or designate it as a global menu bar.

What do you want to do?

Create a custom menu and its commands

Add custom menus to a custom menu bar

Attach a custom menu bar to a form or report

Create a global menu bar


Create a custom menu and its commands

When you create a custom menu bar from scratch, you first create a macro group that defines each custom menu and its commands. For example, if you want five menus on your menu bar, you create five macro groups.

1	Create a macro group for the menu, entering each menu command in the Macro Name column of the Macro window.

How?

Enter the commands in the order they are to be displayed on the menu. Each command is an individual macro in the macro group.

2	In the Action column, select the actions you want to carry out when each command is chosen, setting the appropriate arguments for each action.

You can select several actions for each command by leaving the Macro Name column blank in the rows following the command name.

3	Add the menus you've created to a custom menu bar.

How?

Tip   To create a line between two menu commands, type a hyphen (-) in the Macro Name column between the appropriate menu commands. To create an access key so that you can use the keyboard to choose the command, type an ampersand (&) before the letter you want to be the access key. This letter will be underlined on the menu.


Add custom menus to a custom menu bar

When you create a custom menu bar from scratch, an AddMenu action is carried out for each custom menu you created in a menu bar macro that defines the menu bar. For example, if you want five menus on your menu bar, five AddMenu actions are carried out in your menu bar macro — one for each menu.

1	Create a macro, selecting an AddMenu action for each menu in the Action column of the Macro window.

How?

Enter the actions in the order they are to be displayed on the menu bar.

2	For each AddMenu action, set:

•	The Menu Name argument to the menu name that appears on the menu bar.

•	The Menu Macro Name argument to the name of the macro group that defines the menu.

•	The Status Bar Text argument to the text that appears in the status bar when you select the menu name.

Tip   To create an access key so that you can use the keyboard to choose the menu, type an ampersand (&) before the letter you want to be the access key. This letter will be underlined on the menu name in the menu bar.


Attach a custom menu bar to a form or report

1	In form or report Design view, open the form or report's property sheet.

2	Set the MenuBar property to the name of the menu bar macro that defines the custom menu bar.

Whenever you open the form or report, Microsoft Access replaces the built-in menu bar with the one you created.


Create a submenu for a custom menu without using the Menu Builder

When you create a custom menu, you can include one or more levels of submenus. A submenu branches off another menu to display its own menu commands.

You can create a custom submenu using the Menu Builder by following the instructions in the Menu Builder. You can also create the custom submenu on your own.

1	Create a custom menu bar without using the Menu Builder.

How?

2	In the macro group that contains the menu command that you want to branch to a submenu, enter the AddMenu action in the Action column of the macro that defines the command.

3	Set the Menu Name argument to the menu name that appears on the menu bar, the Menu Macro Name argument to the name of the macro group that defines the submenu, and the Status Bar Text argument to the text the appears in the status bar when you select the menu name.


Create a custom shortcut menu for a form, report, or control

1	In form or report Design view, display the property sheet for the form, report, or form control.

2	In the property sheet, click the ShortcutMenuBar property, and then click the Build button to the right of the property box.

3	Use the Menu Builder to add a single menu to the shortcut menu bar. The commands on this menu appear in the shortcut menu.

To do this, click <Empty Menu Bar> in the Menu Builder, and then complete the boxes in the upper half of the window to create, change, or delete menus, submenus, and commands, which are shown in the lower half of the window. Use the buttons in the middle to indent or move the items in the lower half of the window.

Tip   You can also create the menu from scratch by using a macro group. You can attach the macro group to the form, report, or control by setting the form, report, or control's ShortcutMenuBar property to the name of the macro group. If you want custom commands to carry out actions other than DoMenuItem, RunMacro, or RunCode, you must edit the macros created by the Menu Builder or create them from scratch. For more information on creating a custom menu from scratch, click  [image].


Display a different custom menu bar or shortcut menu in response to an event

You can change the menu bar or shortcut menu a user sees while working with a database by changing the settings of the MenuBar and ShortcutMenuBar properties in a macro or event procedure.

What do you want to do?

Change the menu bar or shortcut menu by using a macro

Change the menu bar or shortcut menu by using Visual Basic


Display a different custom menu bar or shortcut menu by using a macro

1	Create a macro.

How?

2	In a blank action row, click SetValue in the action list.

3	To change the menu bar of a form or report, set the Item argument to the identifier for the form or report's MenuBar property (for example, Forms![Customers].MenuBar), and then set the Expression argument to the name of the menu bar macro that defines the custom menu bar.

4	To change the global menu bar, set the Item argument to Application.MenuBar, and then set the Expression argument to the name of the menu bar macro that defines the custom menu bar.

5	To change the shortcut menu bar of a form, report, or control, set the Item argument to the identifier for the object's ShortcutMenuBar property (for example, Forms![Customers].ShortcutMenuBar), and then set the Expression argument to the name of the macro group that defines the custom shortcut menu.

Note   The macro group should include a single menu that includes the commands that appear in the shortcut menu.

6	To change the global shortcut menu, set the Item argument to Application.ShortcutMenuBar, and then set the Expression argument to the name of the macro group that defines the custom shortcut menu.

7	Run the macro in response to the event you want to trigger the menu change.

How?

For more information about creating custom menus, click  [image].


Display a different custom menu bar or shortcut menu by using an event procedure

1	In the Module window, open the event procedure for the event that you want to trigger the menu change.

How?

For example, to change a menu by clicking a command button on a form, open the button's Click event procedure.

2	Do one or more of the following:

•	To change the menu bar of a form or report, add an assignment statement to the event procedure that sets the MenuBar property of the form or report. Set the property to the name of the menu bar macro that defines the custom menu bar.

For example, to change the Customers menu bar to a menu defined by the macro NewMenuBar, add the following assignment statement to the event procedure:

Forms![Customers].MenuBar = "NewMenuBar"

•	To change the global menu bar, add an assignment statement to the event procedure that sets the MenuBar property of the Application object. Set the property to the name of the menu bar macro that defines the custom menu bar. For example:

Application.MenuBar = "NewMenuBar"

•	To change the shortcut menu of a form, report, or control, add an assignment statement to the event procedure that sets the ShortcutMenuBar property of the object. Set the property to the name of the macro group that defines the shortcut menu.

For example, to change the Customers shortcut menu to a menu defined by the macro NewMenuBar, add the following assignment statement to the event procedure:

Forms![Customers].ShortcutMenuBar = "NewShortcutMenu"

•	To change the global shortcut menu, add an assignment statement to the event procedure that sets the ShortcutMenuBar property of the Application object. Set the property to the name of the macro group that defines the custom shortcut menu. For example:

Application.ShortcutMenuBar = "NewShortcutMenu"


Make custom menu commands appear dimmed or selected

You can dim (gray out) or select (check) the custom menu commands a user sees while working with a database by carrying out the SetMenuItem action in a macro or Visual Basic procedure.

What do you want to do?

Make custom menu commands appear dimmed or selected by using a macro

Make custom menu commands appear dimmed or selected by using Visual Basic


Make custom menu commands appear dimmed or selected by using a macro

1	Create a macro.

How?

2	In a blank action row, click SetMenuItem in the action list.

3	Set the Menu Index, Menu Item, and Menu Sub Item arguments to the settings for the command that you want to appear dimmed or selected.

Set the Flag argument to the setting for the appearance you want (Gray, Check, Ungray, or Uncheck).

4	Run the macro.

How?

For more information about the SetMenuItem action, click  [image].


Make custom menu commands appear dimmed or selected by using Visual Basic

1	Create a Visual Basic procedure.

How?

2	Carry out the SetMenuItem action in the procedure, setting the Menu Index, Menu Item, and Menu Sub Item arguments to the settings for the command that you want to appear dimmed or selected, and then setting the Flag argument to the setting for the appearance you want (Gray, Check, Ungray, or Uncheck).

How?

3	Run the procedure.

How?

For more information about the SetMenuItem action, click  [image].


Run a macro

When you run a macro, Microsoft Access starts at the beginning of the macro and carries out all the actions in the macro until it reaches either another macro (if the macro is in a macro group) or the end of the macro.

You can run a macro directly, from another macro or an event procedure, or in response to an event that occurs on a form, report, or control. For example, you can attach a macro to a command button on a form so that the macro runs when a user clicks the button. You can also create a custom menu command or toolbar button that runs a macro, assign a macro to a key combination, or run a macro automatically when you open a database.

What do you want to do?

Run a macro directly

Run a macro in a macro group

Run a macro from another macro or an event procedure

Run a macro in response to an event on a form, report, or control

Create a command button that runs a macro

Create a custom menu command that runs a macro

Create a toolbar button that runs a macro

Assign a macro to a key combination

Run a macro when my database first opens


Run a macro directly

You can run a macro directly from the Macro window, from the Database window, or from other windows in Microsoft Access.

To run a macro from the Macro window

•	Click  [image]  on the toolbar.

To run a macro from the Database window

•	Click the Macros tab and then double-click a macro name.

To run a macro from anywhere in Microsoft Access

•	On the Tools menu, click Macro. Then click a macro in the Macro Name box.

Note   You normally run a macro directly only to test it. You can then attach the macro to a form, report, or control so that it runs in response to an event, or you can create a custom menu command that runs the macro.


Run a macro in a macro group
Run a macro that is in a macro group

•	Run the macro just as you would run a macro that isn't in a macro group, but use this syntax:

macrogroupname.macroname

For example, here's how to refer to a macro called Categories in a macro group called Forms Switchboard Buttons:

Forms Switchboard Buttons.Categories

You use the macrogroupname.macroname syntax whenever you specify a macro in a macro group. For example, use this syntax when you specify the macro as an event property setting on a form or report or when you refer to the macro in the Macro Name argument of the RunMacro action. When you are selecting a macro name from a list, Microsoft Access includes an entry for each macro in each macro group.


Find problems in a macro by single stepping through it

By single stepping through a macro, you can observe the flow of the macro and the results of each action, and isolate any action that causes an error or produces unwanted results.

1	Open the macro.

How?

2	Click  [image]  on the toolbar.

3	Click  [image]  on the toolbar.

4	Click Step to carry out the action shown in the Macro Single Step dialog box.

5	Click Halt to halt the execution of the macro and close the dialog box.

6	Click Continue to turn off single stepping and run the remainder of the macro.

Tip   To halt a macro while it's running and then single step through it, press CTRL+BREAK.


Run a macro from another macro or from a Visual Basic procedure

If you want to run a macro from another macro or from a Visual Basic procedure, add the RunMacro action to your macro or procedure.

•	To add the RunMacro action to a macro, click RunMacro in the action list in a blank action row, and set the Macro Name argument to the name of the macro you want to run.

•	To add the RunMacro action to a Visual Basic procedure, add the RunMacro method of the DoCmd object to your procedure, and specify the name of the macro you want to run; for example, the following RunMacro method runs the macro My Macro:

DoCmd.RunMacro "My Macro"

For more information on the RunMacro action, click  [image].


Open a macro

1	In the Database window, click the Macros tab.

2	Click the name of the macro you want to open.

3	Click Design.

4	Make the changes you want to make. For example:

•	To add an action, click  [image].

•	To move or copy an action, click  [image].

•	To add a condition, click  [image].


Troubleshoot macros

What do you need help with?

I don't understand how macros work. Please give me an overview.

How do I find where problems are occurring in my macro?

I don't know what event to attach my macro to so that it does what I want.

How do I temporarily disable an action in a macro?

The Where Condition argument in my macro's OpenForm or OpenReport action is producing unexpected results.

The RunCode action in my macro won't run a Visual Basic for applications module.

When I run my macro, Microsoft Access displays messages that I don't want to see.

I'm using the SendKeys action in a macro to send keystrokes to a dialog box, but they're not being sent.


How do I temporarily disable an action in a macro?

To cause Microsoft Access to temporarily ignore an action, type False as a condition. Temporarily disabling an action can be helpful when you're trying to find problems in a macro. This is similar to temporarily commenting out a line of Visual Basic for applications code by typing a single quotation mark (') at the beginning of the line.

For more information about entering a condition for a macro action, click  [image].


The Where Condition argument in my macro's OpenForm or OpenReport action is producing unexpected results.

The Where Condition argument of an OpenForm or OpenReport action may produce unexpected results for any of the following reasons:

•	The Where Condition expression uses invalid syntax to refer to the value of a control or property. For more information about referring to the value of a control, click  [image].

•	The Where Condition argument uses invalid syntax to combine the value of a field, control, or property with a literal string. For more information about values in expressions, click  [image].

•	The OpenForm or OpenReport action is being carried out using the corresponding Visual Basic for applications methods in a procedure, and the Where Condition argument is specified in the wrong position in the list of arguments. The Where Condition argument must be the fourth argument. If the Where Condition argument isn't preceded by View and Filter Name arguments, you must still type a comma as a placeholder for those arguments.

For more information on the OpenForm action, click  [image]. For more information on the OpenReport action, click  [image].


The RunCode action in my macro won't run a Visual Basic for applications module.

You use the RunCode action to run a Function procedure, not a module. In Microsoft Access, you run procedures rather than modules. Replace the name of the module with the name of the function in the module that you want to run. To run a Sub procedure, call it in the function.

To open a module, use the OpenModule action.


When I run my macro, Microsoft Access displays messages that I don't want to see.

You can temporarily stop the display of warnings and other messages while a macro is running by carrying out the SetWarnings action in the macro. You can also use the SetWarnings action to restart the display of messages. For more information, click  [image].


I'm using the SendKeys action in a macro to send keystrokes to a dialog box, but they're not being sent.

Because the dialog box suspends the macro, you must put the SendKeys action before the action that causes the dialog box to open and set the Wait argument to No to avoid pauses in processing. For more information about the SendKeys action, click  [image].


 Should I use a macro or Visual Basic?

In Microsoft Access, you can accomplish many tasks with macros or through the user interface. In many other database programs, the same tasks require programming. Whether to use a macro or Visual Basic often depends on what you want to do.

When should I use a macro?

Macros are an easy way to take care of simple details such as opening and closing forms, showing and hiding toolbars, and running reports. You can quickly and easily tie together the database objects you've created because there's little syntax to remember — the arguments for each action are displayed in the lower part of the Macro window.

In addition to the ease of use macros provide, you must use macros to:

•	Create custom menu bars.

•	Make global key assignments.

•	Run your own macro or procedure from a button on a toolbar. You can attach a macro to a toolbar button, but you cannot attach a Visual Basic procedure to a toolbar button. To run a Visual Basic procedure, carry out the RunCode action in the macro attached to the toolbar button.

•	Carry out an action or series of actions when a database first opens.

When should I use Visual Basic?

You should use Visual Basic instead of macros if you want to:

•	Make your database easier to maintain. Because macros are separate objects from the forms and reports that use them, a database containing many macros that respond to events on forms and reports can be difficult to maintain. In contrast, Visual Basic event procedures are built into the form's or report's definition. If you move a form or report from one database to another, the event procedures built into the form or report move with it.

•	Create your own functions. Microsoft Access includes many built-in functions — such as the IPmt function that calculates an interest payment. You can use these functions to perform calculations without having to create complicated expressions. Using Visual Basic, you can also create your own functions to either perform calculations that exceed the capability of an expression or replace complex expressions. In addition, you can use the functions you create in expressions to apply a common operation to more than one object.

•	Mask error messages. When something unexpected happens while a user is working with your database and Microsoft Access displays an error message, the message can be quite mysterious to the user, especially if the user isn't familiar with Microsoft Access. Using Visual Basic, you can detect the error when it occurs and either display your own message or take some action.

•	Create or manipulate objects. In most cases, you'll find that it's easiest to create and modify an object in that object's Design view. In some situations, however, you may want to manipulate the definition of an object in code. Using Visual Basic, you can manipulate all the objects in a database, as well as the database itself.

•	Perform system-level actions. You can carry out the RunApp action in a macro to run another Windows-based or MS-DOS–based application from your application, but you can't use a macro to do much else outside Microsoft Access. Using Visual Basic, you can check to see if a file exists on the system, use OLE Automation or dynamic data exchange (DDE) to communicate with other Windows-based applications such as Microsoft Excel, and call functions in Windows dynamic-link libraries (DLLs).

•	Manipulate records one at a time. You can use Visual Basic to step through a set of records one record at a time and perform an operation on each record. In contrast, macros work with entire sets of records at once.

•	Pass arguments to your Visual Basic procedures. You can set arguments for macro actions in the lower part of the Macro window when you create the macro, but you can't change them when the macro is running. With Visual Basic, however, you can pass arguments to your code at the time it is run or you can use variables for arguments — something you can't do in macros. This gives you a great deal of flexibility in how your Visual Basic procedures run.


Create a command button that prints the current record

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image].

3	On the form, click where you want to place the command button.

4	In the first wizard dialog box, click Record Operations in the Categories box, and then click Print Record in the Actions box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design view.

If you want to see the event procedure that makes the button work, open the button's property sheet, and then click the Build button next to the OnClick property box.

Tip   You can print the current record in a report by carrying out the OpenReport action in the Click event procedure for the command button. For example, adding the following Visual Basic code to the event procedure prints the current record in the Invoice report:

Dim DocName As String

Dim strFil As String

DocName = "Invoice"

strFil = "Reports!Invoice!OrderID = Forms!Orders!OrderID"

DoCmd.OpenReport DocName, acNormal, , strFil


Setting the value of a control or property by using a macro or an event procedure

By assigning new values to controls and properties in response to events that occur on a form or report, you can make the objects you've created work together so that they're easier to use.

Here are some common situations that call for setting values with a macro or an event procedure:

Setting the value of a control on one form equal to the value of a control on another form

For example, you can put a command button on a Customers form that opens an Orders form and automatically fills in billing information from the Customers form.

Updating the value of a control that's dependent on the value of another control

For example, you might have a PaymentDate control whose default value is the ship date (the value of the ShipDate control). You can use a macro or an event procedure to automatically reset the value of the PaymentDate control whenever the value in the ShipDate control changes.

For more information on setting the value of a control based on the value of another control, click  [image].

Setting a form or control property in response to a selection or other event

You can use a macro or an event procedure to set a form or control property in order to:

•	Hide or display a control based on the value of another control. For example, you may want the DateDue control on an Orders form to be hidden if the order is already paid for (if the Paid control's value is Yes) or visible if payment is still due.

•	Disable or lock a control based on the value of another control. For example, you can disable a DriversLicense control if the value of an Age control is below the minimum age for a driver's license.

•	Display different sets of records depending on a selection. For example, you can control what records are displayed in a Customers form, depending on which option is selected in a Customer Type option group. To do this, set the RecordSource property of the form to one of several different queries, each of which contains the records for a different set of customers.

For more information on setting the value of a property in response to an event, click  [image].


Set the value of a control based on the value of another control

You can assign the value of a control based on the value of another control by adding a SetValue action to a macro or by using an assignment statement in a Visual Basic procedure.

What do you want to do?

Set the value of a control based on the value of another control by using a macro

Set the value of a control based on the value of another control by using Visual Basic


Set the value of a control based on the value of another control by using a macro

1	Create a macro.

How?

2	In a blank action row, click SetValue in the action list.

3	Set the Item argument to the identifier for the first control (the control whose value you want to set), and then set the Expression argument to the identifier for the second control (the control whose value you want to assign to the first control).

4	Run the macro.

How?


Set the value of a control based on the value of another control by using Visual Basic

1	Create a Visual Basic procedure.

How?

2	Add an assignment statement to the procedure by typing the identifier for the first control (the control whose value you want to set), an equal sign, and the identifier for the second control (the control whose value you want to assign to the first control).

•	To refer to the value of a control on the current form, type the Me keyword followed by the ! operator and the name of the control. For example, the following statement assigns the value of the City control on the current form to the ShipCity control on the current form:

Me![ShipCity] = Me![City]

•	To refer to the value of a control on a different form, type the control's full identifier. For example, the following identifier refers to the ShipCity control on the ShipForm form:

Forms![ShipForm]![ShipCity]

3	Run the procedure.

How?

For more information on referring to the value of a control, click  [image].


Set the value of a property in response to an event

You can assign the value of a property in response to an event, such as a click on a command button, by adding a SetValue action to a macro or by using an assignment statement in a Visual Basic procedure.

What do you want to do?

Set the value of a property in response to an event by using a macro

Set the value of a property in response to an event by using Visual Basic


Set the value of a property in response to an event by using a macro

1	Create a macro.

How?

2	In a blank action row, click SetValue in the action list.

3	Set the Item argument to the identifier for the property whose value you want to set, and then set the Expression argument to the value you want to assign to the property.

4	For the event that you want to trigger the macro, set the event property to the name of the macro.

For an example of setting the value of a property in response to an event, click  [image].


Set the value of a property in response to an event by using Visual Basic

1	Open the event procedure for the event.

How?

2	Add an assignment statement to the procedure by typing the identifier for the property whose value you want to set, an equal sign, and the value you want to assign.

•	To refer to the property of a control on the current form, type the Me keyword followed by the ! operator, the name of the control, the . (dot) operator, and the name of the property. For example, the following statement assigns the value False to the Visible property of the DateDue control on the current form:

Me![DateDue].Visible = False

•	To refer to the property of a control on a different form, type the control's full identifier. For example, the following identifier refers to the Visible property of the DateDue control on the ShipForm form:

Forms![ShipForm]![DateDue].Visible

For more information on referring to a property, click  [image].

For an example of setting the value of a property in response to an event, click  [image].


Example of setting the value of a property in response to an event

You can set the value of a property based on a value in the current record by running a macro or an event procedure in response to the form's Current event. For example, you may want the DateDue control on an Orders form to be hidden if the order is already paid for (if the value of the Paid control is Yes or True).

To run a macro, set the form's OnCurrent event property to the name of a macro that sets the DateDue control's Visible property to No if the value of the Paid control is Yes.

To use an event procedure, add the following Visual Basic code to the Form_Current event procedure:

If Me![Paid] = True Then

Me![DateDue].Visible = False

Else

Me![DateDue].Visible = True

End If


Synchronize records between two forms

You may often want to look at related records on two forms at the same time. For example, while looking at a customer record on a Customers form, you may want to open an Orders form that shows the customer's orders.

When you move between records on a form, you may also want to automatically view related records on a second form. For example, as you move between supplier records on a Suppliers form, you may want to see the products each supplier carries in a Product List form.

You can synchronize records between two forms by creating a command button that opens and synchronizes a second form, or by using the Current event to display related records on the second form when you move between records on the first form.

Note   You can also use the Form Wizard to create two related forms from scratch. In the first screen of the wizard, select fields from two different tables. In the second screen, click Linked Forms. The wizard creates the two related forms; each form contains fields from one of the tables. One of the forms also has a command button that opens the other form and synchronizes the records between the forms.

What do you want to do?

Create a command button that opens and synchronizes a form

Display related records in one form when you move between records on another form


Display related records when you move between records on a form

When you move between records on a form, you can display related records on a second form by running a macro or an event procedure in response to the form's Current event.

What do you want to do?

Use a macro to display related records when you move between records on a form

Use Visual Basic to display related records when you move between records on a form


Use a macro to display related records when you move between records on a form

1	Open the first form in Design view.

2	Create a macro.

How?

3	In a blank action row, click OpenForm in the action list.

4	Set the Form Name argument to the name of the second form, and then set the Where Condition argument to display the related records you want.

5	Set the OnCurrent event property of the form to the name of the macro.

For an example of using a macro to display related records when you move between records on a form, click  [image].


Example of using a macro to display related records when you move between records

When you move between supplier records on a Suppliers form, you may want to see the products each supplier carries in a Product List form. You can accomplish this by carrying out an OpenForm action in a macro in response to the form's Current event. Set the action's Where Condition argument to display records on the Product List form whose value in the SupplierID field matches the value in the SupplierID field on the Suppliers form, as follows:

[SupplierID]=Forms![Suppliers]![SupplierID]

Note   If you don't always want the Product List form to open when you move between records on the Suppliers form, include a conditional expression in the macro that checks whether or not the Product List form is open.

After creating the macro, set the form's OnCurrent property to the name of the macro.


Use Visual Basic to display related records when you move between records on a form

1	Open the first form in Design view.

2	Open the form's Form_Current event procedure.

How?

3	Add Visual Basic code to the event procedure to display records in the second form that have field values that match a related field on the first form.

For an example of using Visual Basic to display related records when you move between records on a form, click  [image].


Example of using Visual Basic to display related records when you move between records

When you move between supplier records on a Suppliers form, you may want to see the products each supplier carries in a Product List form. You can accomplish this by setting the FilterOn and Filter properties of the Product List form in the Form_Current event procedure of the Supplier's form:

Private Sub Form_Current

' Declare and set a variable to store the WHERE

' clause that describes the records you want to

' display.

Dim strCond As String

strCond = "SupplierID = Forms!Suppliers!SupplierID"

' Use the IsLoaded function from the Northwind

' sample database to check whether the Product List

' form is open, then set the properties.

If IsLoaded("Product List") Then

Forms![Product List].FilterOn = True

Forms![Product List].Filter = strCond

End If

End Sub


Find a record by selecting a value from a list

On a form, you can create a list box or a combo box that finds a record when you select a value from the list.

1	In form Design view, click  [image]  in the toolbox if it's not already pressed in.

2	In the toolbox, click  [image]  or click  [image].

3	On the form, click where you want to place the list box or combo box.

4	In the first wizard dialog box, click the option to find a record based on the value you selected in the list box or combo box.

5	Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the list box or combo box in Design view.

If you want to see the event procedure that makes the list box or combo box work, open the box's property sheet, and then click the Build button next to the AfterUpdate property box.


Why use a macro or an event procedure for data validation?

In most cases, you can verify that data is entered correctly into a control on a form by setting the ValidationRule property for the control, or by setting record or field validation rules in the underlying table to which the control is bound. Macros and event procedures provide additional power and flexibility for more complex validation.

Use a macro or an event procedure for data validation if:

•	Your validation rule involves conditions for more than one value on the form. For example, you may want to verify that any two of three fields are filled in before saving a record.

•	You want to display different error messages for different types of errors in the field. For example, if the value entered is greater than the acceptable range, you can display one message, and if it's less than the acceptable range, you can display a different message.

•	You want to be able to override your validation rule. In this case, you can display a warning message asking the user to confirm the data.

•	The validation involves references to controls on other forms or contains a function.

•	You have a validation rule that you can use for more than one form, and you want the convenience of defining the rule once, then referring to it in each form.

For more information on creating a macro, click  [image].

For more information on customizing an event procedure, click  [image].

For information on using a macro or an event procedure to validate data, click  [image].


Validate data by using a macro or event procedure

You can use a macro or an event procedure to validate data being entered in a form by creating a macro that responds to an event on the form, or by adding Visual Basic code to the form's built-in event procedures.

What do you want to do?

Validate data by using a macro

Validate data by using an event procedure


Validate data by using a macro

1	Open the form in Design view.

2	Create a macro.

How?

3	In the Macro window, click  [image]  on the toolbar.

4	In the Condition column of a blank action row, enter a validation condition.

5	In the Action column, click the action in the action list that you want to carry out if the validation condition is true.

6	For any additional actions you want to carry out if the validation condition is true, enter an ellipsis (...) in the Condition column followed by the action in the Action column. For example, it's usually a good idea to carry out a CancelEvent action for each validation condition after any other actions have been carried out.

7	For the event that you want to trigger the validation, set the event property to the name of the macro. For example, to trigger the validation when a control is updated with changed data, set the BeforeUpdate event property of the control to the name of the macro.

Tip   To validate data before a record as a whole is updated, attach the validation macro to the form's BeforeUpdate event rather than to the control's BeforeUpdate event.

For an example of validating data by using a macro, click  [image].

For information on the events used for data validation, click  [image].

For information on the order of validation for controls and fields, click  [image].


Example of validating data by using a macro

In some circumstances, you may want to use validation rules that depend on complex conditions, and then take different actions depending on those conditions. For example, because different countries have different rules for their postal codes, a database that stores postal codes can't rely on a simple validation rule to ensure that a postal code is entered correctly.

You can, however, create a macro that checks which country is entered in the Country control and then checks that the value entered in the PostalCode control has the right characteristics for that country.

First, open the form that contains the controls in Design view. Then, create a macro that displays different messages depending on the value of the Country control and the length of the entry in the PostalCode control.

Finally, set the BeforeUpdate event property of the form to the name of the macro. You use the form property rather than the control property because the validation involves two different controls on the form.

Now when you use the form to add a new supplier, Microsoft Access runs the validation macro after you finish entering the new record, but before it saves the record in the Suppliers table. If either condition in the macro is met, Microsoft Access displays the appropriate message and doesn't save the record in the Suppliers table.


Validate data by using an event procedure

1	Open the form in Design view.

2	Open the event procedure for the event that you want to trigger the validation.

How?

For example, to trigger the validation rule when a control is updated with changed data, open the control's BeforeUpdate event procedure.

3	Add Visual Basic code to the event procedure, specifying the validation condition and the operations to perform when those conditions are met.

Tips

•	It's usually a good idea to cancel the event that triggers the validation after the operations have been performed. You can cancel many events by setting the event procedure's Cancel argument to True.

•	To validate data before the record as a whole is updated, add code to the form's, rather than the control's, BeforeUpdate event procedure.

For an example of validating data by using an event procedure, click  [image].

For information on the events used for data validation, click  [image].

For information on the order of validation for controls and fields, click  [image].


Example of validating data by using an event procedure

In some circumstances, you may want to use validation rules that depend on complex conditions, and then take different actions depending on those conditions. For example, because different countries have different rules for their postal codes, a database that stores postal codes can't rely on a simple validation rule to ensure that a postal code is entered correctly.

You can, however, create an event procedure that checks which country is entered in the Country control and then checks that the value entered in the PostalCode control has the right characteristics for that country.

First, open the form that contains the controls in Design view. Then, add the following Visual Basic code to the form's BeforeUpdate event procedure to display different messages depending on the value of the Country control and the length of the entry in the PostalCode control.

Private Sub Form_BeforeUpdate(Cancel As Integer)

Select Case Me![Country]

Case "France", "Italy", "Spain"

If Len(Me![PostalCode]) <> 5 Then

MsgBox "PostalCode must be 5 characters."

Cancel = True

End If

Case "Australia", "Singapore"

If Len(Me![PostalCode]) <> 4 Then

MsgBox "PostalCode must be 4 characters."

Cancel = True

End If

End Select

End Sub

Note that you add Visual Basic code to the form's, not the control's, BeforeUpdate event procedure because the validation involves two different controls on the form.

Now when you use the form to add a new supplier, Microsoft Access runs the validation procedure after you finish entering the new record, but before it saves the record in the Suppliers table. If either condition in the procedure is met, Microsoft Access displays the appropriate message and doesn't save the record in the Suppliers table.


Events used for data validation

You typically use the following events to determine when Microsoft Access runs a validation macro or event procedure from a form.

Form event	Use for validation
BeforeUpdate	Before saving new or changed data in a record
OnDelete	Before deleting a record
Control event	Use for validation
BeforeUpdate	Before saving new or changed data in a control
OnExit	Before leaving a control


Order of validation for controls and fields

Validation rules for controls and fields are evaluated in the following order:

1.	Macro or event procedure validation (for example, a macro or an event procedure that responds to the BeforeUpdate event of the control or the form containing the control)

2.	The control's ValidationRule property

3.	The underlying table's validation rules for the field (as set in the field's ValidationRule, Required, and AllowZeroLength properties)

4.	The underlying table's ValidationRule property (this property performs validation on records)


Print a report from a form

You can automate how a user prints a report by carrying out the OpenReport and PrintOut actions in a macro or an event procedure. For example, you can make it possible for a user to print a report by clicking a button on a form, choosing a command from a custom menu, or pressing a key combination.

Use the OpenReport action if you want to restrict the records to be printed, or if you want to open a report in Print Preview. The OpenReport action has arguments you can use to specify the report to open, the view you want the report to open in (Print, Design, or Print Preview), and the set of records you want to see. When you use the OpenReport action to print a report, Microsoft Access prints the report using the default settings in the Print dialog box.

Use the PrintOut action to set printing options before printing your report. The PrintOut action includes arguments for every option in the Print dialog box (except Print To File), so you can specify a range of pages, the number of copies you want to print, and the print quality that you prefer. The PrintOut action prints the active object in the database, so in your macro or event procedure you must first carry out the SelectObject action to select the report you want, and then carry out the PrintOut action to print it.

What do you want to do?

Create a command button that prints a report

Add the OpenReport or PrintOut action to a macro

Carry out the OpenReport or PrintOut action in a Visual Basic procedure

Read about the OpenReport action

Read about the PrintOut action


Force a page break in a report if a condition is met

You can force a page break in a report if a condition is met by setting the Visible property of a page break control in a macro or an event procedure.

What do you want to do?

Use a macro to force a page break in a report if a condition is met

Use Visual Basic to force a page break in a report if a condition is met


Use a macro to force a page break in a report if a condition is met

1	Open the report in Design view.

2	In the toolbox, click  [image], then click in the report section where you want a conditional page break.

3	Create a macro.

How?

4	In a blank action row, click SetValue in the action list.

5	Set the Item argument to the identifier for the Visible property of the page break control. For example, if the name of the control is CondPgBreak, set the Item argument to [CondPgBreak].Visible.

6	Set the Expression argument to No.

7	Set the OnFormat property of the report's page header section to the name of the macro.

This hides the page break control when the report starts formatting each page, so the page doesn't break.

8	Create a second macro that sets the Visible property of the page break control to Yes when a conditional expression is met.

9	Select the section where you want the page to break, and set the section's OnFormat property to the name of the second macro.

When the condition is met, the page breaks. After the page is broken, the macro attached to the page header hides the page break control until the condition is met again.


Use Visual Basic to force a page break in a report if a condition is met

1	Open the report in Design view.

2	In the toolbox, click  [image], then click in the report section where you want a conditional page break.

3	Open the report's PageHeader_Format event procedure.

How?

4	In the event procedure, add an assignment statement that sets the Visible property of the page break control to No. For example, if the name of the control is CondPgBreak, add the following assignment statement:

Me![CondPgBreak].Visible = "No"

This hides the page break control when the report starts formatting each page, so the page doesn't break.

5	In the Format event procedure of the section where you want the page to break, add Visual Basic code that sets the Visible property to Yes when a condition is met. For example, if you want a page break to occur in the Detail section of the report if the value of the Counter control is 10, add the following code to the Detail_Format event procedure:

If Me![Counter] = 10 Then

Me![CondPgBreak].Visible = "Yes"

End If

When the condition is met, the page breaks. After the page is broken, the event procedure attached to the page header hides the page break control until the condition is met again.


Show or hide warning messages

You can temporarily disable the modal warning messages displayed by Microsoft Access while a macro or Visual Basic procedure is running, or enable them again, by carrying out the SetWarnings action in the macro or procedure.

What do you want to do?

Show or hide warning messages by using a macro

Show or hide warning messages by using Visual Basic


Show or hide warning messages by using a macro

1	Open an existing macro in the Macro window.

How?

2	In the place in the macro where you want to stop or resume the display of modal warning messages, add the SetWarnings action.

How?

3	To temporarily stop the display of warning messages, set the Warnings On argument to No. To resume displaying them, set the Warnings On argument to Yes.

4	Run the macro.

How?

When the macro stops running, the display of warning messages automatically resumes.


Show or hide warning messages by using Visual Basic

1	Open a Function or Sub procedure in the Module window.

2	In the place in the procedure where you want to stop or resume the display of modal warning messages, carry out the SetWarnings action.

How?

3	To temporarily stop the display of warning messages, set the Warnings On argument to No. To resume displaying them, set the Warnings On argument to Yes.

4	Run the procedure.

How?

When the code stops running, the display of warning messages automatically resumes.


Navigate between controls, records, and form pages

You can automatically move to a control, record, or form page in response to an event that happens on a form by carrying out the GoToControl, GoToPage, and GoToRecord actions in a macro or an event procedure.

What do you want to do?

Navigate between controls, records, and form pages by using a macro

Navigate between controls, records, and form pages by using Visual Basic


Navigate between controls, records, and form pages by using a macro

1	Create a macro.

How?

2	Do one of the following:

•	To move to a specific control, click GoToControl in the action list of a blank action row, and then set the Control Name argument to the name of the control to which you want to move.

•	To move to a specific record or to a new record, click GoToRecord in the action list of a blank action row, and then set the arguments.

•	To move to a specific form page, click GoToPage in the action list of a blank action row, then set the arguments.

3	Run the macro.

How?

For more information on the GoToControl action, click  [image].

For more information on the GoToRecord action, click  [image].

For more information on the GoToPage action, click  [image].


Navigate between controls, records, and form pages by using Visual Basic

1	Open the event procedure for the appropriate event in the Module window.

How?

For example, to respond to a mouse click on a command button, open the button's Click event procedure.

2	Do one of the following:

•	To move to a specific control, carry out the GoToControl action in the procedure, setting the Control Name argument to the name of the control to which you want to move.

  How?

•	To move to a specific record, or to a new record, carry out the GoToRecord action in the procedure.

•	To move to a specific form page, carry out the GoToPage action in the procedure.

3	Run the procedure.

How?

Note   You can also use Visual Basic to locate or move between records by using a Recordset object and the Move, Find, and Seek methods.

For more information on the GoToControl action, click  [image].

For more information on the GoToRecord action, click  [image].

For more information on the GoToPage action, click  [image].

For more information on the Recordset object and its methods, click  [image].


Automate importing, exporting, or linking of data

Depending on the type of data with which you're working, you can automate importing, exporting, and linking of data by carrying out the TransferDatabase, TransferSpreadsheet, or TransferText action in a macro or Visual Basic procedure.

What do you want to do?

Automate importing, exporting, or linking of data by using a macro

Automate importing,  exporting, or linking of data by using Visual Basic


Automate importing, exporting, or linking of data by using a macro

1	Create a macro.

How?

2	Do one of the following:

•	To import, export, or link data between the current Microsoft Access database and another database, click TransferDatabase in the action list of a blank action row.

•	To import, export, or link data between the current Microsoft Access database and a spreadsheet file, click TransferSpreadsheet in the action list of a blank action row.

•	To import, export, or link data between the current Microsoft Access database and a text file, click TransferText in the action list of a blank action row.

3	Set the action arguments.

4	Run the macro.

How?

For more information on the TransferDatabase action, click  [image].

For more information on the TransferSpreadsheet action, click  [image].

For more information on the TransferText action, click  [image].


Automate importing, exporting, or linking of data by using Visual Basic

1	Create a Visual Basic procedure.

How?

2	Do one of the following:

•	To import, export, or link data between the current Microsoft Access database and another database, carry out the TransferDatabase action in the procedure.

  How?

•	To import, export, or link data between the current Microsoft Access database and a spreadsheet file, carry out the TransferSpreadsheet action in the procedure.

•	To import, export, or link data between the current Microsoft Access database and a text file, carry out the TransferText action in the procedure.

3	Run the procedure.

How?

For more information on the TransferDatabase action, click  [image].

For more information on the TransferSpreadsheet action, click  [image].

For more information on the TransferText action, click  [image].


Automatically view the latest records for a form

You can automatically view the latest records for a form by refreshing and requerying the records.

If you're using a database that's shared on a network, you can view the latest version of existing records by creating a command button that updates form data.

To display the latest set of records in a form, including new records, you can requery the records by adding the Requery action to a macro or adding the Requery method to a Visual Basic procedure.

What do you want to do?

Create a command button that updates form data

Automatically view the latest records for a form by using a macro

Automatically view the latest records for a form by using Visual Basic


Automatically view the latest records for a form by using a macro

1	Create a macro.

How?

2	In a blank action row, click Requery in the action list.

To update records for a control that is based on a table or query, set the Control Name argument to the name of the control. To update the records for the form as a whole, leave the Control Name argument blank.

3	Run the macro.

How?

For more information on the Requery action, click  [image].


Automatically view the latest records for a form by using Visual Basic

1	Create a Visual Basic procedure.

How?

2	Add the Requery method to the procedure for the form or control whose records you want to update. For example, to view the latest records in a combo box, CategoryID, add the following method to the procedure:

CategoryID.Requery

3	Run the procedure.

How?

For more information on the Requery method, click  [image].

For an example of updating (requerying) a list to display the most current data, click  [image].


Display a message box

When you want to display a brief message, such as a warning, you can use a predefined dialog box called a message box. You can display a message box by adding the MsgBox action to a macro, or by adding the MsgBox function to a Visual Basic procedure.

What do you want to do?

Display a message box by using a macro

Display a message box by using Visual Basic


Display a message box by using a macro

1	Create a macro.

How?

2	In a blank action row, click MsgBox in the action list, and then set the action arguments.

3	Run the macro.

How?

For more information on the MsgBox action, click  [image].


Display a message box by using Visual Basic

1	Create a Visual Basic procedure.

How?

2	Add an assignment statement to the procedure that assigns the value returned by the MsgBox function to a variable. The function returns different values depending on the button a user clicks in the message box. Your procedure can then perform different operations based on the value returned.

For example, the following assignment statement runs the MsgBox function, displaying a message, and assigns the value returned by the function to the variable RetValue:

RetValue = MsgBox("Continue?", vbOKCancel)

3	Run the procedure.

How?

For information on the MsgBox function, click  [image].


Save a database object using a macro or event procedure

You can automate saving a database object by carrying out the Save action in a macro or an event procedure.

What do you want to do?

Save a database object by using a macro

Save a database object by using an event procedure


Save a database object by using a macro

1	Create a macro.

How?

2	In a blank action row, click Save in the action list, and then set the Object Type argument to the type of the object you want to save and the Object Name argument to the name of the object.

3	Run the macro.

How?

For example, to save a form by clicking a command button on the form, set the button's OnClick property to the name of the macro.

For more information on the Save action, click  [image].


Save a database object by using an event procedure

1	Open the event procedure for the appropriate event in the Module window.

How?

For example, to save a form by clicking a command button on a form, open the button's Click event procedure.

2	Carry out the Save action in the procedure, setting the Object Type argument to the type of the object you want to save and the Object Name argument to the name of the object.

How?

3	Run the procedure.

How?

For more information on the Save action, click  [image].


Carry out an action when my database first opens

You can use a special macro named AutoExec to carry out an action or series of actions when your database first opens. When you open a database, Microsoft Access looks for a macro with this name and, if it finds one, runs it automatically.

1	Create a macro containing the actions you want to run when you open the database.

How?

2	Save the macro with the name AutoExec.

The next time you open the database, Microsoft Access runs this macro automatically.

Notes

•	If you don't want to run the AutoExec macro when you open the database, hold down the SHIFT key when the database opens. You can use the SHIFT key to disable the AutoExec macro if you select the Use Access Special Keys check box in the Startup dialog box (Tools menu). To see the check box, click Advanced in the Startup dialog box.

•	You can also control how a database or application starts by setting options in the Startup dialog box (Tools menu). For more information, click  [image].


Assign an action or set of actions to a key

You can assign an action or set of actions to a specific key or key combination by creating an AutoKeys macro group. When you press the key or key combination, Microsoft Access carries out the action.

1	In the Database window, click the Macros tab.

2	Click New.

3	Click  [image]  on the toolbar.

4	In the Macro Name column, type the key or key combination to which you want to assign the action or set of actions.

For information on the key combinations you can use to make key assignments, click  [image].

5	Add the action or set of actions you want the key or key combination to carry out. For example, you could add a RunMacro action that runs the Print Current Record macro when CTRL+P is pressed.

6	Repeat steps 4 and 5 for any other key assignments you want to make.

7	Save the macro group with the name AutoKeys.

The new key assignments are in effect as soon as you save the macro group and each time you open the database.

Note   If you assign a set of actions to a key combination that is already being used by Microsoft Access (for example, CTRL+C for Copy), the actions you assign this key combination replace the Microsoft Access key assignment.


AutoKeys key combinations

The following table shows the key combinations you can use to make key assignments in an AutoKeys macro group. These key combinations are a subset of the syntax used in the SendKeys statement in Visual Basic. For more information on the syntax of the SendKeys statement, click  [image].

SendKeys syntax	Key combination
^A or ^4	CTRL+Any letter or number key
{F1}	Any function key
^{F1}	CTRL+Any function key
+{F1}	SHIFT+Any function key
{INSERT}	INS
^{INSERT}	CTRL+INS
+{INSERT}	SHIFT+INS
{DELETE} or {DEL}	DEL
^{DELETE} or ^{DEL}	CTRL+DEL
+{DELETE} or +{DEL}	SHIFT+DEL


Why does the folder default to My Documents when I open or create a new database?

In the past, you probably kept your files in the same folder or directory as the application that created them. However, you probably found that when it came time to back up all your files, it was complicated and time consuming because they were in different locations on your computer. As a solution, Microsoft Access defaults to the My Documents folder, which is a place where you can store all your files, enabling you to back up just one folder.

You can rename or move the My Documents folder, and Microsoft Windows still keeps track of it. This means Microsoft Access defaults to the renamed My Documents folder, regardless of its name or location on your computer. If you delete the My Documents folder, Microsoft Access will recreate it automatically.

If you prefer, you can have Microsoft Access default to a different folder entirely. For more information, click  [image].


I'm getting the message "Can't bind name name."

This error indicates that the specified name isn't a recognized field name or valid expression. Two possible causes are:

•	The data type of a parameter in a crosstab query or in a query that a crosstab query or chart is based on isn't specified in the Query Parameters dialog box. To solve the problem, do the following:

1	In the query that contains the parameter, specify the parameter and its data type in the Query Parameters dialog box. For more information, click  [image].

2	Then, in the query that contains the parameter, set the ColumnHeadings property. For more information, click  [image].

•	In any type of query, you referred to a database, table, or field incorrectly. For example, you referred to a field named Salary in an expression by typing [Sallary]*1.1.


Automatically create a database shortcut in the Favorites folder

When you open a database, you can have Microsoft Access automatically create a shortcut in the Favorites folder that opens the database directly or opens the folder where the database and other files are stored. The Favorites folder stores shortcuts to databases and other files you use frequently, including those in remote locations, so that you don't have to search for the files each time. The original file or folder doesn't move.

1	On the File menu, click Open Database.

2	Do one of the following:

•	To create a shortcut to a subfolder or database listed in the area under the Look In box, select the file or folder, click  [image] on the toolbar, and then click Add Selected Item To Favorites.

•	To create a shortcut to the main folder listed in the Look In box, click  [image] on the toolbar, and then click Add 'foldername' To Favorites.

Note   To quickly open the Favorites folder after you start Microsoft Access, in the Open dialog box, click  [image].


When to use the Favorites folder and the My Documents folder

Use the Favorites folder to store shortcuts to databases you use frequently, including those in remote locations. The original file or folder doesn't move. You can use a shortcut for quick access to the file without having to remember where the file is located. For information on adding a database shortcut to the Favorites folder automatically, click  [image].

Use the My Documents folder to store all your original databases and other files, enabling you to back up just one folder. It's the default folder for new Microsoft Access databases unless you change the default. For more information on the default folder, click [image].


Create or modify a query that gets its criteria from a custom dialog box

You can use a custom dialog box to enter criteria for a report's underlying query if, for example, you want to determine what records the printed report includes.

1	Create the dialog box.

How?

2	Create or open the query that will collect its criteria values from the dialog box.

3	Make sure that the query includes the tables you want to use and that the query design grid includes the fields whose values you want returned.

4	For each of the dialog box controls where you'll enter criteria values, there must be an associated field in the query's design grid. For each of these fields in the query design grid, use the Expression Builder to enter an expression in the Criteria cell that tells Microsoft Access to refer to the control on the dialog box for the criteria values.

For example, you could create a dialog box form named Customer Info with a control for the CustomerID field. By entering a customer ID in the dialog box, you could have the query return the correct customer's company name, address, and city. To do this, you'd add the CustomerID, CompanyName, Address, and City fields to the query's design grid. In the Criteria cell for the CustomerID field, enter the expression that tells Microsoft Access to refer to the Customer ID control in the dialog box for the criteria values the query uses. In this case, you'd enter the expression [Forms]![Customer Info]![CustomerID].

To read more about using forms to collect and display information, see Chapter 3, "Using Forms to Collect, Display, and Filter Information," in Building Applications with Microsoft Access for Windows 95.

For information on using a form to enter report criteria, click  [image].


I don't know how to display my records again after using the Data Entry command

•	On the Records menu, click Remove Filter/Sort.


I'm getting the error message "Query contains ambiguous outer joins."

This can occur when you try to run a query with certain combinations of joins. For an example of what causes the conflict and information on how to resolve it, refer to article Q124937 in the Microsoft Knowledge Base. For information on accessing the Knowledge Base, click  [image].


 What is a procedure?

You write Visual Basic for applications code in units called procedures. A procedure contains a series of statements and methods that perform an operation or calculate a value. For example, the following event procedure uses the OpenForm method to open the Orders form:

Private Sub OpenOrders_Click()

DoCmd.OpenForm "Orders"

End Sub

There are two kinds of procedures:

•	Sub procedures, like Visual Basic statements, perform an operation or series of operations but don't return a value. You can create your own Sub procedures or use the event procedures that Microsoft Access defines for you.

Each form and report in your database has a built-in form module or report module that contains predefined event procedures that run in response to events that occur on the form, the report, or the controls on the form or report. When Microsoft Access recognizes that an event has occurred on a form, report, or control, it automatically runs the event procedure named for the object and event. For example, you can write an event procedure that sets the focus to a Spouse Name text box when the user selects a Married check box.

•	Function procedures (often simply called functions) return a value, such as the result of a calculation. Visual Basic includes many built-in functions; for example, the Now function returns the current date and time. In addition to these built-in functions, you can create your own custom functions.

Because functions return values, you use them in expressions. You can use functions in expressions in many places in Microsoft Access, including in a Visual Basic statement or method, in many property settings, or in a criteria expression in a filter or query.

Tip   Wizards often automatically create event procedures for an object when you create the object. You can look at these event procedures to see examples of how procedures work.

Here is an example of a Function procedure, FirstOfNextMonth, that returns the date of the first day of the month following the current date:

Function FirstOfNextMonth()

FirstOfNextMonth = _

DateSerial(Year(Now), Month(Now) + 1, 1)

End Function

The function consists of a single assignment statement that assigns the results of an expression (on the right side of the equal sign [=]) to the name of the function, FirstOfNextMonth (on the left side of the equal sign). It calculates its results using the built-in Visual Basic DateSerial, Year, Now, and Month functions.

Once you've created this function, you can use it in an expression anywhere in Microsoft Access. For example, you could specify that a text box display the first day of the month following the current date as its default value by setting the text box control's DefaultValue property to the following expression in the property sheet:

=FirstOfNextMonth()

Both Sub and Function procedures can accept arguments. For more information on using arguments in Visual Basic, click  [image].


Create a custom Visual Basic for applications procedure

You can customize an event procedure by adding code to predefined templates in a form module or report module. You also can create your own Function procedures or Sub procedures in a standard module,  form module, or report module.

You can call procedures in a standard module from expressions, event procedures, procedures in other standard modules, and macros. Event procedures run automatically in response to events — such as mouse clicks — that occur on a form, report, or control.

What do you want to do?

Create a custom function

Create a custom Sub procedure

Customize an event procedure


Create a custom function

1	Declare the function by entering the Function statement in a standard module, form module, or report module.

To open a standard module, click the Modules tab in the Database window, and then click New. To open a form or report module, open the form or report in Design view, and then click  [image]  on the toolbar.

2	Specify any function arguments in parentheses immediately following the function name. For example, the following declaration for the IsLoaded function specifies strFormName as an argument:

Function IsLoaded(strFormName)

3	Add the Visual Basic for applications code that performs the operation or calculation that you want the function to perform.

For more information on the Function statement, click  [image].


Create a custom Sub procedure

1	Declare the procedure by entering the Sub statement in a standard module, form module, or report module.

To open a standard module, click the Modules tab in the Database window, and then click New. To open a form or report module, open the form or report in Design view, and then click  [image]  on the toolbar.

2	Specify any arguments in parentheses immediately following the procedure name. For example, the following declaration for the ShowEvent Sub procedure specifies strEventName as an argument:

Sub ShowEvent(strEventName)

3	Add the Visual Basic for applications code that performs the operation that you want the procedure to perform.

For more information on the Sub statement, click  [image].


Customize an event procedure

Each form module and report module in a database contains predefined event procedures that run in response to events that occur on a form or report. You can create a custom response to an event by adding Visual Basic for applications code to the event procedure.

1	In form or report Design view, display the property sheet for the form or report, or a section or control on the form or report.

2	Click the Event tab.

3	Click the event property for the event that you want to trigger the procedure. For example, to display the event procedure for the Change event, click the OnChange property.

4	Click the Build button next to the property box to display the Choose Builder dialog box.

5	Double-click Code Builder to display the event procedure's Sub and End Sub statements in the Module window. These statements define, or declare, the event procedure.

Microsoft Access automatically declares event procedures for each object and event in a form or report module, using the Private keyword to indicate that the procedure can be accessed only by other procedures in that module.

6	Add the code to the event procedure that you want to run when the event occurs. For example, to produce a sound through the computer's speaker when data in the CompanyName text box changes, add a Beep statement to the CompanyName_Change event procedure, as follows:

Private Sub CompanyName_Change()

Beep

End Sub

The event procedure runs each time the event occurs for the object.


Running Visual Basic for applications code

You run Visual Basic code in Microsoft Access by running a Sub procedure or Function procedure. Procedures contain a series of statements and methods that perform an operation or calculate a value.

Procedures are stored in units called modules. However, you don't run a module; rather, you run the procedures in the module in response to events, or you call the procedures from expressions, macros, or other procedures.

Here are the ways to run Visual Basic code in Microsoft Access:

•	Customize an event procedure.

For example, you can add code to the Click event procedure of a command button that opens a form when a user clicks the button. For more information on customizing an event procedure, click  [image].

•	Use a function in an expression.

For example, you can use a function in an expression that defines a calculated field in a form, report, or query. You can use expressions as property settings in queries and filters, in macros and actions, in Visual Basic statements and methods, or in SQL statements. For more information on creating a custom function, click  [image].

•	Call a Sub procedure in another procedure or in the Debug window.

For example, you can call a Sub procedure in another procedure to perform an operation that is common to many procedures. Rather than repeating the Visual Basic code that performs the operation in each procedure, you write it once in the common procedure, then call the common procedure each time you want to perform the operation. For more information on creating a Sub procedure, click  [image].

•	Carry out the RunCode action in a macro.

You can use the RunCode action to run a built-in Visual Basic function or a function you've created in a macro. (To run a Sub procedure, create a function that calls the Sub procedure and then use the RunCode action to run the function.) For more information on the RunCode action, click  [image].


Carry out a macro action in a Visual Basic for applications procedure

Microsoft Access defines a special object, DoCmd, that you use to carry out macro actions in Visual Basic procedures. You carry out an action by adding a method of the DoCmd object to your procedure. Most actions have a corresponding DoCmd method.

•	In the procedure, add the DoCmd method that corresponds to the action, using the following syntax:

DoCmd.actionname [arguments]

Actionname is the name of a macro action. Arguments are the action arguments, if there are any.

For example, to create a procedure that carries out the OpenForm action, add the OpenForm method of the DoCmd object to the procedure. The following method is equivalent to the OpenForm action; it opens the Add Products form:

DoCmd.OpenForm "Add Products"

Eight actions don't have corresponding DoCmd methods, although some have equivalent Visual Basic statements or functions. For a list of those actions and their Visual Basic equivalents, click  [image].


Macro actions that don't have corresponding DoCmd methods

Action	Visual Basic for applications equivalent
AddMenu	No equivalent
MsgBox	MsgBox function or statement
RunApp	Shell function
RunCode	Procedure call (Call statement)
SendKeys	SendKeys statement
SetValue	Assignment statement (Let statement)
StopAllMacros	Stop or End statements
StopMacro	Exit Sub or Exit Function statements


Getting online Help on Visual Basic for applications

There are many ways to access online Help for answers to questions about Visual Basic and for information about Visual Basic keywords. Descriptions of a few of the most common and useful ways of accessing Help follow.

Note   If you choose Typical Setup when you install Microsoft Access, Setup doesn't install language reference online Help topics for components shared between Microsoft Access and other applications. For example, Microsoft Access doesn't install language reference online Help for some Visual Basic functions and statements. To install all language reference topics, run Setup again and click Help Topics, then click Change Option and click Language Reference.

To access online Help, you can:

•	Press F1 in a Visual Basic module. While you are working in a module, you can go directly to online Help on a method, property, function, statement, or object by clicking the keyword in a line of code and then pressing F1.

•	Browse the object hierarchy. You can use the Object Browser to see the list of an object's methods and properties. For information on using the Object Browser, click  [image].

•	Ask the Answer Wizard. The Answer Wizard makes it easy to find the topics you're looking for. Just type your query, and then select one of the topics the Answer Wizard suggests. The more specific your query is, the more specific the suggested topics will be. An example of a specific query is "How do I program my form to automatically update data?"

On the Answer Wizard tab in the Help Topics dialog box, look under Programming And Language Reference for topics with reference information about elements of the Visual Basic for applications programming language. The Tell Me About area lists topics with conceptual information, while the How Do I area lists topics with information about how to accomplish specific tasks.

•	Use the Contents, Index, and Find tabs. The Help Topics dialog box contains several tabs that you can use to access Help information in different ways:

•	Click the Contents tab and then double-click the Microsoft Access Programming And Language Reference book to see the categories of reference information, such as actions, events, functions, objects and collections, methods, properties, and statements. Double-click a category book to view lists of topics for each category.

To print a topic or book of topics, select the topic or book and then click Print.

•	Click the Index tab to see a list of index entries for topics. In the first box, type the first few letters of the word you're looking for. In the second box, click the index entry you want, and then click Display.

Note   If several topics have the same name, the Index will distinguish the second, third, and so on topics by showing the product or area of the product the topics pertain to. The first topic will not be identified by product or product area.

•	Click the Find tab to do a full-text search for a word or phrase in Help.

Tips

•	To switch between your application and online Help, press ALT+TAB or use the Windows taskbar. If you leave online Help active, you can immediately return to the last topic you were viewing.

•	To copy selected text, change the font size, print, annotate, or keep the Help window on top, use the shortcut menu.


Copy Visual Basic for applications examples in online Help

1	With the right mouse button, select the text you want to copy.

2	On the shortcut menu, click Copy.

3	Switch to Microsoft Access.

4	Paste the example into your module.

Tip   You can also press CTRL+C to copy a selected example in a Help window. Press CTRL+V to paste the example into your module.


Work with objects in Visual Basic for applications using the Object Browser

You can use the Object Browser to view and navigate among the objects available in Microsoft Access and other applications that support Visual Basic, as well as the methods and properties of each object. When you locate a method or property in the Object Browser, you can paste its syntax into the active module.

What do you want to do?

Locate a method or property in the Object Browser

Use the Object Browser to paste method or property syntax into a Visual Basic module


Locate a method or property in the Object Browser

1	Open any module.

2	On the View menu, click Object Browser.

3	In the Libraries/Databases box, click Access or another library.

4	In the Modules/Classes box, click the object you're interested in.

5	In the Methods/Properties box, click the method or property you want.


Use the Object Browser to paste method or property syntax into a module

1	Click in a module where you want to paste the syntax.

2	Locate the method or property in the Object Browser.

3	Click Paste Text.

Microsoft Access pastes the syntax from the bottom box of the Object Browser into the module.


Change how Visual Basic for applications code is displayed in the Module window

By setting options in the Options dialog box, you can change the color, font, size, and tab width used when you type Visual Basic code in the Module window. You can also specify whether each procedure is displayed individually in the Module window (default), or whether the entire module is displayed.

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Set the appropriate options.

For more information on an option, click  [image]  in the title bar of the Options dialog box, and then click the option.


Disable syntax-error checking for Visual Basic for applications code

Visual Basic automatically checks the code you type in the Module window for syntax errors as you type it. To disable this feature, do the following:

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Under Coding Options, clear the Auto Syntax Check check box.


Ignore error handling for Visual Basic for applications code

When you add an On Error statement to a Visual Basic procedure to handle errors that occur while the procedure runs, Visual Basic automatically branches to an error-handling routine when an error occurs. However, you may want to ignore a procedure's error-handling code in some circumstances; for example, while you're debugging the procedure.

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Under Coding Options, select the Break On All Errors check box.


Require variable declarations for Visual Basic for applications code

Visual Basic doesn't automatically require that you explicitly declare a variable before using it in a procedure. If you use a variable that hasn't been explicitly declared, Visual Basic implicitly declares it as a variable with the Variant data type.

Although implicit declarations are convenient, they can lead to subtle errors in your code. To require that variables be declared before they are used in a procedure, do the following:

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Under Coding Options, select the Require Variable Declaration check box.

When the Require Variable Declaration check box is selected, Microsoft Access automatically includes an Option Explicit statement in the Declarations section of all new modules in the database, including the built-in form or report modules associated with new forms or reports. For more information on the Option Explicit statement, click  [image].


Specify a command-line argument that can be used in Visual Basic code

When you start Microsoft Access, you can use the /Cmd command-line option to specify a command-line argument that can be used in Visual Basic for applications code. To specify this argument, do the following:

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Under Current Database Only, type the argument in the Command Line Arguments box.

For more information on the /Cmd command-line option, click  [image].


Change how Visual Basic for applications compiles code

By default, Visual Basic compiles code on demand — it compiles a module only when code in the module changes or when a procedure in the module is called by a procedure in another module.

However, while you're developing a database application, you may want Visual Basic to more fully compile code so that you can detect compilation errors. To disable compile on demand, do the following.

1	On the Tools menu, click Options.

2	Click the Module tab.

3	Under Coding Options, clear the Compile On Demand check box.

Note   Disabling the compile on demand feature can slow down performance.


Control the flow of Visual Basic for applications code

Using conditional statements and looping statements (also known as control structures), you can write Visual Basic code that makes decisions, repeats actions, and runs a series of statements that apply to the same object.

What do you want to do?

Use conditional statements to make decisions in Visual Basic code

Use loops to repeat Visual Basic code

Run a series of statements in Visual Basic that apply to the same object


Use conditional statements to make decisions in Visual Basic for applications code

Conditional statements evaluate whether a condition is True or False and then specify one or more statements to run, depending on the result. Usually, a condition is an expression that uses a comparison operator to compare one value or variable with another.

What do you want to do?

Branch when a condition is True or False (If...Then...Else statement)

Select a branch from a set of conditions (Select Case statement)

Learn more about comparison operators


Use loops to repeat Visual Basic for applications code

Looping allows you to run a group of statements repeatedly. Some loops repeat statements while or until a condition is False; others repeat statements while or until a condition is True. There are also loops that repeat statements a specified number of times or for each object in a collection or an array.

What do you want to do?

Repeat statements while or until a condition is True or False (Do...Loop statement)

Repeat statements a specified number of times (For...Next statement)

Repeat statements for each object in a collection or an array (For Each...Next statement)


Run a series of statements in Visual Basic that apply to the same object

In Visual Basic for applications, you usually need to specify an object before you can run one of its methods or change one of its properties.

•	To specify an object once for an entire series of statements, use the With statement.

For more information on the With statement, click  [image].


Debug Visual Basic for applications code

Debugging is a process you use to find and resolve errors, or bugs, in your Visual Basic code. There are three types of errors you may encounter as your code runs:

•	Compile-time errors occur as a result of incorrectly constructed code. You may have forgotten to balance pairs of statements (such as If and End If or For and Next), or you may have a programming mistake that violates the rules of Visual Basic (such as a misspelled word, missing separator, or type mismatch error).

Compile-time errors also include syntax errors, which are errors in grammar or punctuation. These include mismatched parentheses or an incorrect number of arguments passed to a function.

•	Run-time errors occur after the application starts to run.  Examples of run-time errors include attempting an illegal operation, such as dividing by zero or writing to a file that doesn't exist.

•	Logic errors occur when the application doesn't perform as intended and produces incorrect results.

To help you isolate all three types of errors and to monitor how your code runs, Visual Basic provides debugging tools that let you step through your code one line at a time, examine or monitor the values of expressions and variables, and trace procedure calls.

Note   To use most of the Microsoft Access debugging tools, you need to suspend execution of your code.

What do you want to do?

Use a breakpoint to suspend execution of code

Step through code one line at a time

Examine the values of expressions and variables using the Debug window

Monitor the values of expressions and variables by setting a watch expression

Trace Visual Basic procedure calls


Use a breakpoint to suspend execution of Visual Basic for applications code

When you suspend execution of Visual Basic code, the code is still running but paused between running statements. To make Visual Basic pause execution of your code, you can set a breakpoint.

1	In the Module window, move the insertion point to a line of code that isn't already a breakpoint.

2	Click  [image]  on the toolbar or press F9.

To clear a breakpoint, move the insertion point to the line of code on which the breakpoint has been set, then click  [image]  on the toolbar or press F9.

Note   You can also cause code execution to be suspended by setting a watch expression, by adding a Stop statement to a procedure, or by pressing CTRL+BREAK while the code is running.


Step through Visual Basic for applications code

Stepping through your Visual Basic code can help you identify where an error is occurring. You can see whether each line of code produces the results you expect.

1	Suspend execution of the code.

How?

Microsoft Access displays the line of code where execution is suspended.

2	Do one of the following:

•	To step through each line of code and into the code in a procedure called by another procedure (step into), click  [image]  on the toolbar or press F8.

•	To step through each line of code but run any procedure that is called as a unit (step over), click  [image]  on the toolbar or press SHIFT+F8.

•	To run the code that precedes the current line of code, and then break so you can step through each line of code (step to cursor), press CTRL+F8.

You can alternate between these types of stepping. The type of stepping you do depends on which portions of code you want to analyze.


Use the Immediate pane in the Debug window while working with Visual Basic

Use the Immediate pane in the Debug window to check the results of a line of Visual Basic for applications code. You can use the Immediate pane to check the value of a control, field, or property; to display the result of an expression; or to assign a new value to a variable, field, or property. The Immediate pane is a kind of scratch pad window in which statements, methods, and Sub procedures are evaluated immediately.

1	If you want to use the Immediate pane at a certain point during execution of the code, suspend execution at that point.

How?

2	Click  [image]  on the toolbar.

3	Type a statement, method, or Sub procedure call in the window, and then press ENTER.

Tips

•	You can view the results of an expression in the Immediate pane by entering the Print method of the Debug object, followed by the expression. You can use a question mark (?) as shorthand for the Print method. For example, Visual Basic displays the value returned by the FirstOfNextMonth custom function if you enter either of the following lines in the Immediate pane:

Debug.Print FirstOfNextMonth()

? FirstOfNextMonth()

You can also add the Print method of the Debug object to your Visual Basic code to display values or the results of expressions in the Immediate pane while the code is running. When the code has finished running, you can look at the results.

•	You can display the Immediate pane in any window in Microsoft Access by pressing CTRL+G.


Set a watch expression in Visual Basic for applications code

A watch expression is an expression you specify to be monitored in the Debug window. When execution of your code is suspended, you can observe the values of the watch expressions you selected in the Watch pane of the Debug window. You can also perform an instant watch to see the value of an expression that hasn't been specified as a watch expression.

What do you want to do?

Add a watch expression to the Watch pane of the Debug window

Perform an instant watch


Add a watch expression to the Watch pane of the Debug window

1	On the Tools menu, click Add Watch.

Microsoft Access displays the Add Watch dialog box.

2	If an expression is already selected in the Module window, it is automatically displayed in the dialog box. If no expression is displayed, enter the expression you want to evaluate. The expression can be a variable, a property, a function call, or any other valid expression.

3	To select the range for which the expression will be evaluated, select a module or procedure context under Context.

Note   Select the narrowest scope that fits your needs. Selecting all procedures or all modules could slow code execution.

4	To define how the system responds to the watch expression, select an option under Watch Type:

•	To display the value of the watch expression, click Watch Expression.

•	To stop execution if the expression evaluates to True, click Break When Expression Is True.

•	To stop execution if the value of the expression changes, click Break When Expression Has Changed.

To modify a watch expression, select the expression in the Watch pane, and then click Edit Watch on the Tools menu. To delete the watch expression, click Delete.


Perform an instant watch while debugging Visual Basic for applications code

1	Suspend execution of your Visual Basic code.

How?

2	Select the expression whose value you want to see.

3	Click  [image]  on the toolbar.

Microsoft Access displays the Instant Watch dialog box, where you can see the value of the expression or add the expression to the Watch pane.


Trace Visual Basic procedure calls while debugging Visual Basic code

When you suspend execution of Visual Basic for applications code while debugging the code, you can use the Calls dialog box to view a list of procedures that have been started but not completed.

1	Suspend execution of your Visual Basic code.

How?

2	Click  [image]  on the toolbar.

Microsoft Access displays the most recently called procedure at the top of the list, followed by the next most recent procedure call, and so on. To display the statement that calls the next procedure in the list, click Show.


Make a Visual Basic for applications procedure available to more than one database

1	Create a separate database of common procedures.

This database can contain the functions and Sub procedures that you want to make available to more than one database.

2	Add the procedure to the database.

3	Open a module in the database where you want to use the procedure.

4	On the Tools menu, click References.

5	In the References dialog box, click the box next to the database that contains the common procedures.

Once you have established the reference to the database, you can call the procedures in the referenced database from code in the current database.


Working with data and database objects using Visual Basic for applications code

In addition to working with data and objects such as forms and reports in the Microsoft Access interface, you can use the power of Visual Basic to write procedures that automatically create, delete, and modify data and objects. For example, you can write a procedure that places a caption on a form or that changes the color of a field on a form.

You can refer to data and objects directly in your procedure code, or declare object variables to represent them. Once an object variable is declared and assigned, you can use it just as you would the object it represents, and you can change its value, just as you can that of any variable.

For example, the following Sub procedure creates a table, Old Invoices, with a single field, OrderID:

Sub CreateTable ()

' Declare variables.

Dim dbs As Database, tbl As TableDef, fld As Field

' Assign the current database to the database

' variable.

Set dbs = CurrentDB()

' Create a new table and field, and assign them

' to the table and field variables.

Set tbl = dbs.CreateTableDef("Old Invoices")

Set fld = tbl.CreateField("OrderID", dbText)

' Add the field to the table, then add the table

' to the database.

tbl.Fields.Append fld

dbs.TableDefs.Append tbl

dbs.TableDefs.Refresh

End Sub

The Microsoft Jet database engine defines the objects, such as tables, queries, relationships, and indexes, that handle data-management tasks in a Microsoft Access database. These objects are called data access objects. You can share Visual Basic code that uses data access objects with other applications, such as Microsoft Excel, that use the Jet database engine.

In addition, Microsoft Access defines a variety of objects that you use for working with data, such as forms, reports, and controls. You can share Visual Basic code that uses Microsoft Access objects with other applications that support OLE Automation.

For more information on working with data access objects, click  [image]  or see Chapter 5, "Working with Objects and Collections," in Building Applications with Microsoft Access for Windows 95.


Displaying multiple instances of a form

When you create a form and open it in Microsoft Access, you normally display a single copy of it. However, you can use Visual Basic for applications to display different records in different copies, or instances, of a form you create.

For example, a Customer Phone List form might have a command button to view additional customer information in a Customers form. Normally, you could view customer information in the Customers form for only one customer at a time. However, by using the New keyword in a Visual Basic procedure, you can create multiple instances of the Customers form to view more than one customer record at the same time.

To reproduce the Customer Phone List example shown above, do the following:

•	In the Declarations section of the Customer Phone List form module (Form_CustomerPhoneList), declare a collection variable in which copies of the Customers form will be stored, as follows:

  Dim colFrmInstances As New Collection

•	Then, in the View command button's Click event procedure, add the following code:

  Private Sub View_Click()

 	' Declare an object variable based on the Customers

 	' form.

 	Dim frmNewInst As Form_Customers

 	' Set the variable to a new instance of the form.

 	Set frmNewInst = New Form_Customers

 	' Set form properties.

 	frmNewInst.AllowAdditions = False

 	frmNewInst.AllowDeletions = False

 	frmNewInst.NavigationButtons = False

 	frmNewInst.RecordSelectors = False

 	' Synchronize the Customer Phone List and Customers

 	' forms, requery, and make the Customers form

 	' instance visible.

 	frmNewInst.RecordSource = _

"Select * from Customers Where CustomerID = '" _

& Forms![Customer Phone List]!CustomerID & "';"

 	frmNewInst.Requery

 	frmNewInst.Visible = True

' Change the caption so that each instance can be

' distinguished easily.

frmNewInst.Caption = "Detail of " & _

frmNewInst!CustomerID

' Add the new form instance to a collection so that

' the form will remain open. Form instances close

' when all variables referring to them have gone out

' of scope.

colFrmInstances.Add frmNewInst, frmNewInst!CustomerID

  End Sub

For more information on the New keyword, click  [image].


Convert macros to Visual Basic for applications

Microsoft Access can automatically convert macros to Visual Basic event procedures or modules that perform equivalent actions using Visual Basic code. You can convert macros on a form or report, or convert global macros that aren't attached to a specific form or report.

What do you want to do?

Convert macros on a form or report

Convert global macros


Convert macros on a form or report to Visual Basic for applications

•	In form or report Design view, click Macros on the Tools menu, and then click Convert Macros To Visual Basic.


Convert global macros to Visual Basic for applications

1	In the Database window, click the Macros tab.

2	Click the macro you want to convert.

3	On the File menu, click Save As/Export.

4	In the Save As dialog box, click Save As Visual Basic Module.


Use arguments in Visual Basic for applications

An argument supplies additional information to a procedure, statement, or method. When you create a Function or Sub procedure, you declare arguments if you want to be able to supply information to the procedure when you call it.

When you call a procedure that has arguments, you specify the arguments that you want to pass to it. You also specify arguments for many statements and methods.

What do you want to do?

Create a custom function

Create a Sub procedure

Specify arguments when you use a procedure, statement, or method


Specify arguments when you use a procedure, statement, or method in Visual Basic code

•	Specify the arguments immediately after the name of the procedure, statement, or method. For a Function procedure or a method that returns a value, enclose the arguments in parentheses. If you specify more than one argument, separate the arguments with a comma.

For example, the following Close method of the DoCmd object closes the Add Products form. It accepts two arguments, acForm and "Add Products":

DoCmd.Close acForm, "Add Products"

Because this method doesn't return a value, the arguments aren't enclosed in parentheses.

Tip   You can use the Object Browser to paste method or property syntax, including arguments, into your Visual Basic for applications code. The Object Browser pastes named arguments that you can specify in any order. You can use these named arguments, or replace the named arguments with standard arguments. For more information on using the Object Browser, click  [image]. For more information on using named arguments, click  [image].


Troubleshoot Visual Basic modules

What do you need help with?

I don't understand how modules work. Please give me an overview.

How do I find where problems are occurring in my Visual Basic for applications code?

The criteria argument in a DLookup or other domain aggregate function produces unexpected results.

When I run my code, Microsoft Access displays messages that I don't want to see.

How do I use Visual Basic to add a new record to a table?

My procedure produces unexpected results when I use one of the Find methods.

I want to test my Function or Sub procedure to see if it works.

Microsoft Access produces a "Sub or Function not defined" error when I try to use the IsLoaded function.

Microsoft Access produces a "Method or data member not found" error when I try to refer to a table field in code.

How can I use Visual Basic to change the underlying SQL statement of a query?


When I run my code, Microsoft Access displays messages that I don't want to see.

You can temporarily stop the display of warnings and other messages while Visual Basic for applications code is running by using the SetWarnings method to carry out the SetWarnings action. You can also use the SetWarnings method to restart the display of messages. For more information, click  [image].


How do I use Visual Basic for applications to add a new record to a table?

You can programmatically add a new record to a table or result set by using the AddNew and Update methods of the Recordset object. For more information, click  [image]  or see Chapter 9, "Working with Sets of Records," in Building Applications with Microsoft Access for Windows 95.


My procedure produces unexpected results when I use one of the Find methods.

The FindFirst, FindLast, FindNext, and FindPrevious methods may produce unexpected results for the following reasons:

•	The criteria argument uses invalid syntax to refer to the value of a control or property. For more information about referring to the value of a control, click  [image].

•	The criteria argument uses invalid syntax to combine the value of a field, control, or property with a literal string. For more information about values in expressions, click  [image].

The FindRecord and FindNext methods may produce unexpected results if the FindRecord method's onlycurrentfield argument is set to acCurrent. Use the GoToControl method to move the focus to the control containing the data you're searching for before using the FindRecord or FindNext method.


I want to test my Function or Sub procedure to see if it works.

You can use the Immediate pane in the Debug window to check the results of a Function or Sub procedure. For example, to see the value returned by the custom function FirstOfNextMonth, type a question mark followed by a space, the name of the function, and any arguments surrounded by parentheses:

? FirstOfNextMonth(Now)

For more information, click  [image].


Microsoft Access produces a "Sub or Function not defined" error when I try to use the IsLoaded function.

The IsLoaded function is a sample Function procedure included with the Northwind Traders sample database, and not a built-in Visual Basic function. To use the IsLoaded function in your database, first open the Northwind sample database, then copy the function, and paste it in a module in your database.

For information about opening the Northwind sample database, click  [image].


Microsoft Access produces a "Method or data member not found" error when I try to refer to a table field in code.

Microsoft Access produces this error if you use the . (dot) operator rather than the ! operator to refer directly to a table field. For example, this error is produced by the last line of the following block of Visual Basic for applications code:

Dim dbsCurrent As Database

Dim tblTest As TableDef

Dim fldTest As Field

Set dbsCurrent = CurrentDb()

Set tblTest = dbsCurrent.TableDefs("Categories")

Set fldTest = tblTest.CategoryID

To correct the problem, replace the . (dot) operator with the ! operator or refer to the field as an element of the Fields collection. You can use either of the following lines of code, although the first may result in faster performance:

Set fldTest = tblTest!CategoryID

Set fldTest = tblTest.Fields("CategoryID")

For more information on using the . (dot) and ! operators, click  [image].


How can I use Visual Basic for applications to change the underlying SQL statement of a query?

You can use the SQL property of a QueryDef object to change the underlying SQL statement of a query. For example, the following block of Visual Basic code changes the underlying SQL statement of the query EmployeeList so that the query selects all records in the Employees table:

Dim dbsCurrent As Database

Dim qryTest As QueryDef

Set dbsCurrent = CurrentDb()

Set qryTest = dbsCurrent.QueryDefs("EmployeeList")

qryTest.SQL = "SELECT * FROM Employees;"

For more information about the SQL property, click  [image].


Optimizing Visual Basic for applications code performance

Often, the best way to improve the speed of your Visual Basic code is to choose a more efficient approach. However, certain techniques can help make your code run faster.

•	Make sure the code in your database is compiled. In the Module window, click Compile All Modules on the Run menu, and then click Save All Modules on the File menu.

Note   Make sure to recompile your code after you rename a database file. Renaming a database decompiles the code in the database.

•	Always explicitly declare variables. You can require that variables be explicitly declared before they are used in a procedure by setting the Require Variable Declarations Tools option. For more information, click  [image].

•	Use the most specific type possible when you declare variables. For example, declare a variable that will be used to represent a form as type Form rather than as type Object or Variant.

•	Use variables to refer to properties, controls, and data access objects. If you refer more than once to the value of a property or control on a form, or to a data access object or its property, create object variables and refer to the variables rather than using full identifiers.

•	Use the Me keyword for form references within an event procedure.

•	Use the Ilf function judiciously. Avoid using the Ilf function if either of the return expressions takes a long time to evaluate.

•	Use string functions when appropriate. Use the $ functions (for example, the Str$ function) when working with strings and the non-$ functions when working with Variant or other data types.

•	Use the Integer or Long data type for math when possible.

•	Use dynamic arrays and the Erase or ReDim statement to reclaim memory.

•	Use constants whenever possible.

•	Use bookmarks for fast relocation. Use bookmarks instead of the FindNext method or some other means to return to a particular record.

•	Use the FindRecord and FindNext methods on indexed fields. These methods are much more efficient when used on a field that is indexed.

•	Organize your modules. Visual Basic loads modules on demand — that is, it loads a module into memory only when your code calls one of the procedures in that module. Placing related procedures in the same module causes Visual Basic to load modules only as needed.

•	Eliminate dead code and unused variables. As you develop and modify your applications, you may leave behind procedures that aren't called from anywhere in your code or declared variables that are no longer used. Consider reviewing your code to find and remove unused procedures and variables.

For more information, see Chapter 13, "Optimizing Your Application," in Building Applications with Microsoft Access for Windows 95.


Adjust the size and proportions of a picture on a Microsoft Access form or report

How you adjust the size and proportions of a picture depends on whether it's a background picture (watermark) or a picture displayed in the foreground using an image control, unbound object frame, or bound object frame.

What do you want to do?

Adjust the size of a background picture

Adjust the size of a picture displayed in an image control, unbound object frame, or bound object frame


Adjust the size and proportions of a background picture

1	In form or report Design view, double-click the form selector or report selector to open the property sheet.

2	In the PictureSizeMode property box, click one of the following settings:

Setting	Description
Clip	Displays the picture at actual size. If the picture is larger than the form or report, the image is cut off.
Stretch	Sizes the picture to fit within the form or report. This setting may distort the image.
Zoom	Displays the picture in its entirety after sizing it to fill either the height or width of the form or report. This setting won't distort the image.
Note   If you set the PictureTiling property to Yes, set the PictureSizeMode property to Clip.


Change a switchboard form created by the Database Wizard

When you use the Database Wizard to create a database, Microsoft Access automatically creates a switchboard that helps you to navigate around the database. This switchboard has buttons that you can click to open forms and reports (or open other switchboards that open additional forms and reports), quit Microsoft Access, or customize the switchboard.

What do you want to do?

Create a new switchboard that you can open from the opening switchboard

Make a change to an existing switchboard

Change which switchboard is automatically displayed when you open the database

Delete a switchboard


Create a new switchboard that you can open from the opening switchboard

1	Open the database if it's not already open, and then click Change Switchboard Items in the opening switchboard.

2	Click New.

3	Type the name of the new switchboard, and then click OK.

Microsoft Access adds the switchboard to the Switchboard Pages box.

4	Click the new switchboard, and then click Edit.

5	Click New.

6	Type the text for the first switchboard item, and then click a command in the Command box. For example, type View Recording Artists, and then click Open Form In Edit Mode in the Command box.

Depending on which command you click, Microsoft Access displays another box below the Command box. Click an item in this box, if necessary. For example, if you click one of the form commands in the Command box, click the name of the form you want to open.

7	Click an item in the second box. For example, if you clicked Open Form In Edit Mode in step 6, click Recording Artists in the Form box, and then click OK.

8	Repeat steps 5 through 7 until you've added all the items to the switchboard. If you want to edit or delete an item, click the item in the Items On This Switchboard box, and then click Edit or Delete. If you want to rearrange items, click the item in the box, and then click Move Up or Move Down.

9	When you've finished creating the switchboard, click Close.


Make a change to an existing switchboard

1	Open the database if it's not already open, and then click Change Switchboard Items in the opening switchboard.

2	Click the switchboard you want to edit, and then click Edit.

3	Click the item on the switchboard you want to change, and then do one of the following:

•	To change the text of the item, the command performed by the item, or the object that's opened or run when you click the button, click Edit.

•	To add an item, click New, type the text for the item, and then click a command in the Command box. Depending on which command you click, Microsoft Access displays another box below the Command box. Click an item in this box, if necessary. For example, if you click one of the form commands in the Command box, click the name of the form you want to open.

•	To delete an item, click Delete.

•	To move an item, click Move Up or Move Down.

4	When you're finished changing items, click Close.


Change which switchboard is automatically displayed when you open the database

1	Open the database if it's not already open, and then click Change Switchboard Items in the opening switchboard.

2	If the switchboard that you want to use as the opening switchboard is displayed in the Switchboard Pages box, click it. Otherwise, create the switchboard.

How?

3	Click Make Default.

The next time you open your database, Microsoft Access will automatically display the switchboard you specified.


Delete a switchboard

1	Open the database if it's not already open, and then click Change Switchboard Items in the opening switchboard.

2	Click the switchboard you want to delete in the Switchboard Pages box, and then click Delete.


Save a form as a report

1	Open the form in Design view.

2	On the View menu, click Toolbars.

3	Click Customize.

4	In the Customize Toolbars dialog box, click Form & Report Design in the Categories box.

5	Drag  [image]  to the toolbar, and click Close.

6	Click  [image]  on the toolbar.

7	Type a name for the report, and then click OK.

8	Press F11 to switch to the Database window.

9	Click the Report tab, and the double-click the report to open it in Print Preview.

The report has the same controls and property settings as the form.


New and improved wizards, builders, and add-ins

Microsoft Access for Windows 95 includes many new and improved wizards, builders, and add-ins that make it easy to create and maintain databases and database objects.

New wizards, builders, and add-ins

•	Database Wizard. Use the new Database Wizard to have Microsoft Access create your database for you. With the Database Wizard, you can pick from over 20 different databases. Microsoft Access includes databases that you can use for business or personal use. For example, you can create an Asset Tracking database or a Wine List database. To use the Database Wizard, click New on the File menu, and then double-click the icon for the database you want to create.

•	Table Analyzer Wizard. Want to take advantage of relational database capabilities in Microsoft Access but you don't know where to start? The Table Analyzer Wizard helps you figure out how to make your database more efficient by normalizing the data. Just click the table you want to analyze in the Database window, point to Analyze on the Tools menu, and then click Table. When you import text or spreadsheet data using one of the import wizards, Microsoft Access asks if you want to run the Table Analyzer Wizard after importing the data.

•	Lookup Wizard. Need help creating a list on a form or datasheet that looks up values from another table? When you use the Lookup Wizard, Microsoft Access walks you through the process of creating a lookup list. You can run the wizard from table Design view by clicking Lookup Wizard as the data type for a field, or you can click Lookup command on the Insert menu in table Datasheet view. Once you've created a Lookup field, whenever you drag that field to a form, Microsoft Access automatically creates a lookup list for that field. For more information, click  [image].

•	Import/Export Wizards. With the new import and export wizards, you can look at your data while you're importing or linking text or spreadsheet data or while you're exporting Microsoft Access data as text. The Import/Export Wizards help you select the correct field delimiters, data types, and so on. Microsoft Access automatically runs the Import Spreadsheet Wizard when you import or link text or spreadsheet data by clicking Get External Data on the File menu. Microsoft Access automatically runs the Text Export Wizard when you export data to an external file by clicking Save As/Export on the File menu.

•	Simple Query Wizard. Use the new Simple Query Wizard to have Microsoft Access create your queries for you. You can use this wizard to create single-table or multiple-table queries. You can also use the wizard to group and summarize your data. For example, you could have the wizard create a count of orders for you, organized by order date. To run the Simple Query Wizard, click the Query tab in the Database window, click New, and then double-click Simple Query Wizard.

•	Form and Report Wizards. With the new Form and Report Wizards, you don't have to create a query beforehand if you want to create a multiple-table form or report — the field picker in the wizard allows you to select fields from any table in your database. Microsoft Access analyzes the relationships between the data and presents you with the options. You can specify several different autoformats and background pictures for your forms and reports. To run the Form Wizard or Report Wizard, click the Forms tab or the Reports tab in the Database window, click New, and then double-click Form Wizard or Report Wizard.

•	Subform/Subreport Wizards and Builder. Microsoft Access includes three new tools to help you create subforms and subreports:

•	If you want to create a main form and subform or a main report and subreport from scratch, use the Form Wizard or the Report Wizard. Just specify the data that you want to include and Microsoft Access does the rest for you.

•	If you want to add a subform to an existing form, or a subreport to an existing report, you can use the new Subform/Subreport Wizard. In the toolbox, click  [image]  if it isn't already pressed in, click  [image], and then click the place where you want the subform or subreport to appear on your form or report.

•	If you've created your form and subform or report and subreport without using a wizard, but you're having trouble linking the forms or reports, use the new Subform/Subreport Field Linker. For more information, click  [image].

•	PivotTable Wizard. With the new PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and a calculation method you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data. For information on creating a PivotTable, click  [image].

•	Database Splitter Wizard. Use the Database Splitter Wizard to split a database into two files: one that contains the tables and one that contains the queries, forms, reports, macros, and modules. This way, users who need to access the data can customize their own forms, reports, and other objects while you maintain a single source of data on the network. To run the wizard, point to Add-ins on the Tools menu, and then click Database Splitter.

•	User-Level Security Wizard. Do you need the advantages and flexibility of user-level security but don't know where to start? Use the User-Level Security Wizard to get started. When you run the wizard on a database, the wizard creates a new database, exports copies of all of the objects from the original database, secures the object types by revoking all permissions of the Users group for those objects in the new database, and then encrypts the new database. After running the wizard, you can grant permissions to users and/or groups. For more information on running the wizard, click  [image].

•	Performance Analyzer. Want to make your database or application run faster? Using the Performance Analyzer, you can easily analyze any or all of the objects in your database. The Performance Analyzer makes suggestions and can even make certain changes for you if you want. To run the Performance Analyzer, point to Analyze on the Tools menu, and then click Performance.

•	Macro to Visual Basic for Applications Converter. Want to convert your macros to take advantage of the extra flexibility offered by Visual Basic? Just select the macro that you want to convert in the Database window, click Save As/Export on the File menu, click Save As Visual Basic Module, and then click OK. Or if you want to convert all the macros used in a particular form or report, in the Design view of that form or report, point to Macros on the Tools menu, and then click Convert Macros To Visual Basic.

•	Conflict Resolver. Using the Windows 95 Briefcase, you can work remotely with a replicated copy of a database and then merge changes back into a master database. The Conflict Resolver helps you manage conflicts that occur during synchronization. To run the Conflict Resolver, point to Replication on the Tools menu, and then click Resolve Conflicts.

Improved wizards, builders, and add-ins

•	Attachment Manager. The version 2.0 Attachment Manager is now called the Linked Table Manager. Use the Linked Table Manager to view or refresh links when the structure or location of  one or more linked tables has changed. With the new Linked Table Manager, you can easily switch between back-end databases. For more information on the Linked Table Manager, click  [image].

•	Menu Builder. You can now create custom shortcut menu bars by using the Menu Builder. For more information, click  [image].

•	Input Mask Wizard. With the improved Input Mask Wizard, you can customize the list of input masks directly from the wizard — you don't have to use the Add-in Manager. To run the Input Mask Wizard, click the Build button next to the InputMask property box in the property sheet.

•	Combo Box and List Box Wizards. You can now use these wizards to create an unbound list box or combo box that finds a record. To run the List Box or Combo Box wizard, in form Design view, make sure that  [image]  is pressed in, click  [image]  or  [image], and then click the place on the form where you want the list box or combo box to appear.

•	Mailing Label Wizard. The version 2.0 Mailing Label Wizard is now called the Label Wizard. With the improved wizard, it's much easier to create mailing labels. You can also create other types of labels besides mailing labels because the wizard provides templates for an assortment of labels. To run the Label Wizard, click the Reports tab in the Database window, click New, choose the table or query you want to use as the source for the report, and then double-click Label Wizard.

•	Chart Wizard. With the improved Chart Wizard, it's much easier to create great-looking charts for your forms and reports. For information on creating a chart, click  [image].


What's in the Microsoft Access Developer's Toolkit?

The Microsoft Access Developer's Toolkit is a separate Microsoft Access package that provides advanced tools that developers can use to create and distribute custom applications.

The Developer's Toolkit includes:

•	A royalty-free distribution license and tools (including the Microsoft Graph 5.0 run-time application) that allow you to distribute unlimited copies of your application.

•	The Microsoft Access Language Reference.

•	The Microsoft Office 95 Data Access Reference.

•	Documentation that includes information on developing run-time applications.

•	An enhanced Setup Wizard that you can use to automatically create disks and compress files for distributing applications. The Setup Wizard has integrated support for OLE custom controls and replication.

•	OLE custom controls. The Microsoft Access Developer's Toolkit includes three custom controls (spinner, data outline, and common dialog) that add versatility to your applications as well as several other custom controls, such as TabStrip and Rich Textbox controls, that you can use to duplicate Windows 95 interface elements and functionality.

•	Replication Manager. With Microsoft Access for Windows 95, you can replicate a database using the Replication commands on the Tools menu, using the drag and drop features of the Briefcase, or using data access objects (DAO) programming elements. With the Replication Manager, you can schedule updates between replicas, determine which objects in a database are replicated, see a visual display of all the replicas in a replica set, and manage more than one replica set at a time.

•	Windows 95 Help Compiler and documentation.

•	Windows API Viewer, which contains declarations and constants used with the Windows 95 application programming interface (API). You can copy and paste these declarations and constants into your Microsoft Access application.

To order the Microsoft Access Developer's Toolkit, see your local reseller, or contact Microsoft or your local Microsoft subsidiary.


Specify the default control type for a field

You can specify a default control type for Text, Number, and Yes/No fields. When you set the default control type for a field, Microsoft Access automatically creates that type of control whenever you add that field to a form or report. For Text and Number fields, the default control type can be a text box, list box, or combo box. For Yes/No fields, the default control type can be a check box, text box, or combo box.

1	Open the table that contains the field in Design view.

2	Click in the Data Type column for a Text, Number, or Yes/No field.

3	Click the Lookup tab in the lower portion of the screen.

4	In the DisplayControl property box, click a control type in the list.


Create a switchboard form using the Switchboard Manager

When you use the Database Wizard to create a database, the wizard creates a switchboard that makes it easy to navigate between the forms and reports in your database. If you want to build the same type of switchboard for a database you created yourself, you can use the Switchboard Manager.

1	On the Tools menu, point to Add-ins, and then click Switchboard Manager.

2	If Microsoft Access asks if you'd like to create a switchboard, click Yes.

3	In the Switchboard Manager dialog box, click Edit.

4	In the Edit Switchboard Page dialog box, type a name for the switchboard in the Switchboard Name box, and then click New.

5	In the Edit Switchboard Item dialog box, type the text for the first switchboard button, and then click a command in the Command box. For example, type Review Products, and then click Open Form In Edit Mode in the Command box.

Depending on which command you click, Microsoft Access displays another box below the Command box. Click an item in this box, if necessary. For example, if you click one of the form commands in the Command box, click the name of the form you want to open.

6	Click an item in the second box. For example if you clicked Open Form In Edit Mode in step 5, click Review Products in the Form box, and then click OK.

7	Repeat steps 4 through 6 until you've added all the items to the switchboard. If you want to edit or delete an item, click the item in the Items On This Switchboard box, and then click Edit or Delete. If you want to rearrange items, click the item in the box, and then click Move Up or Move Down.

8	Click Close.

Notes

•	You can use the Switchboard Manager to create a switchboard that branches to other switchboards. Use the above procedure to create one or more switchboards. To make a switchboard the default switchboard that's automatically opened when you open the database, click the switchboard name in the Switchboard Manager dialog box, and then click Make Default. To have a switchboard branch to another switchboard, choose the Go to Switchboard command in step 5 above, and then specify the switchboard you want to go to.

•	When you create a switchboard with the Switchboard Manager, Microsoft Access creates a Switchboard Items table that describes what the buttons on the form display and do. If you make changes to the Switchboard form later in form Design view, the application may no longer work. If you expect to customize your switchboard form extensively, it's better to create the form from scratch and then specify it as the startup form. For information on designing a startup form, see Chapter 1, "Creating an Application," in Building Applications with Microsoft Access for Windows 95.


Help couldn't return to the Help Topics dialog box

•	Click Help Topics on the button bar at the top of this window to return to the Help Topics dialog box.

If the Contents tab is missing from the Help Topics dialog box, copy the Msaccess.cnt file to the folder that contains your Microsoft Access files.


Use the Microsoft Network to get more information about Microsoft Access

If you have a Microsoft Network account on this computer, you can use the Microsoft Network command in Microsoft Access to get additional information about Microsoft products and services.

1	On the Help menu, click The Microsoft Network.

2	In the Microsoft Network window, click the forum that you want.

3	Click Connect.

Notes

•	If you don't have a Microsoft Network account, this procedure provides an opportunity to sign up for one.

•	If you don't have the Microsoft Network software installed on your computer, the Microsoft Network command is grayed.


Display or change the general properties of a database object

1	In the Database window, click the object whose properties you want to change.

2	Click  [image]  on the toolbar.

For Help on an item, click  [image]  at the top of the dialog box, and then click the item.

Note   The content of the Description field in the Properties dialog box is what is displayed under Description in the Database window when you click  [image]  on the toolbar.


Change the appearance of objects in the Database window

•	In the Database window, click one of the following buttons on the toolbar:  ,  [image],  [image], or  [image].

•	You can also sort the objects. On the View menu, point to Arrange Icons, and sort By Name, By Type, By Created, and By Modified.

Note   To see a description of what each menu command does, rest your pointer over it; information about the command appears in the status bar at the bottom of the window. If the status bar is not displayed, on the Tools menu, click Options, click the View tab, and then select the Status Bar check box.


Microsoft Access accessibility

Microsoft Access contains features that make the product more accessible.

What do you want to do?

Make the toolbar buttons larger

Change the spacing between toolbar buttons

Create a custom toolbar

Create custom colors for a section or control on a form or report

Change the background color of a control or section

Insert repeated entries in a column quickly

Add an AutoCorrect entry while checking spelling

Enter and edit data by using the keyboard

Use shortcut keys

Navigate in Datasheet view by using the keyboard

Navigate in Form view by using the keyboard


Update a table based on values in another table

1	Create an update query that contains the table you want to update and the table whose values you want to copy. For information about how to create an update query, click  [image].

2	If the tables aren't already joined, join them on the fields that have related information. For information on creating joins, click  [image].

For example, if you want to copy data from the ProductName field in the Products table to a field in another table, join the two tables on the primary key, which might be called ProductID.

3	In the Update To cell for the fields you want to update, type an expression with the following syntax:

[tablename].[fieldname]

where tablename and fieldname are the names of the table and field that contain the data you're copying. For example, if you are copying data from the ProductName field in the Products table, you would type [Products].[ProductName] in the Update To cell.


Rearrange columns in Datasheet view by using the keyboard

1	Move the insertion point to a field in the column you want to move.

2	If the entire field is not already highlighted, press F2.

3	To select the entire column, press CTRL+SPACEBAR.

4	To turn on Move mode, press CTRL+F8.

5	To move the column to the right, press the RIGHT ARROW key.

To move the column to the left, press the LEFT ARROW key.

6	To turn off Move mode, press ESC.


Add the Chart button to a toolbar

1	Switch to the appropriate view, and make sure the toolbar you want to put the Chart button on is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	In the Categories box, click Toolbox.

5	From the Buttons box, drag the  [image]  button to the toolbar on which you want it to appear.

6	In the Customize Toolbars dialog box, click Close.


The people who brought you Microsoft Access Help


 Share a database on a network

If your computer is connected to a network, you and others can work with one database at the same time.

There are two ways you can share data in a multiuser environment:

•	Put the entire database on a network server or in a shared folder.

•	Put only the tables on a network server, and keep other database objects on users' computers.

The first method provides these advantages:

•	It's the easiest method to implement.

•	Everyone shares the data and uses the same forms, reports, queries, macros, and modules. This strategy makes it easier to provide a standard set of database objects for all users, which is appropriate if you want all users to use the database the same way or if you can't afford to support users as they create their own objects.

The second provides these advantages:

•	The database's performance is faster because only data is sent across the network.

•	Users can customize their forms, reports, and other objects for their individual needs and preferences.

•	Users can change these objects without affecting other users.

You can separate the tables from the other database objects by using the Database Splitter Wizard.

If you use two computers, such as an office computer and a portable computer, you can use Microsoft Windows Briefcase to make replicas of your Microsoft Access database and to keep those replicas synchronized. Also, users at different locations can all work on their own copies at the same time, and then synchronize them to make sure they are the same.

If you need to restrict access to your database or access to objects in the database, you can secure your database. Microsoft Access provides two security methods: passwords and user-level security.

Also, if you work in a client/server environment, you can take advantage of the extra power and security it provides by creating a client/server application. For more information, see Chapter 18, "Developing Client/Server Applications," in Building Applications with Microsoft Access 95.

What do you want to do?

Share a database on a network server

Share a database when I don't have a network server

Split a database between its interface and its tables

Read about using Briefcase to replicate a database

Read about methods to secure a database


Share a database on a network server

1	Set up a shared folder on a network server. You might need assistance from your network administrator.

2	Copy the database to the network server.

3	Make sure the database is set to open in shared mode, which is the default setting.

How?

Note   Each computer on the network must have its own copy of the Microsoft Access executable file, as permitted by your Microsoft Access license agreement.


Share a database when a network server doesn't exist

1	Copy the database to a shared folder. For information on sharing folders, search the Microsoft Windows Help Index for "folders, sharing."

2	Make sure the database is set to open in shared mode, which is the default setting.

How?

Note   Each computer on the network must have its own copy of the Microsoft Access executable file, as permitted by your Microsoft Access license agreement.


Split an existing database between its data and its objects

This procedure splits a database into two files: one that contains the tables and one that contains the queries, forms, reports, macros, and modules. This way, users who need to access the data can customize their own forms, reports, and other objects while maintaining a single source of data on the network.

1	On the Tools menu, point to Add-ins, and then click Database Splitter.

2	Follow the instructions in the Database Splitter Wizard dialog boxes.


Editing data in a multiuser environment

In a multiuser environment, more than one person might be working with the same records at the same time. Since other people can change or even delete the same data you're trying to edit, you might occasionally conflict with others as they work.

Microsoft Access helps you keep track of the status of records as you edit them, and makes sure you're using the latest data. When two or more people try to edit the same record, Microsoft Access displays messages that help you resolve conflicts. For example, if you try to save a record that another user has locked, Microsoft Access displays the name of the person who locked that record.

To help you keep track of the status of records, Microsoft Access displays the following symbols in the current record selector.

Symbol	Meaning
	This record is the current record and hasn't been edited.
	You have edited this record, but you haven't saved your changes yet. As long as this symbol is displayed, other users can't see the changes you've made to the record, and they won't be able to edit the record, if you have the record locked. To free the record for use by others, either save or undo your changes.
	This record is locked by another user. You can't edit it. If you try to type in a locked record, Microsoft Access sounds a beep.
For information on choosing a record-locking strategy, click  [image].


Choosing a record-locking strategy in a multiuser environment

When you edit a record, Microsoft Access can automatically prevent other users from changing the record before you have finished editing it.

Giving one user exclusive access to a record is called locking. There are three locking strategies to choose from:

•	No Locks — Microsoft Access does not lock the record you're editing. When you try to save changes to a record that another person has also changed, Microsoft Access displays a message giving you the options of overwriting the other user's changes to the record, copying your version of the record to the Clipboard, or discarding your changes. This strategy ensures that records can always be edited, but it can create editing conflicts between users.

•	Edited Records — Microsoft Access locks the record you're editing, so no other user can change it. It might also lock other records that are stored nearby on your disk. If another user tries to edit a record that you've locked, Microsoft Access displays  [image]  in the other user's datasheet. This strategy ensures that you can always finish making changes that you start. It is a good choice if you don't have editing conflicts often.

•	All Records — Microsoft Access locks all records in the form or datasheet (and underlying tables) you're editing for the entire time you have it open, so no one else can edit or lock the records. This strategy is very restrictive, so choose it only when you know you're the only person who needs to edit records at any one time.

For information on specifying one of these options, click  [image].

Note   When you edit data in a linked SQL database table using ODBC, Microsoft Access doesn't lock records; instead, the rules of that SQL database govern locking. In this instance, regardless of the record-locking setting you choose for your database, Microsoft Access always appears as though the No Locks setting has been selected.


Specify whether a database opens in shared or exclusive mode by default

This procedure affects the way a database is opened only on your computer. It does not affect the default for users on other computers.

1	On the Tools menu, click Options.

2	Click the Advanced tab.

3	If you want others to be able to open the database at the same time you have it open, click Shared.

If you want sole access to the database when you have it open, click Exclusive.

Notes

•	When you open a database in a multiuser environment, you can open it in exclusive and/or read-only mode, even if you specify shared mode by default. For more information, click  [image].

•	If you set up security in your multiuser environment, you can ensure that users don't open a database exclusively by denying them Open Exclusive permission for the database. For more information on removing permissions, click  [image].


Specify the default type of record locking used in a multiuser environment

1	On the Tools menu, click Options.

2	Click the Advanced tab.

3	In the Default Record Locking box, click the option you want.

For information on these options, click  [image].


Avoiding data-locking conflicts in a multiuser environment

There are four settings that help you avoid data-locking conflicts with other users in a multiuser environment:

•	Refresh Interval — sets the number of seconds after which Microsoft Access automatically updates records in Datasheet or Form view. Valid values are 1 through 32,766 seconds. When you refresh the current datasheet or form, Microsoft Access doesn't reorder records, add new records, or remove deleted records. To view these changes, you must requery the underlying records for the datasheet or form.

•	Update Retry Interval — sets the number of milliseconds after which Microsoft Access automatically tries to save a changed record that is locked by another user. Valid values are 0 through 1,000 milliseconds.

•	Number of Update Retries — sets the number of times Microsoft Access tries to save a changed record that is locked by another user. Valid values are 0 through 10.

•	ODBC Refresh Interval — sets the interval after which Microsoft Access automatically refreshes records that you're accessing using ODBC. Valid values are 1 through 32,766 seconds.

For information on specifying one of these options, click  [image].


Specify multiuser/ODBC update retry and refresh interval settings

1	On the Tools menu, click Options.

2	Click the Advanced tab.

3	Type values in the boxes for the options you want to change.

For information on these options, click  [image].


Tips for editing database objects in a multiuser environment

•	Although you can design a database while others use it, it's a good idea to design most objects before you allow other users to open the database for shared access. When you want to make extensive design changes, you can ensure that you're the only one using the database by selecting the Exclusive option in the Open Database dialog box when you open the database.

•	If another user has a table open or is viewing data in queries, forms, or reports based on the table, you can't make any changes to the table's design. Microsoft Access informs you that it is read-only.

•	Because no one can view data in a table that another user has open in Design view, keep a table open in Design view only as long as necessary if others need to use the table or any queries, forms, or reports based on the table.

•	If objects are dependent on one another, update all of them at the same time so that other users don't open inconsistent versions of the objects. For example, if you want to add fields to a form, make sure to add the fields to the underlying query before you update the form.

•	If you change a query, form, or report that another user has open, that user must close and reopen the changed object to use the latest version. With Visual Basic for applications modules, other users can't run the updated Function or Sub procedures until they close and reopen the database.

•	If you save changes to a macro while another user is running it, you can cause errors to occur in the user's macro. To prevent this, open the database for exclusive access before making changes to a macro.


Troubleshoot problems viewing data or objects in a multiuser environment

What do you need help with?

Why can't I change the table's design?

Why can't I view data in a table?

Why can't I open a database object?


Why can't I change the table's design?

•	If another user has a table open or is viewing data in queries, forms, or reports based on the table, you can't make any changes to the table's design. Microsoft Access informs you that it is read-only.

•	You might not have permission to change the design. If your shared database is secured, access to objects is controlled by the people who create or administer it. Your permissions might be determined by the group you are in.


Why can't I view data in a table?

•	You can't view data in a table that another user has open in Design view. Wait until the table is available. When you open a table in Design view, keep it open only as long as necessary if others need to use the table or any queries, forms, or reports based on the table.

•	You might not have permission to view the data. If your shared database is secured, access to objects is controlled by the people who create or administer it. Your permissions might be determined by the group you are in.


Why can't I open a database object?

You might not have permission to open the object. If your shared database is secured, access to objects is controlled by the people who create or administer it. You might have permission to view an object but not to see it Design view or to update it. Also, your permissions might be determined by the group you are in.


Sending feedback on user assistance

The Answer Wizard senses that your question hasn't been answered to your satisfaction. In creating the Answer Wizard, our goal is to provide you with the assistance you need, when you need it. If the Answer Wizard hasn't answered a question satisfactorily, please let us know. Your feedback can help us refine future versions.

You can send feedback via electronic mail to:

•	offc95ua@microsoft.com

Or you can send a letter to:

•	Office UA Feedback
Microsoft Corporation
1 Microsoft Way
Redmond, WA   98052
USA

Tell us the question(s) you asked. Tell us what didn't work. The more details you provide, the better we can make adjustments in the future. We look forward to hearing from you!

The Microsoft Office User Assistance Team


Where the Answer Wizard wants to go

The Answer Wizard wants to go wherever you want to go. If you need help, ask the Answer Wizard about the task you're working on. The Answer Wizard can take you right to the tools you need and describe how to use them once you get there.


Make my computer smile

1	Type a colon, and then type a right parenthesis.

:)

2	Repeat until the desired level of machine happiness is achieved.


Entries in the File Name box

In the File Name box in the Open dialog box (File menu), you can do any of the following to locate your file:

•	You can type partial filenames. For example, type region to find all files with names that include "region."

•	You can type filename extensions. For example, type *.mdb to find Microsoft Access database files. (This works only if you haven't set the Windows option to hide the MS-DOS file extension.)

•	You can use wildcard characters: use an asterisk (*) to match any number of characters, or use a question mark (?) to match any single character. For example, to find only filenames that end with "region," type *region; or type gr?y to find instances of both "gray" and "grey" in filenames.

•	You can include the full pathname — for example, c:\Hobbies\Book Collection. When you include a drive letter, share, or folder, the application automatically updates the location in the Look In box and displays only the name of the file in the File Name box.

•	You can search more than one folder at a time by typing multiple paths. Separate each path with a list separator character; usually this is a semicolon (;) — for example, type c:\Book Collection;c:\Inventory for 1993. To search all subfolders, click  [image]  and then click Search Subfolders.

•	To reuse a recent entry, you can click its name in the File Name box.


Sort a list of files in the Open dialog box.
Sort a list of files in the Open dialog box

1	On the File menu, click Open database.

2	Click  [image].

3	Click Sorting.

4	Specify how you want to sort the files.


Change saved search criteria in the Advanced Find dialog box

1	On the File menu, click Open Database.

2	Click Advanced.

3	In the Advanced Find dialog box, click Open Search.

4	Click the name of the saved search, and then click Open.

A box that lists the search criteria appears at the top of the Advanced Find dialog box.

5	Click the criterion you want to change, and then click Delete.

The criterion's settings appear in the Define More Criteria box. If you change your mind, you can click Add To List to restore the search criterion you just deleted.

To clear all criteria and use the default values in a search, click New Search.

6	Under Define More Criteria, specify the new criteria.

7	Click Add To List.

8	Click Save Search, type the name of the saved search, and then click OK.

9	Click Yes to replace the existing saved search.

To assign a new name to the modified search criteria, type a new name, and then click OK.

10	To start the search, click Find Now.


Troubleshoot finding files

If the file you need isn't listed in the Open dialog box:

•	Type the name of the file in the File Name box, and then click Find Now.

•	Make sure that you have the correct file format selected in the Files Of Type box.

•	Make sure that the entries in the Text Or Property box and the Last Modified box are appropriate for the files you’re searching for. To clear all current criteria except the file location and the default file type, click New Search.

•	Make sure that you’re looking on the correct drive and in the correct folder.

•	If you don't know the folder name, you can search all the folders on the specified drive. Click  [image]  and then click Search Subfolders.

•	You can search multiple paths by typing them in the File Name box. Separate each path with a list separator character—usually a semicolon; for example, type c:\Book Collection;c:\Inventory for 1993 in this box. To search all subfolders, click  [image]  and then click Search Subfolders.

•	If you’re looking for a file on a network computer and the drive doesn’t appear in the Look In box, click  [image]  and then click Map Network Drive. In the Drive box, click the drive letter you want to use to connect to the network computer, enter its path in the Path box, and then click OK.

•	The file may be hidden. To display all files — including file types such as *.dll and *.sys — click the Windows Start button, point to Programs, and then click Windows Explorer. Click Options on the View menu, and then click Show All Files on the View tab.


What's new about the Database window?

The redesigned Database window in Microsoft Access for Windows 95 provides a variety of options for viewing and manipulating database objects.

•	Quickly Switch Between Objects. You can switch between object types by using tabs across the top of the window.

•	Use Different List Types for Your Objects. You can list objects using large or small icons, or list them by name or by name and details. The details are the object's properties: object description, date modified, date created, object type, and owner. Each detail appears in a separate column that you can resize to hide or show more of that information. You can also display objects in a different order by sorting them.

•	Easily Hide Objects. You can hide objects that you don’t want others to see; for example, you might want to hide subform objects.

•	Drag Objects to Create Desktop Shortcuts. You can drag a table, query, form, report, or macro to the desktop to create a shortcut for opening that object.

•	Drag and Drop Data Between Applications. You can drag and drop tables and queries from the Database window to other applications, such as Microsoft Excel or Microsoft Word.

•	Create New Tables by Using Drag and Drop. You can drag and drop Microsoft Excel spreadsheet cells to the Database window to create new tables.

•	Rename Objects in Place. You can rename an object by clicking on its name and then clicking again to edit it.


What's new about working with data?

Microsoft Access for Windows 95 adds the following new features to make working with data even easier.

•	Create Tables in Datasheet View. You can create a table by entering data directly into a blank datasheet. After you save the new datasheet, Microsoft Access analyzes your data and automatically assigns the appropriate data type and format for each field.

•	Drag and Drop or Output Data to Other Applications. You can select data in a form or datasheet and drag and drop to Microsoft Word or Microsoft Excel. You can also select data from a form or datasheet and save it as text, as Rich Text Format (which can be opened by Microsoft Word and most Windows word processors and desktop publishing programs), or as a Microsoft Excel worksheet.

•	Check Spelling and Automatically Correct Typing Errors. You can check the spelling of all Text or Memo fields or selected entries in datasheets and forms. You can also have Microsoft Access automatically correct your common spelling and typing errors as you type, and automatically capitalize the names of the days of the week.

•	Filter in Datasheets or Forms. You can filter records easily using Filter By Selection or Filter By Form.

•	Sort subforms. You can now sort records in a subform.

•	Redesign Tables in Datasheet View. You can insert or delete fields (columns) in Datasheet view.

•	Format Datasheets. You can change a datasheet's characteristics by:

•	Displaying cells that look raised or sunken, changing the color of grid lines, showing only horizontal or vertical grid lines, or both.

•	Displaying data in a different font color and style.

•	Animating rows so that you can watch them slide up and fill the slot of a deleted record. This is the default, although you can turn animation off if you want.

•	Inserting a Lookup field directly by using the Lookup Wizard.

•	Renaming a field in Datasheet view.

•	Use Briefcase Replication to Synchronize Multiple Copies of Your Database. Through replication, multiple users in different locations can work on their own copies of a database and then synchronize the common data in all the replicas.


What's new about securing and administering a database?

Many new features make it easier to secure and administer databases using Microsoft Access for Windows 95.

•	Use One Password to Protect Your Database. You can assign a single password to control who can open a database instead of or in addition to implementing user-level security.

•	New User-Level Security Wizard Makes It Easier to Secure Your Database.

•	Hide Objects in the Database Window. You can hide database objects that you don't want other users to see or open in the Database window.

•	Easily Change Workgroup Information on Startup. You can change to a different workgroup information file when starting Microsoft Access by using the new command-line option /Wrkgrp workgroup information file. You can use this parameter with the Run command on the Windows Start menu or in the Target box of a shortcut.


What's new with printing and previewing?

Microsoft Access for Windows 95 offers the following enhancements for printing and previewing database objects:

•	New User Interface. Some menus and dialog boxes have been redesigned to make them easier to use and to match those used in other Microsoft Windows 95 applications.

•	The Print dialog box is the same as the one used by other Windows 95 applications.

•	The Print Setup command on the File menu is now called Page Setup.

•	  on the toolbar prints the selected object without displaying the Print dialog box.

•	In report Design view, the Sample Preview command is now called Layout Preview and is available on the View menu and by clicking the arrow next to the View button on the toolbar.

•	The Print Definition command is now called the Documentor command and is available by pointing to the Analyze command on the Tools menu.

•	Preview Multiple Pages. The Pages command on the View menu lets you view up to 12 pages at a time.

•	Expanded Previewing Options. New buttons on the Print Preview toolbar increase the options for previewing objects:

•	  displays one full page.

•	  displays two full pages.

•	The Zoom Control box lists zoom percentages at which you can view the object.


What's new about working with other applications?

Microsoft Access for Windows 95 provides many new features for working with other products.

•	Retain Text Formatting. When you copy or cut data from Microsoft Access forms and datasheets, the settings for font, alignment, and number formatting for column headings and data are retained when you paste them into Microsoft Excel spreadsheets.

•	Output Subreports to Other File Formats. When you output a report with a subreport to a .txt, .rtf, or .xls file format, the subreport is output along with the main report.

•	Format and Print Microsoft Excel Data in Microsoft Access Reports. When you need the grouping and formatting functionality of Microsoft Access reports for data you have in a Microsoft Excel spreadsheet, you can click Access Report on the Data menu in Microsoft Excel to start the Microsoft Access Report Wizard. For details, see the Help provided with Microsoft Excel.

•	Enter Microsoft Excel Data Using a Microsoft Access Form. When you want to enter data in a Microsoft Excel spreadsheet using a form that has complex formatting, check boxes, list boxes, and text boxes with specific data types, you can click Access Form on the Data menu in Microsoft Excel to start the Microsoft Access Form Wizard. For details, see the Help provided with Microsoft Excel.

•	Permanently Move Microsoft Excel Data into Microsoft Access. When a Microsoft Excel spreadsheet is no longer the appropriate tool for your data, you can create a Microsoft Access database from the spreadsheet by clicking Convert To Access on the Data menu in Microsoft Excel. For details, see the Help provided with Microsoft Excel.

•	Create a PivotTable Control in a Microsoft Access Form. Using the PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and calculation method you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data. (To take advantage of this wizard, you need to have Microsoft Excel installed.)

•	Link a Spreadsheet. You can link data from a Microsoft Excel or a Lotus 1-2-3 spreadsheet as long as the data is arranged in an appropriate tabular format.

•	Use Microsoft Access as an OLE Automation Server. When you use Microsoft Access as an OLE Automation Server, you can manipulate Microsoft Access objects from another application, such as Microsoft Excel.

•	Drag and Drop Database Objects. The following drag-and-drop functionality is now available in Microsoft Access:

•	You can drag and drop database objects between open Microsoft Access databases. (You must have two instances of Microsoft Access running.)

•	You can drag and drop Microsoft Access tables and queries into other applications, such as Microsoft Word and Microsoft Excel.

•	You can create a table by dragging and dropping a range of cells from a Microsoft Excel spreadsheet into the Database window.

•	You can drag and drop OLE objects into an OLE Object field in a form in Form view or into a form or report in Design view.


What's new with table design?

Microsoft Access for Windows 95 provides many new features to make designing tables easier and to make the tables more powerful:

•	Create Lookup Lists with the New Lookup Wizard. Use the Lookup Wizard to create a Lookup field that displays a list of values (either in a list box or combo box) looked up from another table. You can also use the Lookup Wizard in a table to create a field that displays a list of values you define. Adding this Lookup field to a form by dragging it from the field list automatically creates a list box or combo box with the same properties. Lookup field list boxes or combo boxes are also automatically added to any query that includes that field.

•	Create Tables from Datasheet View. Create a table by entering data in a blank datasheet — much like adding data to a spreadsheet. When you save the new datasheet, Microsoft Access evaluates the data you entered and automatically creates appropriate field types and formats for you. Also, you can add, insert, and rename columns (fields) to any table in Datasheet view at any time.

•	Improve Table Design with the New Table Analyzer Wizard. Use the Table Analyzer to split a large table into two or more smaller tables so that you can store data more efficiently. This is particularly useful if you are importing data from a large flat-file database such as a spreadsheet and want to take advantage of Microsoft Access relational database features.

•	Modify a Table's Design While Setting Relationships. Change a table's design from the Relationships window, for example, to define a primary key or add additional fields.

•	Link Text Files and Spreadsheets. Link (attach) data from delimited and fixed-width text files, and spreadsheets.


What's new with database design?

Microsoft Access for Windows 95 adds the following new features to make designing and using a database easier and make your databases more powerful:

•	Create Databases with the New Database Wizard. Use the Database Wizard to quickly create an entire database from one of many database templates.

•	Optimize Your Database's Performance. Use the Performance Analyzer to optimize the performance of all or selected objects in your database. The Performance Analyzer will automatically make some changes for you, and will provide suggestions and considerations for other improvements you can make yourself.

•	Save Network Overhead with the New Database Splitter Wizard. Use the Database Splitter Wizard to split a database into a back end containing the data (tables) and a front end containing all other objects and links to the tables in the back end. This is useful when sharing a database on a network. The back end (data) then resides in a shared folder, and users run copies of the front end from their own computers. This creates less network overhead than running the entire database from a shared folder.

•	Set Properties for Your Database. View, change, and define database properties. For example, you can view or change summary information (such as a title, subject, or author), or you can view statistics (such as the creation date, the name of the last user to access the database, or total editing time) or a list of all objects in a database. You can also define your own database properties that identify characteristics of the database, which you can search for if you don't remember the filename.

•	Easily Customize Your Database. Create a customized application easily using the new Startup properties to specify whether a specific form displays automatically whenever a database is opened or control whether custom or built-in menus, the Database window, or Status bar are displayed.


What's new with form and report design?

Microsoft Access for Windows 95 provides many new features to make it faster and easier to create great-looking forms and reports.

Creating and Formatting Forms and Reports

•	New Form and Report Wizards. Want to create a multiple-table form or report, but don't want to create a query? With the new Form and Report Wizards, you don't have to create a query beforehand — the field picker in the wizard allows you to select fields from any table in your database. With the new Form Wizard, it's easy to create a form with a subform or link a form to another form. You can even create a form that includes two subforms. You just specify the data that you want and Microsoft Access presents you with the options. Likewise, with the new Report Wizard, it's easy to create reports that group or total data. Just tell the wizard what you want to do and let it do the rest.

•	New Subform/Subreport Wizard. If you want to add a subform to an existing form, or a subreport to an existing report, you can use the new Subform/Subreport Wizard. Just click  [image]  in the toolbox, click your form or report, and away you go. (You can also launch the wizard by dragging a form or report from the Database window to a form or report that's open in Design view.) Or if you're having trouble linking a main form and a subform, or a main report and subreport, use the new Subform/Subreport Field Linker.

•	Inherited Filters. Want to create a form or report from a table or query you've already filtered? With the filtered records displayed, just click the New Object button on the toolbar, and then click one of the form or report options. The new form or report uses the table or query as its record source and inherits the filter.

•	AutoFormat. Don't like the look of your form or report? Change it quickly by clicking the AutoFormat button. When you click  [image], Microsoft Access provides you with a variety of predefined formats to choose from. You can use the AutoFormat button to change the look of your whole form or report or just selected controls. You can also customize the predefined formats or create your own.

•	Background Pictures. Want to add a logo or other picture to the background of your form or report? Just enter a path in the Picture property box for the form or report, or select a picture using the Picture Builder. With Microsoft Access 95, you can also make more controls transparent so your background pictures show through.

•	Formatting Toolbar. The new Formatting toolbar puts many formatting tasks at your fingertips. For example, you can add a background color to a section or apply a special effect to a control with just a few clicks of the mouse.

•	Grouping Records on Reports. When you print a grouped report, the detail records for a group might continue onto another page or column. You can specify whether you want the records in groups kept together by page or by column by using the report's GrpKeepTogether property. You can also repeat a group header at the top of the next page or column by setting the group header's RepeatSection property to Yes.

Creating and Formatting Controls

•	Default Controls for Fields. You can use the new DisplayControl table or query property to specify a default type of control (text box, check box, list box, or combo box) for a field. When you drag that field from the field list, or if you use a wizard to create a form or report, Microsoft Access automatically creates the right type of control.

•	New Lookup Wizard. Need help creating a list on a form that looks up values from another table? Use the new Lookup Wizard. You can run the wizard in table Design view by specifying Lookup Wizard as the data type for the field. Or you can click Lookup Column on the Insert menu in Datasheet view. When you run the wizard, Microsoft Access walks you through the process of creating a lookup list. When you add that field to a form, Microsoft Access automatically creates a list box or combo box (depending on which control you select in the wizard) with the appropriate properties set for you.

•	Improved List Box and Combo Box Wizards. If you want to create a list box or combo box that finds a record, it's easy to do with the improved List Box and Combo Box Wizards. In form Design view, make sure  [image]  is pressed in in the toolbox, click  [image]  or  [image], and then click the location on your form where you want to place the list box or combo box.

•	Change Controls Dynamically. Want to change a text box to a combo box? Or maybe you want to change a check box to an option button? You don't need to delete the control and start over—just click Change To on the Format menu, and click the type of control you want to change it to. Microsoft Access copies the appropriate properties from one control to the other so you don't have to specify them again.

•	Format Painter. Want to copy formatting characteristics from one control to another? Just click the control you want to copy formatting characteristics from, click  [image]  on the toolbar, and then click the control you want to copy them to.

•	ScreenTips. Want to create a custom tip on a form that pops up when you place the mouse pointer over a control? Just enter the message you want to display in the ControlTipText property box for the control. Or you might want to create a custom tip that pops up when you click  [image]  and then click a form, report, or control.

•	New Special Effects. Create great-looking Windows 95 forms and reports with the new settings for the SpecialEffect property. With Microsoft Access 95, you can create etched, shadowed, or chiseled effects in addition to the version 2.0 special effects (flat, raised, and sunken).

•	Page Number or Date/Time Controls. Want to add a control to display a page number or a date? Just click the Page Number command or the Date And Time Command on the Insert menu and specify the options you want.

•	New PivotTable Wizard. With the new PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and calculation method that you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data. (To take advantage of this wizard, you need to have Microsoft Excel installed.)

•	Improved Chart Wizard. With the improved Chart Wizard, it's much easier to create a chart for a form or report.

•	Drag and Drop Objects. With Microsoft Access 95, you can drag OLE objects to Form view to add a bound object or to form Design view or report Design view to add an unbound object. (The object application you're dragging from must have support for drag and drop.) You can also drag a query or table datasheet from the Database window to a form or report to create a subform or subreport displayed in Datasheet view.

•	Custom Controls. It's easy to add custom controls to your forms and reports with Microsoft Access 95. Just click Custom Controls on the Insert menu, and then click the control you want to insert.

Performance

•	New Image Control. If you want to display unbound pictures on your forms and reports, use an image control. Just click  [image]  in the toolbox, and click the location on the form or report where you want to place the picture. Image controls display pictures much faster than unbound object frames do. However, you can't double-click the picture to edit it if you use an image control.

•	Faster Combo Boxes. You'll notice that combo boxes on forms in Microsoft Access 95 work faster than combo boxes in version 2.0.

•	Faster Report Previewing. Previewing reports is faster because events are triggered only the first time you page through a report.

•	Performance Analyzer. Have Microsoft Access analyze your form's or report's objects (or any other objects) to make sure they're as fast as they can be. To run the Performance Analyzer, point to Analyze on the Tools menu, and then click Performance.


What's new with filters?

Microsoft Access for Windows 95 makes filtering even easier with the following new ways to filter records:

•	With Filter By Selection, you can specify which set of records you want to work with by selecting (highlighting) directly in the form or datasheet the value you're searching for, and then clicking  [image]  on the toolbar. Once you've narrowed the focus to a specific set of records, you can narrow it even further by selecting another value from within the subset of records.

•	With Filter By Form, you can specify which set of records you want to work with by switching to a view of your form or datasheet with blank fields (instead of data) into which you can specify the value or values you're searching for. You specify a value you're searching for by typing it or picking it from a list in the field.

After creating a filter using one of these methods, you can save the filter as a query if you want, bypassing the query design grid altogether.

Note   You can still create advanced filters in the Advanced Filter/Sort window using the design grid, formerly called the Query By Example (QBE) grid.

In addition, you can now do the following with filters:

•	Filter records in the Datasheet view of a table or query.

•	Base a new form or report on filtered data. After applying a filter to a table or query, you can display just the filtered records in a form or report. For example, you can quickly create mailing labels from the filtered records by clicking the arrow next to the New Object button on the toolbar, clicking New Report, and then selecting Mailing Label.

•	Save a filter with a table, query, or form. Previously you had to save a filter as a query to reuse it at a later time. If you base a new form or report on a closed table or query that has a filter saved with it, the form or report will inherit the filter, which you can then apply as needed.

Note   A saved filter doesn't become a separate object in the Database window.

•	Save a sort order you've applied to the filtered records in a table, query, or form. If you sort the records in ascending or descending order, Microsoft Access saves the sort order when you save the object and its filter. If you base a new form or report on the filtered and sorted data, the records in the form or report will be sorted automatically. You can remove the sort order or reapply it as needed.

Note   If you sort the records in a table, query, or form that doesn't have a filter, Microsoft Access still saves the sort order. If you base a new form or report on a table or query in this case, the form or report inherits the sort order and applies it automatically.

•	Apply, remove, or change a filter and sort order that a report inherits by setting the new Filter, FilterOn, OrderBy, and OrderByOn properties.

•	Apply a filter to a subform. The filter limits records in the subform without limiting records in the main form.

•	Apply a filter automatically when a form is first opened by specifying a macro using the ApplyFilter action or an event procedure using the ApplyFilter method of the DoCmd object as the OnOpen property setting of the form. You can also apply a filter using the OpenForm or OpenReport action, or their corresponding methods. To apply a filter automatically when a table is first opened, open the table using a macro containing the OpenTable action, immediately followed by an ApplyFilter action.

•	Affect what happens on a form in response to someone creating or applying a filter. This is possible using the new OnFilter event and OnApplyFilter event.

•	Create a custom Filter By Form or add or modify expressions entered into a Filter By Form window using the BuildCriteria method in code. For example, you could use the BuildCriteria method to add criteria in addition to any criteria specified in the Filter By Form window.


What's new with macros, modules, and developing applications?

Microsoft Access for Windows 95 provides many new features to make it easier to use macros and Visual Basic for applications modules, and to create powerful database applications.

New macro action and custom menu features

•	Save action. You can automate saving a database object by carrying out the new Save action in a macro or Visual Basic procedure.

•	Custom shortcut menus. You can create your own custom shortcut menus by clicking the Build button next to the new ShortcutMenuBar property.

•	Make custom menu commands appear dimmed or selected. You can dim (gray out) or select (check) the custom menu commands a user sees while working with a database by carrying out the SetMenuItem action in a macro or Visual Basic procedure.

Improved development environment and tools

•	Improved Module window. The Module window is easier to use than ever before, and includes color-coded syntax to help make your code easier to read. For more information, see Chapter 2, "Introducing Visual Basic," in Building Applications with Microsoft Access for Windows 95.

•	Better debugging tools. The Debug window combines an Immediate pane, where you can type commands and send information, with a Watch pane, where you can view the value of variables and controls. For more information, see Chapter 7, "Debugging Visual Basic Code," in Building Applications.

•	Object Browser. The Object Browser helps you navigate between the objects in your system and take advantage of all the objects, functions, and constants available to you. For more information, see Chapter 5, "Working with Objects and Collections," in Building Applications.

•	References command. Use the References command to make Visual Basic procedures available in more than one database. You can store common procedures in separate databases and then make them available to the current database without restarting Microsoft Access. For more information, see Chapter 12, "Using Library Databases and Dynamic-Link Libraries," in Building Applications.

•	Startup command. Using the Startup command, you can quickly specify your application's startup form, title-bar text, icon, menu, and toolbar. You use this same interface to make customization options unavailable to your users when you deliver your completed application. For more information, see Chapter 1, "Creating an Application," and Chapter 14, "Securing and Delivering Your Application," in Building Applications.

Improved programming language features

•	Object-oriented language framework. You can now declare procedures and variables as Public in form and report modules, making them available to other modules in your application. For more information, see Chapter 2, "Introducing Visual Basic," and Chapter 4, "Variables, Constants, and Data Types," in Building Applications.

•	Object creation syntax. For creating new objects, such as forms or reports, Visual Basic adds the New keyword. Using New, you can open more than one instance of the same form at a time. For more information, see Chapter 5, "Working with Objects and Collections," in Building Applications.

•	Flexible parameters for procedures. Using the Optional keyword, you can declare a procedure with optional parameters. Or, using the ParamArray keyword, you can work with a variable number of parameters. Also, when calling a procedure, you can specify parameters by name, making your code more readable and allowing you to pass parameters in any order you like. For more information, see Chapter 2, "Introducing Visual Basic," in Building Applications.

•	Conditional compilation. Using the #If...Then and #EndIf statements, you can specify code that you want Microsoft Access to include or ignore in your application. This is especially useful as a debugging technique. For more information, see Chapter 7, "Debugging Visual Basic Code," in Building Applications.

•	Faster performance. Because Visual Basic loads only the code you need and performs many operations more quickly than before, your applications load and run faster. For information on taking advantage of these improvements and increasing performance in other ways, see Chapter 13, "Optimizing Your Application," in Building Applications.

•	New data types and statements. Visual Basic includes two new data types, Boolean and Byte. Visual Basic also has more powerful user-defined types, which can include objects and allow you to use the ReDim statement on arrays they contain. For simpler, more readable code, try the With and For Each statements. For more information, see Chapter 4, "Variables, Constants, and Data Types," in Building Applications, or search the online index for these keywords.

New advanced features

•	OLE Automation. Microsoft Access can now act as an OLE Automation server, so that you can control it from another application such as Microsoft Excel or the Microsoft Visual Basic programming system. For more information, see Chapter 11, "Communicating with Other Applications," in Building Applications.

•	Report, keyboard, and filtering event improvements. Two new form events, the Filter event and the ApplyFilter event, allow more precise control over filtering on your forms. Two new report events, the Page event and the NoData event, help you respond to common report printing problems. The new KeyPreview property makes it easier to process keyboard events on a form. For more information, see Chapter 6, "Responding to Events," in Building Applications.

•	Object model improvements. For more control over your application and its environment, use the new methods of the Application object, and the Err and Error objects. For more information, see Chapter 5, "Working with Objects and Collections," and Chapter 8, "Handling Run-Time Errors," in Building Applications.

•	New Calendar custom control. The Calendar control helps you produce more functional applications. For more information, see Chapter 15, "Using OLE Custom Controls," in Building Applications.

•	Database replication. If users of your application need to share data but aren't always connected to the network, database replication may be useful for you. With database replication, Microsoft Access automatically synchronizes changes between databases. For more information, see Chapter 19, "Using Database Replication," in Building Applications.


What's new with queries?

Microsoft Access for Windows 95 includes a number of new features that make querying easier and more efficient. However, the most significant change is that you may not need to create a query at all to achieve the results you want. If you planned on creating a query to use as the source of records for a form or report, consider using a form or report wizard instead. The form and report wizards automatically create an SQL statement to use as the record source for the form or report so you don't have to create a query. In some cases, however, you'll still need to use a query as the basis for a form or report.

If you do need to create a query, the following new features make the process quick and easy:

•	New Simple Query Wizard. Create a select query that retrieves data from one or more tables using the new Simple Query Wizard. This wizard creates simple select queries or select queries that calculate sums, averages, counts, and other types of totals on one or more tables.

•	Filter by Form or Selection. Use Filter By Form or Filter By Selection to find the same set of records you want a query to find, and then save the filter as a query.

In addition, the following features provide new ways to work with queries:

•	Datasheet Filtering. Apply filters to the data in query Datasheet view  to isolate a subset of records within the query's results.

•	On-Demand Sorting. Using the Sort buttons on the toolbar, you can now sort records in ascending or descending order in Datasheet view. Previously you could only specify a sort order in query Design view. Microsoft Access saves the sort order when you save the query's datasheet.

•	Query Type Button. Specify the type of query you want by using the new Query Type button on the toolbar in query Design view.

•	Flexible AutoJoins. Enable or disable automatic join lines in query Design view. Previously, Microsoft Access automatically displayed join lines between tables in query Design view, connecting fields with the same name and data type if relationships weren't already defined between the tables. With the new Option setting, you can disable this feature if the automatic joins aren't what you want.

•	Top Values Button. Click  [image]  on the toolbar in query Design view to display the top values in the query's results. Previously you had to set the TopValues property in the query's property sheet to display these values.

Note   The Archive Query Wizard is no longer available. Instead, you can create a make-table query that copies existing records into a new table.


What's new with toolbars and toolbar buttons?

To help you work more quickly and accurately in Microsoft Access for Windows 95, a variety of new buttons, such as the Format Painter and Spellchecker buttons, have been added to the built-in toolbars. You can also find a variety of new buttons in the Customize Toolbars dialog box, which you can add to toolbars. (Buttons with images from Microsoft Access version 2.0 are also still available.) Additional toolbar enhancements give you greater flexibility for customizing toolbars and toolbar buttons.

Microsoft Access for Windows 95 offers the following enhancements to toolbars and toolbar buttons:

•	A Button Editor that enables you to edit an existing button image or design a new image. Besides changing or creating the image itself, you can add or change colors or move the entire image around until it's positioned where you want on the top of the button.

•	The ability to copy and paste images from one button to another on the same toolbar or different toolbars and to use bitmaps from a source outside Microsoft Access for toolbar buttons.

•	A Formatting toolbar in form and report Design view, with buttons that enable you to customize the appearance of a form or report. This toolbar includes all the formatting choices previously available through the Palette.

•	Buttons with drop-down list boxes and portable palettes.

When you click a drop-down-style button, it sometimes displays a list of choices, such as a list of the types of queries you can switch to. In the case of the Formatting toolbar, these buttons display palettes you can use to help design a form or report. You can drag the palettes away from the toolbar buttons, and then place them anywhere in the window while you're designing a form or report.

•	The ability to enable or disable shortcut menus on toolbars. By disabling shortcut menus, you can prevent others from customizing your toolbars.


New and improved wizards, builders, and add-ins

Microsoft Access for Windows 95 includes many new and improved wizards, builders, and add-ins that make it easy to create and maintain databases and database objects.

New wizards, builders, and add-ins

•	Database Wizard. Use the new Database Wizard to have Microsoft Access create your database for you. With the Database Wizard, you can pick from over 20 different databases. Microsoft Access includes databases that you can use for business or personal use. For example, you can create an Asset Tracking database or a Wine List database. To use the Database Wizard, click New on the File menu, and then double-click the icon for the database you want to create.

•	Table Analyzer Wizard. Want to take advantage of relational database capabilities in Microsoft Access but you don't know where to start? The Table Analyzer Wizard helps you figure out how to make your database more efficient by normalizing the data. Just click the table you want to analyze in the Database window, point to Analyze on the Tools menu, and then click Table. When you import text or spreadsheet data using one of the import wizards, Microsoft Access asks if you want to run the Table Analyzer Wizard after importing the data.

•	Lookup Wizard. Need help creating a list on a form or datasheet that looks up values from another table? When you use the Lookup Wizard, Microsoft Access walks you through the process of creating a lookup list. You can run the wizard from table Design view by clicking Lookup Wizard as the data type for a field, or you can click Lookup command on the Insert menu in table Datasheet view. Once you've created a Lookup field, whenever you drag that field to a form, Microsoft Access automatically creates a lookup list for that field.

•	Import/Export Wizards. With the new import and export wizards, you can look at your data while you're importing or linking text or spreadsheet data or while you're exporting Microsoft Access data as text. The Import/Export Wizards help you select the correct field delimiters, data types, and so on. Microsoft Access automatically runs the Import Spreadsheet Wizard when you import or link text or spreadsheet data by clicking Get External Data on the File menu. Microsoft Access automatically runs the Text Export Wizard when you export data to an external file by clicking Save As/Export on the File menu.

•	Simple Query Wizard. Use the new Simple Query Wizard to have Microsoft Access create your queries for you. You can use this wizard to create single-table or multiple-table queries. You can also use the wizard to group and summarize your data. For example, you could have the wizard create a count of orders for you, organized by order date. To run the Simple Query Wizard, click the Query tab in the Database window, click New, and then double-click Simple Query Wizard.

•	Form and Report Wizards. With the new Form and Report Wizards, you don't have to create a query beforehand if you want to create a multiple-table form or report — the field picker in the wizard allows you to select fields from any table in your database. Microsoft Access analyzes the relationships between the data and presents you with the options. You can specify several different autoformats and background pictures for your forms and reports. To run the Form Wizard or Report Wizard, click the Forms tab or the Reports tab in the Database window, click New, and then double-click Form Wizard or Report Wizard.

•	Subform/Subreport Wizards and Builder. Microsoft Access includes three new tools to help you create subforms and subreports:

•	If you want to create a main form and subform or a main report and subreport from scratch, use the Form Wizard or the Report Wizard. Just specify the data that you want to include and Microsoft Access does the rest for you.

•	If you want to add a subform to an existing form, or a subreport to an existing report, you can use the new Subform/Subreport Wizard. In the toolbox, click  [image]  if it isn't already pressed in, click  [image], and then click the place where you want the subform or subreport to appear on your form or report.

•	If you've created your form and subform or report and subreport without using a wizard, but you're having trouble linking the forms or reports, use the new Subform/Subreport Field Linker.

•	PivotTable Wizard. With the new PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and a calculation method you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data.

•	Database Splitter Wizard. Use the Database Splitter Wizard to split a database into two files: one that contains the tables and one that contains the queries, forms, reports, macros, and modules. This way, users who need to access the data can customize their own forms, reports, and other objects while you maintain a single source of data on the network. To run the wizard, point to Add-ins on the Tools menu, and then click Database Splitter.

•	User-Level Security Wizard. Do you need the advantages and flexibility of user-level security but don't know where to start? Use the User-Level Security Wizard to get started. When you run the wizard on a database, the wizard creates a new database, exports copies of all of the objects from the original database, secures the object types by revoking all permissions of the Users group for those objects in the new database, and then encrypts the new database. After running the wizard, you can grant permissions to users and/or groups.

•	Performance Analyzer. Want to make your database or application run faster? Using the Performance Analyzer, you can easily analyze any or all of the objects in your database. The Performance Analyzer makes suggestions and can even make certain changes for you if you want. To run the Performance Analyzer, point to Analyze on the Tools menu, and then click Performance.

•	Macro to Visual Basic for Applications Converter. Want to convert your macros to take advantage of the extra flexibility offered by Visual Basic? Just select the macro that you want to convert in the Database window, click Save As/Export on the File menu, click Save As Visual Basic Module, and then click OK. Or if you want to convert all the macros used in a particular form or report, in the Design view of that form or report, point to Macros on the Tools menu, and then click Convert Macros To Visual Basic.

•	Conflict Resolver. Using the Windows 95 Briefcase, you can work remotely with a replicated copy of a database and then merge changes back into a master database. The Conflict Resolver helps you manage conflicts that occur during synchronization. To run the Conflict Resolver, point to Replication on the Tools menu, and then click Resolve Conflicts.

Improved wizards, builders, and add-ins

•	Attachment Manager. The version 2.0 Attachment Manager is now called the Linked Table Manager. Use the Linked Table Manager to view or refresh links when the structure or location of  one or more linked tables has changed. With the new Linked Table Manager, you can easily switch between back-end databases.

•	Menu Builder. You can now create custom shortcut menu bars by using the Menu Builder.

•	Input Mask Wizard. With the improved Input Mask Wizard, you can customize the list of input masks directly from the wizard — you don't have to use the Add-in Manager. To run the Input Mask Wizard, click the Build button next to the InputMask property box in the property sheet.

•	Combo Box and List Box Wizards. You can now use these wizards to create an unbound list box or combo box that finds a record. To run the List Box or Combo Box wizard, in form Design view, make sure that  [image]  is pressed in, click  [image]  or  [image], and then click the place on the form where you want the list box or combo box to appear.

•	Mailing Label Wizard. The version 2.0 Mailing Label Wizard is now called the Label Wizard. With the improved wizard, it's much easier to create mailing labels. You can also create other types of labels besides mailing labels because the wizard provides templates for an assortment of labels. To run the Label Wizard, click the Reports tab in the Database window, click New, choose the table or query you want to use as the source for the report, and then double-click Label Wizard.

•	Chart Wizard. With the improved Chart Wizard, it's much easier to create great-looking charts for your forms and reports.


 Create a new table from the results of a query with a make-table query

1	Create a query, selecting the tables or queries that contain the records you want to put in the new table.

How?

2	In query Design view, click  [image]  on the toolbar, and then click Make Table. The Make Table dialog box appears.

3	In the Table Name box, type the name of the table you want to create or click the name of a table you want to replace.

4	Click Current Database to put the new table in the currently open database. Or click Another Database and type the name of the database you want to put the new table in. Type the path if necessary.

5	Click OK.

6	To preview the new table before you create it, click  [image]  on the toolbar. Make any changes you want. To return to query Design view, click  [image]  on the toolbar.

7	To create the new table, click  [image]  on the toolbar.

Notes

•	To stop a query after you start it, press CTRL+BREAK.

•	After you run a make-table query, you might want to switch to the new table's Design view and set a primary key and table properties. For information on primary keys, click  [image].

•	The data in the new table you create does not inherit the field properties from the original table.


Important considerations when using a query that deletes records

•	Maintain backup copies of your data at all times. If you delete the wrong records, you can retrieve them from your backup copies.

•	Preview the data you are deleting before you delete it. You can do this by viewing the query in Datasheet view before you run the query.

•	In some cases, running a delete query might delete records in related tables, even if they're not included in the query. This can happen when your query contains a table that's on the "one" side of a one-to-many relationship, and you've selected the Cascade Delete Related Records check box (in the Relationships dialog box) for that relationship. When you delete records from the table, you'll also delete records from the "many" table. If you specified referential integrity for a relationship and don't have the Cascade Delete Related Records check box selected, you can delete records only in the "one" table. For more information, click  [image].

•	If you make changes to a Paradox, dBASE, or FoxPro table that's linked to your database, you can't cancel a delete query after you start running it.

•	Once you delete records using a delete query, you can't undo the operation. Make sure the query has selected only the records you want to delete before running it.


Delete a group of records with a query

You can use a single delete query to delete records from a single table or from multiple tables in a one-to-one relationship. To delete records from multiple tables in a one-to-many relationship (for example, all customers from Ireland and all their orders), you must run two queries, since a query cannot delete records from the primary table and the related tables at the same time.

You can distinguish a one-to-many relationship in query Design view by looking at the joins between tables. If one end of a join is marked by the  [image]  symbol, it is a one-to-many relationship. Otherwise, it is a one-to-one relationship.

What do you want to do?

Delete records from a single table or multiple tables that have a one-to-one relationship

Delete records from multiple tables that have a one-to-many relationship


Delete records from one table or tables in a one-to-one relationship

For information on important considerations when using a query that deletes records, click  [image].

1	Create a new query that contains the table from which you want to delete records.

How?

2	In query Design view, click  [image]  on the toolbar, and then click Delete.

3	From the table from which you want to delete records, drag the asterisk (*) from the field list to the query design grid.

"From" appears in the Delete cell under this field, as shown in the illustration that follows.

4	To specify criteria for deleting records, drag to the design grid the fields on which you want to set criteria.

"Where" appears in the Delete cell under this field, as shown in the following illustration.

5	In the Criteria cell for the fields that you have dragged to the grid, type the criteria.

For information on criteria, click  [image].

6	To preview the records that will be deleted, click  [image]  on the toolbar. To return to query Design view, click  [image]  on the toolbar. Make any changes you want in Design view.

7	Click  [image]  on the toolbar to delete the records.

Note   To stop a query after you start it, press CTRL+BREAK.


Delete records from tables in a one-to-many relationship

For information on important considerations when using a query that deletes records, click  [image].

1	Create a new query that contains the tables from which you want to delete records.

How?

2	In query Design view, click  [image]  on the toolbar, and then click Delete.

3	From the table with related records (on the "many" side), drag the asterisk (*) from the field list to the query design grid.

"From" appears in the Delete cell under this field, as shown in the following illustration.

4	From the primary table (on the "one" side of the one-to-many relationship), drag to the design grid the fields on which you want to set criteria.

"Where" appears in the Delete cell under this field, as shown in the illustration that follows.

5	In the Criteria cell for the fields that you have dragged to the grid, type the criteria.

For information on criteria, click  [image].

6	To preview the records that will be deleted, click  [image]  on the toolbar. To return to query Design view, click  [image]  on the toolbar. Make any changes you want in Design view.

7	Click  [image]  on the toolbar to delete the records from the "many" table.

8	Select the field list for each related table and press DELETE to remove it from the query.

9	With just the primary table remaining in the query and the field on which you want to set criteria in the design grid, click  [image]  again. Microsoft Access deletes the specified records from the "one" table.

Note   To stop a query after you start it, press CTRL+BREAK.


Append records from a table to another table using an append query

1	Create a query that contains the table whose records you want to append to another table.

How?

2	In query Design view, click  [image]  on the toolbar, and then click Append. The Append dialog box appears.

3	In the Table Name box, type the name of the table you want to append records to.

4	Click Current Database to put the new table in the currently open database. Or click Another Database and type the name of the database you want to put the new table in. Type the path if necessary.

You can also identify a path to a Microsoft FoxPro, Paradox, or dBASE, database, or you can enter a connection string to an SQL database.

5	Click OK.

6	Drag from the field list to the query design grid the fields you want to append, any fields you want to use for setting criteria, and the primary key field. The primary key field might not be necessary when this field has an AutoNumber data type. For more information, click  [image].

If you want to append all fields that have the same name as fields in the table you're appending to, you can just drag the asterisk (*) to the query design grid.

7	If the fields you've selected have the same name in both tables, Microsoft Access automatically fills the matching name in the Append To row. If the fields in the two tables don't have the same name, in the Append To row, enter the names of the fields in the table you're appending to.

8	In the Criteria cell for the fields that you have dragged to the grid, type the criteria on which additions will be made.

For information on criteria, click  [image].

9	To preview the new table before you create it, click  [image]  on the toolbar. To return to query Design view, click  [image]  on the toolbar. Make any changes you want in Design view.

10	Click  [image]  on the toolbar to add the records.

Notes

•	To stop a query after you start it, press CTRL+BREAK.

•	If you append records to a table with an AutoNumber field, do not include the AutoNumber field in your query if you want Microsoft Access to renumber the appended records. Do include the AutoNumber field in the query if you want to retain the original values from the field. If there are duplicate values, however, Microsoft Access won't append the records.

•	If the table you are appending records to includes a primary key field, the records you are appending must have the same field or an equivalent field of the same data type. AutoNumber fields are the exception  — they are also compatible with Number fields with the FieldSize property set to Long Integer. Microsoft Access won't append the records if either duplicate or empty values would result in the primary key field.


Appending records with AutoNumber fields

When you append records to a table with an AutoNumber field, you can either have Microsoft Access automatically add the AutoNumber values, or you can retain the values from the original table.

•	To have Microsoft Access add AutoNumber values automatically, don't drag the AutoNumber field to the query design grid when you create the query.

With this method, Microsoft Access appends records and automatically inserts AutoNumber values. The first record appended has a value that is one larger than the largest entry that was ever entered in the AutoNumber field (even if the record that contained the largest AutoNumber value has been deleted).

•	To keep the AutoNumber values from the original table, drag its AutoNumber field to the query design grid when you create the query.

Don't use this method if the AutoNumber field in the table to which you're appending is a primary key and the table from which you're appending contains duplicate AutoNumber values.


Examples of expressions in update queries

Use expressions such as the following in the Update To cell in the query design grid for the field you want to update.

Expression	Result
"Salesperson"	Changes value to Salesperson
#8/10/95#	Changes date values to 10-Aug-95
Yes	Changes No values in a Yes/No field to Yes
"PN"&[PartNumber]	Concatenates PN to the beginning of each specified part number
[Order Details].[UnitPrice]*[Order Details].[Quantity]	Calculates the product of UnitPrice and Quantity, both in the Order Details table
[Freight]*1.5	Increases freight charges by 50 percent
DSum("[Quantity]*[UnitPrice]", "Order Details","[ProductID]=" & [ProductID])	Updates sales totals in the current table, based on the product of Quantity and UnitPrice in the Order Details table
Right([FieldName],5):Exit()	Truncates the leftmost characters in a field, leaving the five rightmost characters


Change records as a group using an update query

1	Create a query, selecting the tables or queries that include the records you want to update and the fields you want to use for setting criteria.

How?

2	In query Design view, click  [image]  on the toolbar, and then click Update.

3	Drag from the field list to the query design grid the fields you want to update or for which you want to specify criteria.

4	In the Criteria cell, specify the criteria if necessary.

For information on criteria, click  [image].

5	In the Update To cell for the fields you want to update, type the expression or value you want to use to change the fields, as shown in the following illustration.

For examples of expressions, click  [image].

6	To see a list of the records that will be updated, click  [image]  on the toolbar. This list won't show the new values. To return to query Design view, click  [image]  on the toolbar. Make any changes you want in Design view.

7	Click  [image]  on the toolbar to create the new table.

Note   To stop a query after you start it, press CTRL+BREAK.


Run a make-table, append, delete, or update query

1	Open the query in Design view.

2	Click  [image]  and check the records you have selected.  By previewing the result of the query, you can check your query before modifying data.

3	Click  [image]  and make any necessary changes.

4	Click  [image]  on the toolbar to run the query.

Note   To stop a query after you start it, press CTRL+BREAK.

For information on viewing the results of a make-table, append, or delete query, click  [image].

For information on viewing the results of an update query, click  [image].


View the results of a make-table, append, or delete query

1	Click the  [image]  on the toolbar.

2	In the Database window, click the Tables tab.

3	Click the table you created or changed, and then click Open.


View the results of an update query

1	In query Design view, click the  [image]  on the toolbar, and then click Select.

2	On the View menu, click Datasheet.


Preview the affected records in a make-table, delete, append, or update query

•	In query Design view, click  [image]  on the toolbar.

For this  query	The datasheet displays
Update	The fields to be updated.
Delete	The records to be deleted.
Make-table	The fields to be included in the new table.
Append	The records to be added to another table.


Stop a query

•	Press CTRL+BREAK.


 Switch between views of a query

A query has three views: Design view, Datasheet view, and SQL view. Use Design view to create a query from scratch (instead of using a wizard or one of the other techniques for creating queries), or to change the design of an existing query. Use Datasheet view to see the data retrieved by your query or, in the case of an action query, to preview the data that will be affected when you run the action query. Use SQL view when you want to view or enter SQL statements to create or change a query.

1	Click the arrow next to the View button on the toolbar.

2	In the drop-down list, click the view that you want.


What's new with queries?

Microsoft Access for Windows 95 includes a number of new features that make querying easier and more efficient. However, the most significant change is that you may not need to create a query at all to achieve the results you want. If you planned on creating a query to use as the source of records for a form or report, consider using a form or report wizard instead. The form and report wizards automatically create an SQL statement to use as the record source for the form or report so you don't have to create a query. In some cases, however, you'll still need to use a query as the basis for a form or report. For more information, click  [image].

If you do need to create a query, the following new features make the process quick and easy:

•	New Simple Query Wizard. Create a select query that retrieves data from one or more tables using the new Simple Query Wizard. This wizard creates simple select queries or select queries that calculate sums, averages, counts, and other types of totals on one or more tables.

•	Filter by Form or Selection. Use Filter By Form or Filter By Selection to find the same set of records you want a query to find, and then save the filter as a query. For an example of how to use these filtering methods, click  [image].

In addition, the following features provide new ways to work with queries:

•	Datasheet Filtering. Apply filters to the data in query Datasheet view  to isolate a subset of records within the query's results. For more information, click  [image].

•	On-Demand Sorting. Using the Sort buttons on the toolbar, you can now sort records in ascending or descending order in Datasheet view. Previously you could only specify a sort order in query Design view. Microsoft Access saves the sort order when you save the query's datasheet.

•	Query Type Button. Specify the type of query you want by using the new Query Type button on the toolbar in query Design view.

•	Flexible AutoJoins. Enable or disable automatic join lines in query Design view. Previously, Microsoft Access automatically displayed join lines between tables in query Design view, connecting fields with the same name and data type if relationships weren't already defined between the tables. With the new Option setting, you can disable this feature if the automatic joins aren't what you want. For more information, click  [image].

•	Top Values Button. Click  [image]  on the toolbar in query Design view to display the top values in the query's results. Previously you had to set the TopValues property in the query's property sheet to display these values.

Note   The Archive Query Wizard is no longer available. Instead, you can create a make-table query that copies existing records into a new table. For more information, click  [image].


Open or run a query

You can open select, crosstab, and action queries in Design view. You can also open select and crosstab queries in Datasheet view, enabling you to view the query's results.

You can't view the results of an action query (identified by an exclamation point (!) next to its name in the Database window). However, you can preview the data that will be affected when you run the action query.

What do you want to do?

Open a query in Design view

View the results of a select or crosstab query in Datasheet view

Preview in Datasheet view the records that will be affected by a make-table, delete, append, or update query

Switch between views of a query

Run a make-table, append, delete, or update query


Open a query in Design view

1	In the Database window, click the Queries tab.

2	Click the query you want to open, and then click Design.

Notes

•	If a form or report is based on a query, you can open the query to modify its design directly from the form or report. For more information, click  [image].

•	If you previously saved a query while SQL view was displayed, that's the view Microsoft Access displays the next time you click Design in the Database window for that query.


View the results of a select or crosstab query

Microsoft Access displays the results of a select or crosstab query in a datasheet. You can display the datasheet from query Design view or from the Database window.

From	Do this
Query Design view	Click  [image]  on the toolbar, and then click Datasheet View
Database window	Click the Queries tab, and then double-click the query name, or select the query and then click Open.
To stop the query, press CTRL+BREAK. (This procedure may not work for very large queries, however.)


 Create a calculated field for custom calculations in a query

You can create a new field that displays the results of a calculation you define with an expression.

1	In query Design view, do one of the following:

•	Type an expression in an empty cell in the Field row. If the expression includes a field name, you must place brackets around the name.

•	If you need help creating the expression, use the Expression Builder. To display it, use the right mouse button to click in the Field row where you're adding the calculated field, and then click Build. For information on how to use the Expression Builder, click  [image].

After you press ENTER or move to another cell, Microsoft Access enters the default field name "ExprN", where N is an integer incremented for each new expression field in the query. The name appears before the expression and is followed by a colon. In a datasheet, this name is the column heading.

You can replace "Expr1" with a more descriptive name, such as "NewPrice." For more information on renaming fields, click  [image].

2	If the expression includes one or more aggregate functions (Sum, Avg, Count, Min, Max, StDev, or Var), and if the design grid includes another field or fields that you want to use for grouping, click  [image]  on the toolbar (unless the Total row is already displayed). Leave "Group By" in the Total cell for the grouping field, and in the calculated field, change "Group By" to "Expression."

Notes

•	The Order Details Extended query in the Northwind sample database has an example of a calculated field called ExtendedPrice. The Order Subtotals query has an example of a calculated field called Subtotals that calculates on groups of records. To view these queries, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Queries tab, click Order Details Extended or Order Subtotals, and then click Design. For information on opening Northwind, click  [image].

•	To enter or view an entire expression without scrolling, press SHIFT+F2 to display the Zoom box.

•	If you want, do any of the following to complete the query:

•	Enter criteria to affect the calculation. For more information, click  [image].

•	Sort the results. For more information, click  [image].

•	Set field properties such as Format (since the field doesn't inherit properties from the underlying table). For more information, click  [image].


Examples of expressions for calculated fields in queries or filters

You can use a calculated field expression in the Field cell in a query or advanced filter's design grid.

What do you want to do?

See examples of expressions that use text values

See examples of expressions that use arithmetic operators

See examples of expressions that use date functions

See examples of expressions that use SQL aggregate or domain aggregate functions

See examples of expressions for working with blank fields (null values)

See examples of expressions that use subqueries

Learn how to create an expression


Calculated field expressions that use text values

Expression	Description
FullName: [FirstName] & " " &  [LastName]	Displays the value of the FirstName and LastName fields, separated by a space, in the FullName field.
Address2: [City] & " " & [Region] & " " & [PostalCode]	Displays the value of the City, Region, and PostalCode fields, separated by spaces, in the Address2 field.
ProductInitial: Left([ProductName], 1)	Uses the Left function to display in the ProductInitial field the first character of the value in the ProductName field.
TypeCode: Right([AssetCode], 2)	Uses the Right function to display in the TypeCode field the last two characters of the value in the AssetCode field.
AreaCode: Mid([Phone],2,2)	Uses the Mid function to display in the AreaCode field the two characters starting at the second character of the value in the Phone field.


Calculated field expressions that use arithmetic operators

Expression	Description
PrimeFreight: [Freight] * 1.1	Displays freight charges plus 10 percent in the PrimeFreight field.
OrderAmount: [Quantity] * [UnitPrice]	Displays the product of the values in the Quantity and UnitPrice fields in the OrderAmount field.
LeadTime: [RequiredDate] - [ShippedDate]	Displays the difference between the values in the RequiredDate and ShippedDate fields in the LeadTime field.
TotalStock: [UnitsInStock]+[UnitsOnOrder]	Displays the sum of the values in the UnitsInStock and UnitsOnOrder fields in the TotalStock field.
FreightPercentage: Sum([Freight])/Sum([Subtotal]) * 100	Displays the percentage of total charges made up of freight charges, by dividing the sum of the values in the Freight field by the sum of the values in the Subtotal field. (This example uses the Sum function.)  The Total row in the design grid must be displayed. If the Format property of the field is set to Percent, don't include the * 100.
Note   When you use an arithmetic operator (+, -, *, /) in an expression and the value of one of the fields in the expression is null, the result of the entire expression will be null. If some records in one of the fields you used in the expression might have a null value, you can convert the null value to zero using the Nz function; for example:

Nz([Subtotal])+Nz([Freight])

For more information on the Nz function, click  [image].


Calculated field expressions that use date functions

Expression	Description
LagTime: DateDiff("d", [OrderDate], [ShippedDate])	Uses the DateDiff function to display in the LagTime field the number of days between the order date and shipped date.
YearHired: DatePart("yyyy",[Hire Date])	Uses the DatePart function to display in the YearHired field the year each employee was hired.
Date( )- 30	Uses the Date function to display the date 30 calendar days prior to the current date.


Calculated field expressions that use SQL and domain aggregate functions

Expression	Description
Count(*)	Uses the Count function to count the number of records in the query, including null (blank) fields.
FreightPercentage: Sum([Freight])/Sum([Subtotal])	Displays in the FreightPercentage field the percentage of total charges made up of freight charges, by dividing the sum of the values in the Freight field by the sum of the values in the Subtotal field. (This example uses the Sum function.)
AverageDiscount: DAvg("[UnitPrice]*[Discount]", "[OrderDetails]")	Uses the DAvg function to display in the AverageDiscount field the average discount given on each order.
For more information on using domain aggregate functions, click  [image].


Calculated field expressions for working with null values

Expression	Description
CurrentCountry: IIf(IsNull([Country]), " ", [Country])	Uses the IIf and IsNull functions to display an empty string in the CurrentCountry field if the Country field is null; otherwise, it displays the contents of the Country field.
LeadTime: IIf(IsNull([RequiredDate] - [ShippedDate]), "Check for a missing date", [RequiredDate] - [ShippedDate])	Uses the IIf and IsNull functions to display in the LeadTime field the message "Check for a missing date" if the difference between the values of the RequiredDate and ShippedDate fields is null; otherwise, it displays the difference.
SixMonthSales: Nz([Qtr1Sales]) + Nz([Qtr2Sales])	Displays in the SixMonthSales field the total of the values in the first- and second-quarter sales fields combined, using the Nz function to convert the null values to zero first.
IIf(IsNull[UnitPrice],0,[UnitPrice])	Changes a null value to a zero (0) in the UnitPrice field.
Note   When you use an arithmetic operator (+, -, *, /) in an expression and the value of one of the fields in the expression is null, the result of the entire expression will be null. If some records in one of the fields you used in the expression might have a null value, you can convert the null value to zero by using the Nz function, as shown in the preceding table.


Calculated field expressions that use subqueries

Expression	Description
Cat: (SELECT CategoryName FROM Categories WHERE [Products].CategoryID=[Categories].CategoryID)	Displays the CategoryName if the CategoryID from the Categories table is the same as the CategoryID from the Products table.


 Using criteria in queries or advanced filters to retrieve certain records

Criteria are restrictions you place on a query or filter to identify the specific records you want to work with. For example, instead of viewing all the suppliers that your company uses, you can view just suppliers from Japan. To do this, you specify criteria that limits the results to records whose Country field is "Japan."

To specify criteria for a field in the design grid, enter an expression in the Criteria cell for that field. The expression in the preceding example would be "Japan." You can use more complicated expressions, however, such as "Between 1000 And 5000."

You can enter additional criteria for the same field or different fields. When you type expressions in more than one Criteria cell, Microsoft Access combines them using either the And or the Or operator. If the expressions are in different cells in the same row, Microsoft Access uses the And operator. If the expressions are in different rows of the design grid, Microsoft Access uses the Or operator.

You can also specify criteria to affect the results of a calculation. By adding criteria, you can limit the groups for which you're performing a calculation, limit the records included in the calculation, or limit the results that are displayed after the calculation is performed.

For examples of how to use multiple criteria in the design grid, click  [image].

For information on how to enter criteria expressions, click  [image].

For examples of criteria expressions, click  [image].


Enter criteria in a query or advanced filter to retrieve certain records

Criteria are instructions you use to tell Microsoft Access which records you want to work with. You can enter criteria for one or more fields in a query or in the Advanced Filter/Sort window.

1	In query Design view, or in the Advanced Filter/Sort window for a table, query, or form, click the first Criteria cell for the field for which you want to set criteria.

2	Enter the criteria expression by typing it or by using the Expression Builder. To display the Expression Builder, use the right mouse button to click in the criteria cell, and then click Build. For more information on using the Expression Builder, click  [image].

3	To enter another expression in the same field or in another field, move to the appropriate criteria cell and enter the expression.

Notes

•	For examples of criteria expressions, click  [image].

•	For information on entering criteria in a query that performs calculations, click  [image].


Specify criteria or a sort order when using the asterisk in the design grid

When you use the asterisk (*), the query results automatically include any fields that are added to the underlying table or query after the query is created, and exclude fields that are deleted. However, you can't sort records or specify criteria on fields unless you add them along with the asterisk to the design grid.

1	In query Design view, drag the asterisk from the field list to the Field row in the design grid.

2	Add the fields you want to sort or set criteria for by dragging them from the field list to the Field row.

3	Select a sort order in the Sort cell for the fields you want to sort.

How?

4	Enter criteria in the Criteria row for the appropriate fields.

How?

5	Clear the Show check box for all fields except the asterisk; otherwise the field will appear twice in the query's results.

6	Click  [image]  on the toolbar to view the results.


How expressions are used in queries and filters

You can use expressions in the design grid of a query or advanced filter, in an SQL statement in a query's SQL view, or in the Filter By Form window, to specify criteria that identify the records you want to work with. In queries, you can also use expressions to update values in a group of records or to create calculated fields.

In the design grid, you enter the expression in different places depending on the operation you're trying to perform. (The following table shows where you can enter expressions.) After you type an expression in the design grid and press the ENTER key, Microsoft Access parses it and displays the expression using syntax it understands. If you don't include an operator with the expression, Microsoft Access assumes you mean the = operator. For example, if you type Denmark as the criteria in a Country field, Microsoft Access interprets the expression as Country="Denmark". If you include references to field names in the expression, the fields must be in one of the tables added to the query (unless you are using the DLookup function or a subquery). You don't have to drag the fields to the design grid, however.

To do this	Type the expression in
Specify criteria for a select, crosstab, or action query, or for an advanced filter	A Criteria cell in the design grid of a query or advanced filter.
Create a calculated field	A Field cell in the design grid of a query or advanced filter.
Update records according to the results of the expression (update queries only)	An Update To cell in the design grid of a query.
Specify the records you want to work with, how they are grouped, the criteria for the groupings, or how records are sorted	An SQL statement in SQL view.
Specify criteria when using Filter By Form	A field in the Filter By Form window (although selecting from the list in the fields is easier).
Note   You can see how Microsoft Access evaluates query expressions by switching to a query's SQL view to display its underlying SQL statements. To display a query in SQL view, click the arrow next to the View button on the toolbar, and then click SQL View.


Examples of expressions used in queries and filters

What do you want to do?

See examples of expressions used in calculated fields

See examples of expressions used as criteria to limit the records you work with

See examples of expressions used to update data in an update query

See examples of expressions used in SQL statements

Learn how expressions are used in queries and filters

Learn how to create an expression


Examples of criteria expressions for queries or filters

You can use a criteria expression in the Criteria cell in the Advanced Filter/Sort window or in the Criteria cell in query Design view. When you type expressions in more than one Criteria cell, Microsoft Access combines them using either the And or the Or operator. If the expressions are in different cells in the same row, Microsoft Access uses the And operator. If the expressions are in different rows of the design grid, Microsoft Access uses the Or operator.

Note   You can also use criteria expressions in a field in the Filter By Form window, although it's easier to select the criteria value from the list in the fields.

What do you want to do?

See examples of expressions that use text values

See examples of expressions that use date functions

See examples of expressions for working with blank fields (null values and zero-length strings)

See examples of expressions that use wildcard characters

See examples of expressions that use domain aggregate functions

See examples of expressions that use subqueries to specify criteria

See examples of multiple expressions combined with And and Or

Learn how to create an expression


Criteria expressions that use text values

Field	Expression	Description
ShipCity	"London"	Displays orders shipped to London.
ShipCity	"London" Or "Hedge End"	Uses the Or operator to display orders shipped to London or Hedge End.
ShippedDate	Between #5-Jan-95# And #10-Jan-95#	Uses the Between...And operator to display orders shipped no earlier than 5-Jan-95 and no later than 10-Jan-95.
ShippedDate	=#2/2/95#	Displays orders shipped on 2-Feb-95.
ShipCountry	In("Canada", "UK")	Uses the In operator to display orders shipped to Canada or the UK.
ShipCountry	Not "USA"	Uses the Not operator to display orders shipped to countries other than the USA.
CompanyName	>="N"	Displays orders shipped to companies whose names start with N through Z.
OrderID	Right([OrderID], 2)="99"	Uses the Right function to display orders with OrderID values ending in 99.
CustomerName	Len([CustomerName])>Val(30)	Uses the Len and Val functions to display orders for customers whose name is more than 30 characters long.


Criteria expressions that use date functions

Field	Expression	Description
RequiredDate	Between Date( ) And DateAdd("m", 3, Date( ))	Uses the Between...And operator and the DateAdd and Date functions to display orders required between today's date and three months from today's date.
OrderDate	< Date( )- 30	Uses the Date function to display orders more than 30 days old.
OrderDate	Year([OrderDate])=1994	Uses the Year function to display orders with order dates in 1994.
OrderDate	DatePart("q", [OrderDate])=4	Uses the DatePart function to display orders for the fourth calendar quarter.
OrderDate	DateSerial (Year([OrderDate]), Month ([OrderDate])+1, 1)-1	Uses the DateSerial function to display orders for the last day of each month.
OrderDate	Year([OrderDate])=Year(Now()) And Month([OrderDate])=Month(Now())	Uses the Year and Month functions and the And operator to display orders for the current year and month.


Criteria expressions for working with null values and zero-length strings

Field	Expression	Description
ShipRegion	Is Null	Displays orders for customers whose ShipRegion field is blank.
ShipRegion	Is Not Null	Displays orders for customers whose ShipRegion field contains a value.
Fax	" "	Displays orders for customers who don't have a fax machine, indicated by a zero-length string value in the Fax field instead of a null (blank) value. If the field were blank instead, you wouldn't know whether the company didn't have a fax machine or the number just hadn't been entered yet.


Criteria expressions that use wildcard characters

Field	Expression	Displays
ShipName	Like "S*"	Orders shipped to customers whose names start with the letter S.
ShipName	Like "*Imports"	Orders shipped to customers whose names end with the word "Imports."
ShipName	Like "[A-D]*"	Orders shipped to customers whose names start with A through D.
ShipName	Like "*ar*"	Orders shipped to customers whose names include the letter sequence "ar."
ShipName	Like "Maison Dewe?"	Orders shipped to the customer with "Maison" as the first part of its name and a 5-letter second name in which the first 4 letters are "Dewe" and the last letter is unknown.


Criteria expressions as subqueries

Field	Expression	Displays
UnitPrice	(SELECT UnitPrice FROM Products WHERE ProductName = "Aniseed Syrup")	Products whose price is the same as the price of Aniseed Syrup.
UnitPrice	>(SELECT AVG(UnitPrice) FROM Products)	Products that have a unit price above the average.
RepTopSalaries	> ALL (SELECT Salary FROM Employees WHERE (Title LIKE "*Manager*") OR (Title LIKE "*Director*"))	Salary of every sales representative whose salary is higher than that of employees with "Manager" or "Director" in their titles.
Salary	SELECT LastName, FirstName, Title, Salary FROM Employees T1 WHERE Salary >= (SELECT AVG(Salary) FROM Employees WHERE Employees.Title = T1.Title) ORDER BY Title;	A list of employees whose salary is higher than the average salary for all employees.


Criteria expressions that use domain aggregate functions

Field	Expression	Description
Freight	>(DstDev("[Freight]", "Orders") + DAvg("[Freight]", "Orders"))	Uses the DAvg and DStDev functions to display all orders for which the freight cost fell above the mean plus the standard deviation for freight cost.
Quantity	>DAvg("[Quantity]", "Orders")	Uses the DAvg function to display products ordered in quantities above the average order quantity.
For more information on using domain aggregate functions, click  [image].


 Design or modify a query

In query Design view, you can do any of the following procedures to complete the design of a new query you just created or modify an existing query. You can also use these procedures to modify an SQL statement that's the source of records for a form or report. Changes you make in query Design view are reflected in the SQL statement.

If you're designing or modifying queries in a multiuser environment, there are certain things you should consider. For more information, click  [image].

What do you want to do?

Add a table or query

Join multiple tables

Change the type of join between two tables

Delete a join between two tables

Add a field

Remove a field

Move a field

Insert a field between other fields

Change a field name

Change column widths

Insert or delete a criteria row

Set or change criteria

Specify a sort order for the result set

Show or hide a field in the query's results

Perform calculations on data

Clear the design grid

Set properties

Modify the SQL statement directly


Add fields to the design grid in a query or advanced filter

In a query, you add only those fields whose data you want to view, set criteria on, group by, update, or sort. In an advanced filter, you add the fields you want to use for sorting or specifying criteria. With a filter, Microsoft Access automatically displays all the fields in the filtered results.

1	Open a query in Design view, or open a form or datasheet, and then display the Advanced Filter/Sort window.

2	In query Design view, make sure the field list for the table containing the fields you want to add appears in the top portion of the window. You can add a table or query if the field list you need isn't in the query.

How?

In the Advanced Filter/Sort window, Microsoft Access displays the field list for the underlying table or query automatically. You can't add more tables or queries to this window.

3	Select one or more fields from the field list and drag them to the columns in the grid.

How?

Note   If you add to the design grid a field name that includes a colon, space, or other special characters, you must enclose the name in brackets. For example, if you add a field named Group: 2, you need to show it in the design grid as [Group: 2].


Select fields to add to the design grid in a query or advanced filter

To select	Do this
A field	Click the field name.
A block of fields	Hold down SHIFT and select the first and last fields in the block.
Noncontiguous fields	Hold down CTRL as you select the fields.
All fields	Double-click the title bar of the field list or click the asterisk (*). (For more information on using the asterisk, click  [image])
Notes

•	Once you've selected fields in the field list, you must drag them to the design grid.

•	When you drag more than one field at a time, Microsoft Access places each field in a separate column. If you drag the asterisk to the grid, Microsoft Access places the table or query name in one column and attaches a period and asterisk to the name (for example, Categories.*). After either operation, the datasheet looks the same.

•	Instead of dragging, you can also add fields by double-clicking the name in the field list or selecting a field directly from the list box in the Field row on the grid.


Remove a field from the design grid in a query or advanced filter

•	In query Design view or in the Advanced Filter/Sort window, select the field by clicking its column selector, and then press the DEL key.

Note   When you remove a field from the design grid, you're only removing it from the query or filter's design. You're not deleting the field and its data from the underlying table.


Show or hide table names for each field in the query design grid

When you add fields from multiple tables to the design grid, you might want to track which table each field came from by displaying the table names under the field names.

•	In query Design view, click Table Names on the View menu.

To control whether the table names are shown or hidden by default, click Options on the Tools menu, click the Tables/Queries tab, and then select or clear the Show Table Names check box.


Insert a field between other fields in the design grid of a query or advanced filter

•	In query Design view or in the Advanced Filter/Sort window, drag the field from the field list to the column in the design grid where you want to insert it.


Insert or delete a criteria row in the design grid of a query or advanced filter

•	To insert a criteria row, in query Design view or in the Advanced Filter/Sort window, click in the row that is below where you want the new row to appear, and then click Row on the Insert menu. A new row is inserted above the row that you clicked.

•	To delete a criteria row, click anywhere in the row, and then click Delete Row on the Edit menu.


Using the asterisk in the query design grid

•	Selecting the asterisk (*) in a query has an advantage over selecting all the fields. When you use the asterisk, the query results automatically include any fields that are added to the underlying table or query after the query is created; and automatically exclude fields that are deleted.

•	When you use the asterisk, you can't sort records or specify criteria for fields unless you add those fields along with the asterisk to the design grid. For more information, click  [image].

•	If you type an asterisk in the Field row rather than dragging it, you must type the table name also. For example, type Customers.*.


Remove a table or query from a query

1	In the upper part of query Design view, select the table or query you want to remove by clicking anywhere in its field list.

2	Press the DEL key.

Fields that you have dragged from the field list to the design grid are also removed from the query. The table or query is not deleted from the database, however.


Add a table or query to a query

You can add a table or query to a query if you'd like to bring together data from more than one table or query, or if you accidentally deleted it from query Design view.

1	In query Design view, click  [image]  on the toolbar.

2	In the Show Table dialog box, click the tab that lists the objects whose data you want to work with. If the table you need is in another database or application, first link the table to the active database.

How?

3	Click the name of the object you want to add to the query. To select additional objects one at a time, hold down CTRL while you click each object name. To select a block of objects, click the first name in the block, hold down SHIFT, and then click the last name in the block.

4	Click Add, and then click Close.

Notes

•	You can also add a table or query to a query by dragging the table or query name from the Database window to the upper part of query Design view.

•	When you have multiple tables or queries in a query, they need to be joined together. For information on joining tables, click  [image].


Add a column to the design grid in a query or advanced filter

1	Click anywhere in the column to the left of which you want to add a new column.

2	On the Insert menu, click Column.


Show or hide a field in a query's results

You can add to the query design grid a field that you use for setting criteria or a sort order, yet not show the data from that particular field in the query's results.

•	In query Design view, click the Show box in the design grid for the field you want to show (check mark) or hide (blank box).

Notes

•	If you want to create a form or report based on the query, and the OutputAllFields property isn't set to Yes, you must show the fields for which you will create bound controls on the form or report.

•	When you close a query, Microsoft Access moves hidden fields to the rightmost columns in the design grid.


Change a field name in a query

You can rename a field in a query to describe the field's data more accurately. This is particularly useful when you define a new calculated field or calculate a sum, count, or another type of total on an existing field. In such cases, unless you enter a name, Microsoft Access assigns names such as Expr1 or SumOfOrder Amount. The new field name must follow object-naming rules.

Changing a field name in the query design grid changes the column heading in query Datasheet view. In addition, if you create a new object, such as a new form or report, based on the query, the new object uses the new field name. For example, if you create a control to display the renamed field, the new field name will be used for the control name and its label caption. The field name in the underlying table doesn't change, however, nor does it change in forms and reports that were based on the query before you changed the field name.

If you want the new field name to be used only for datasheet columns, or label captions in forms and reports, you can set the Caption property for the field instead of renaming the field in the design grid.

What do you want to do?

Display new field names by changing them in the design grid

Display new field names by changing the Caption property


Rename a field in a query

1	In query Design view, place the insertion point to the left of the first letter of the current field name in the design grid.

2	Type the new name followed by a colon.

Notes

•	If you're replacing the field name Expr1 (or Expr2, and so on) that Microsoft Access automatically assigned, replace only the name, not the expression that follows the colon.

•	If a field name includes a colon as a character in the name, you must enclose the name in brackets whenever you refer to the field in Microsoft Access. For example, to refer to a field named Group: 2, you would type [Group: 2].


Change a field's caption in a query

1	In query Design view, select a field in the design grid, and then click  [image]  on the toolbar.

2	In the Caption property box, type the name for the field's caption.


Change a column's width in the design grid of a query or advanced filter

1	In query Design view or in the Advanced Filter/Sort window, move the pointer to the right edge of the column selector for the column you want to change, until the pointer turns into a two-way arrow.

2	Drag the edge to the left to make the column narrower or to the right to make it wider.

Notes

•	Microsoft Access can automatically adjust a column's width to the longest visible entry in the design grid. Move the pointer to the right edge of a column's selector until the pointer turns into a two-way arrow, and then double-click. If you adjust a column's width using this method and then add a value that is longer than the column width, you must adjust the column again to see the complete value.

•	To adjust the width of several columns at once, select the columns by dragging across their column selectors, and then use the preceding procedure.

•	Adjusting column widths in Design view or in the Advanced Filter/Sort window has no effect on the column width in the query or filtered datasheet. However, you can use the same techniques in Datasheet view to adjust the column widths there. The column widths you set in Design view or the Advanced Filter/Sort window aren't saved when you close the query, but the column widths you set in Datasheet view are saved when you save the datasheet.


Move a field in the design grid in a query or advanced filter

1	In query Design view or in the Advanced Filter/Sort window, select the column you want to move.

•	To select one column, click its column selector.

•	To select more than one adjacent column, drag across their column selectors.

2	Click the selector of any one of the selected columns again, and then drag the field or fields to their new location.

The displaced field and all fields to its right move to the right.


Considerations when designing or modifying queries in a multiuser environment

If you open a query to make design changes and someone else modifies the query design before you have finished, Microsoft Access displays a message telling you that the design has changed since you started working. You can either replace the new changes with your changes or save your version of the query with a different name. If others are using the query to view data while you're changing the design, they don’t see the design changes until they close and reopen the query.


Bringing together data from more than one table or query in a query

The power of queries lies in being able to bring together or perform an action on data from more than one table or query. For example, you might want to view customer information with the orders they placed. To see this information, you need data from the Customers and Orders tables.

When you add more than one table or query to a query, you need to make sure their field lists are joined to each other with a join line so that Microsoft Access knows how to connect the information.

Then, when you add fields from both tables or queries to the design grid in query Design view, the default join tells the query to check for matching values in the join fields. (This is called an "inner join" in database terminology.) When it finds matches, it combines those two records and displays them as one record in the query's results. If one table or query doesn't have a matching record in the other table or query, neither record appears in the query's results. If you want the query to select all the records from one table or query whether or not it has matching records in the other table or query, you can change the join type. For examples of different join types and how they affect query results, click  [image].

If you want the query to select records based on the value in the join field being greater than, less than, not equal to, greater than or equal to, or less than or equal to the value in the other join field, you must create an SQL statement in SQL view.

If you previously created relationships between tables in the Relationships window, Microsoft Access automatically displays join lines when you add related tables in query Design view. If referential integrity is enforced, Microsoft Access also displays a "1" above the join line to show which table is on the "one" side of a one-to-many relationship and a  [image]  to show which table is on the "many" side.

Even if you haven't created relationships, Microsoft Access automatically creates joins if you add two tables to a query and the tables each have a field with the same name and data type and if one of the join fields is a primary key. The "one" and "many" symbols are not displayed in this case, because referential integrity is not enforced.

Sometimes the tables you add to the query don't include any fields that can be joined. In this situation, you have to add one or more extra tables or queries to serve solely as a bridge between the tables whose data you want to use. For example, if you add the Customers and Order Details tables to a query, they won't have a join line between them because they don't have any fields that can be joined. But the Orders table is related to both tables, so you can include the Orders table in your query to provide a connection between the other two.

If tables in a query aren't joined to one another, either directly or indirectly, Microsoft Access doesn't know which records are associated with which, so it displays every combination of records (called a "cross-product" or "Cartesian product") between the two tables. Therefore, if each table had 10 records in it, the query's results will contain 100 records (10X10). It also means the query might take a long time to run and ultimately might produce less meaningful results.

Note   There are many factors that determine whether you can update data in a multiple-table query. For more information, click  [image].


Join multiple tables and queries in a query

•	In query Design view, drag a field from the field list for one table or query to the equivalent field (a field of the same data type containing similar data) in the field list for the other table or query.

With this type of join, Microsoft Access selects records from both tables or queries only when the values in the joined fields are equal.

Notes

•	Join numeric fields only if the FieldSize property settings for both are Byte, Integer, or Long Integer.

•	You can change the type of join so that Microsoft Access selects all the records from one table or query whether or not it has matching records in the other table or query. For more information, click  [image].


Change the type of join between tables and queries in a query

1	In query Design view, double-click the join line between the field lists for the tables or queries.

2	In the Join Properties dialog box, click the join option you want, and then click OK.

For examples of different join types and how they affect query results, click  [image].

Notes

•	From the Relationships window, you can change the default join type for tables. For more information, click  [image].

•	All of the joins created using the Join Properties dialog box select records only if the values in the joined fields are equal. You can create joins that select records only if the value in one join field is greater than, less than, not equal to, greater than or equal to, or less than or equal to the value in the other join field; to do so, you must create an SQL statement in SQL view.


Join two copies of the same table in a query

By joining two copies of the same table, you create a self-join that combines records from the same table when there are matching values in the joined fields. For example, say you have an Employees table in which the ReportsTo field for each employee's record displays his or her manager's ID instead of name. To find the name that goes with the ID, you'd have to look through the table for that ID. Instead, you could use a self-join to join the ReportsTo field in the first Employees table with the EmployeeID field in the copy of the Employees table to display the manager's name in each employee's record.

1	In query Design view, add the table to the query twice.

2	Create the join by dragging a field in the first table's field list to the field you want to relate it to in the second field list.

Notes

•	Microsoft Access appends "_1" to the table name in the second field list. For example, if you add the Employees table twice, the first field list is titled "Employees," and the second field list is titled "Employees_1." You can rename the table to something more descriptive by setting the Alias property for the field list. For more information, click  [image].

•	In the ReportsTo example mentioned earlier in this topic, add the LastName, FirstName, and Title fields from the first field list to the design grid. To display the name of the manager that the employee reports to, add the LastName field from the second field list to the design grid. You could then use the Caption property in that field's property sheet to display the field name as "Manager" instead of "LastName."


Delete a join line between tables and queries in a query

•	In query Design view, select the join line, and then press the DEL key.

Note   You can prevent Microsoft Access from automatically creating joins between tables in a query. For more information, click  [image].


Enable or disable automatic joins between tables and queries added to queries

1	On the Tools menu, click Options, and then click the Tables/Queries tab.

2	Select or clear the Enable AutoJoin check box.

Note   If you disable automatic joins, you can still create joins yourself.


Using AutoLookup in a query to enter data automatically

You can design a multiple-table query to automatically fill in certain field values for a new record. When you enter a value in the join field in the query or in a form based on the query, Microsoft Access looks up and fills in existing information related to that value. For example, if you know the value in the join field between a Customers table and an Orders table (typically, a customer identifier such as CustomerID), you could enter the customer ID and have Microsoft Access enter the rest of the information for that customer. If no matching information is found, Microsoft Access displays an error message when the focus leaves the record.

For AutoLookup to work, certain conditions must be met:

•	The query must be based on more than one table and the tables must have a one-to-many relationship. (Referential integrity doesn't have to be enforced.)

•	The join field on the "one" side of the relationship must have a unique index. A unique index means that the field is a primary key or its Indexed property in table Design view is set to Yes (No Duplicates).

•	The join field you add to the design grid must come from the table on the "many" side of the one-to-many relationship. (In other words, it's the foreign key for that table.) For AutoLookup to work, this field can't be a primary key and its Indexed property can't be set to Yes (No Duplicates). For example, in a query that includes the Customers and Orders tables, drag to the design grid the CustomerID field from the Orders table, not the one from the Customers table.

•	The value you enter in the join field from the "many" side must already exist in the join field from the "one" side.

When the value of the join field from the "many" side of the relationship is added or changed in a record, Microsoft Access automatically finds and displays the associated values from the table on the "one" side of the relationship.

While you can always update the join field from the "many" side of a relationship, you can update the join field from the "one" side only if the Cascade Update option was selected when defining the relationship between the tables. Either way, when you update data, Microsoft Access automatically recalculates any totals or expressions in the query that are dependent on the updated data.


Create an AutoLookup query that automatically fills in data for new records

For AutoLookup to work, certain conditions must be met. For more information, click  [image].

1	Create a select query, adding two tables that have a one-to-many relationship.

How?

2	Add the fields for the query to the design grid.

You must include the join field from the "many" side of the one-to-many relationship.

3	If you want, specify criteria in the Criteria row to select specific records.

How?

4	To view the query's results, click  [image]  on the toolbar.

When you enter new data in the join field on the "many" side of the relationship, Microsoft Access will automatically look up and fill in the corresponding data from the "one" side.

Note   For information on troubleshooting an AutoLookup query, click  [image].


Determining when I can update data from a query

In some cases, you can edit the data in query Datasheet view to change the data in the underlying table. In other cases, you can't.

The following table shows when a query's results can be updated.

Query or query field	Updatable	Comments
Query based on one table	Yes
Query based on tables with a one-to-one relationship	Yes
Query based on tables with a one-to-many relationship	Usually	For more information, click  [image].
Query based on three or more tables in which there is a many-to-one-to-many relationship.	No	Though you can't update the data in the query directly, you can update the data in a form based on the query if the form's RecordSetType property is set to Dynaset (Inconsistent Updates).
Crosstab query	No
SQL Pass-through query	No
Query that calculates a sum, average, count or other type of total on the values in a field, or an update query that references a field in the Update To row from either a crosstab query, select query, or subquery that contains totals or aggregate functions	No	By using a domain aggregate function in the Update To row of an update query, you can reference fields from either a crosstab query, select query, or subquery that contains totals or aggregate functions. For more information, click  [image].
Union query	No
UniqueValues property set to Yes	No
Query that includes linked ODBC table with no unique index, or a Paradox table without a primary key	No
Query (or underlying table) for which update permission isn't granted	Can delete but not update
Query (or underlying table) for which delete permission isn't granted	Can update but not delete	To modify data, permissions must be assigned. For more information, click  [image].
Query that includes more than one table or query, and the tables or queries aren't joined by a join line in Design view	No	You must join the tables properly in order to update them.
Calculated field	No
Field is read-only. The database was opened as read-only or is located on a read-only drive.	No
Field in record that has been deleted or locked by another user	No	A locked record should be updatable as soon as it is unlocked.
Memo or OLE Object field in the query's results	Yes


When can I update data in a query whose tables have a one-to-many relationship?

If a query is based on a one-to-many relationship, you might not be able to edit the data in the query's results. The following table lists the types of fields that you might not be able to modify, the status bar message displayed when you attempt to modify them, and, when appropriate, alternative methods for updating them.

Type of field	Status bar message	Comments
Join field from the "one" side	Records in table <name> would have no record on the "one" side.	You can't edit the join field from the "one" side if there are joined "many" side records, unless cascade update is enabled between the two tables.
New records, if the "many" side join field doesn't appear in the datasheet	Can't add record(s); join key of table <name> not in recordset.	Add the join field from the "many" side to your query to allow adding new records.
Join field from the "many" side, after you've updated data on the "one" side	To make changes to this field, first save the record.	Save the record; then you'll be able to make changes to the "many" side join field.
Blank field from the table on the "many" side of a one-to-many relationship where an outer join exists	Record(s) can't be added; no corresponding record on the "one" side.	You've tried to enter a value into a blank field from the "many" side of a one-to-many relationship where an outer join exists. You can only do this for records whose joined field from the table on the "one" side contains a value.
Blank field from the table on the "one" side of a one-to-many relationship where an outer join exists	Can't enter value into blank field on "one" side of outer join.	You've tried to enter a value into a blank field on the "one" side of an outer join. You can only enter values in fields from the table on the "many" side and only if the joined field from the "one" side contains a value for that record.
New records, if entire unique key of ODBC table isn't output	Can't add record(s); primary key for table <name> not in recordset.	Select all primary key fields of ODBC tables to allow inserts into them.


Show or hide table names in the query design grid by default

1	On the Tools menu, click Options, and then click the Tables/Queries tab.

2	Select or clear the Show Table Names check box.


Create a crosstab query that summarizes data with row and column headings using a wizard

A crosstab query displays summarized values, such as sums, counts, and averages, from one field, and groups them by one set of facts listed down the left side of the datasheet as row headings and another set of facts listed across the top of the datasheet as column headings. For an example of a crosstab query, click  [image].

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Crosstab Query Wizard, and then click OK.

3	Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose to run the query or see the query's structure in Design view.

If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view. For more information on changing a query in Design view, click  [image].

To troubleshoot problems with the query, click  [image].

Tip   You can display crosstab data without creating a separate query in your database by using the PivotTable Wizard. With a PivotTable, you can change row and column headings on demand to analyze your data in different ways. For information on creating a PivotTable, click  [image].


Create a simple select query with a wizard

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Simple Query Wizard, and then click OK.

3	Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose to run the query or see the query's structure in Design view.

If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view. For more information on changing a query in Design view, click  [image].

To troubleshoot problems with the query, click  [image].


Find duplicate records or field values in a table using a query wizard

Using the Find Duplicates Wizard, you can determine whether a table contains duplicate values in one or more fields. You can then use the results to determine if there are duplicate records in the table, or to determine which records in the table share the same value. For example, you might search for duplicate values in an address field to determine if you have duplicate records for the same supplier, or you might search for duplicate values in a city field to see which suppliers are in the same city.

Note   Without using the Find Duplicates Wizard, you can have Microsoft Access automatically delete duplicate records. For more information, click  [image].

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Find Duplicates Query Wizard, and then click OK.

3	Follow the directions in the wizard dialog boxes. If you don't choose to show fields in addition to those with duplicate values, the query results will sum the instances of each duplicate value. In the last dialog box, you can choose to run the query or see the query's structure in Design view.

If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view. For more information on changing a query in Design view, click  [image].

To troubleshoot problems with the query, click  [image].


Find unmatched records between tables using a query wizard

Using the Find Unmatched Query Wizard, you can find records in one table that don't have related records in another table. For example, you can find customers who don't have orders.

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Find Unmatched Query Wizard, and then click OK.

3	Follow the directions in the wizard dialog boxes. In the last dialog box, you can choose to run the query or see the query's structure in Design view.

If the resulting query isn't exactly what you want, you can rerun the wizard or change the query in Design view. For more information on changing a query in Design view, click  [image].


Create a select query without a wizard

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	In the Show Table dialog box, click the tab that lists the objects whose data you want to work with.

4	Double-click the name of each object you want to add to the query, and then click Close.

5	If you have multiple tables in the query, you must join them together.

For information on different join types and how they affect query results, click  [image].

Note   If default relationships between tables have already been defined, Microsoft Access automatically displays join lines. Even if no relationships are defined, Microsoft Access can create joins automatically between two fields of the same name and data type, where one of the join fields is a primary key. For more information on relationships, click  [image].

6	Add fields to the query by dragging the field names from the field list to the design grid. For more information on how to add fields, click  [image].

7	Refine your query by entering criteria, adding a sort order, creating calculated fields, computing the sum, average, count, or another type of total on the data it retrieves, or otherwise modifying the query's design.

How?

8	To save the query, click  [image]  on the toolbar. Enter a name that follows Microsoft Access object-naming rules, and then click OK.

9	To see the results of the query, click  [image]  on the toolbar.

To troubleshoot problems with the query, click  [image].


Create a query

Before you create a query, first determine whether the form or report wizards can satisfy your needs instead. They automatically create an SQL statement to use as the record source for the form or report so you don't have to create a query. For more information, click  [image].

If you need to create a query, you don't have to design it from scratch. For certain types of queries, you can have Microsoft Access create the query for you using a query wizard. A query wizard speeds up the process of creating a query because it does all the basic work for you. When you use a query wizard, it prompts you for information and creates a query based on your answers. Even if you've created many queries, you may want to use a wizard to quickly design the query. Then you can switch to Design view to customize it.

You can also create a query by using Filter By Form or Filter By Selection to find the same set of records you want a query to find and then by saving the filter as a query, or you can create a query by saving an SQL statement that the form or report wizard created as a query. If none of these methods satisfy your needs, you can create the query from scratch in query Design view.

What do you want to do?

Learn about the different types of queries I can create

Learn when I should base a form or report on a query instead of using the SQL statement created by a form or report wizard

Save an existing SQL statement as a query

Create a filter that I'll save as a query

Use a wizard to create a:

Simple select query

Crosstab query

Find Duplicates query

Find Unmatched query

Work on my own to create a:

Select query

Parameter query

Crosstab query

SQL query

Action query


Create an SQL query

What do you want to do?

Learn more about SQL queries

Create a union query

Create a pass-through query

Create a data-definition query

Create a subquery


Create an action query

What do you want to do?

Learn more about action queries

Create a make-table query

Create a delete query

Create an append query

Create an update query


Types of queries you can create in Microsoft Access

What type of query do you want to learn more about?

Select queries

Parameter queries

Crosstab queries

Action queries

SQL queries


What is a select query and when would you use one?

A select query is the most common type of query. It retrieves data from one or more tables and displays the results in a datasheet where you can update the records (with some restrictions). You can also use a select query to group records and calculate sums, counts, averages, and other types of totals. For examples of select queries, click  [image]. For information on creating queries, click  [image].


What is a parameter query and when would you use one?

A parameter query is a query that when run displays a dialog box prompting you for information, such as criteria for retrieving records or a value you want to insert in a field. You can design the query to prompt you for more than one piece of information; for example, you can design it to prompt you for two dates. Microsoft Access can then retrieve all records that fall between those two dates.

Parameter queries are also handy when used as the basis for forms and reports. For example, you can create a monthly earnings report based on a parameter query. When you print the report, Microsoft Access displays a dialog box asking for the month that you want the report to cover. You enter a month and Microsoft Access prints the appropriate report. For information on creating a parameter query, click  [image].

You can also create a custom form or dialog box that prompts for information instead of using a parameter query. For more information, click  [image].


What is a crosstab query and when would you use one?

A crosstab query displays summarized values (sums, counts, and averages) from one field in a table and groups them by one set of facts listed down the left side of the datasheet and another set of facts listed across the top of the datasheet. For an example of a crosstab query, click  [image]. For information on creating a crosstab query with a wizard, click  [image]. For information on creating a crosstab query from scratch, click  [image].

Tip   You can display crosstab data without creating a separate query in your database by using the PivotTable Wizard. With a PivotTable, you can change row and column headings on demand to analyze your data in different ways. For information on creating a PivotTable, click  [image].


What is an action query and when would you use one?

An action query is a query that makes changes to many records in just one operation. There are four types of action queries: make-table, delete, append, and update.

Make-table query

Creates a new table from all or part of the data in one or more tables. Make-table queries are helpful for:

•	Creating a table to export to other Microsoft Access databases. For example, you might want to create a table that contains several fields from your Employees table, and then export that table to a database used by your personnel department.

•	Creating reports that display data from a specified point in time. For example, suppose you want to print five reports that display quarterly sales totals as of 9:00 A.M. on 31-Mar-92. To preserve the data exactly as it was at that time, create a make-table query that retrieves the records you need and stores them in a new table. Then use this table, rather than a query, as the basis for the reports. (In comparison, a report based on a query or SQL statement extracts the most up-to-date values from the tables rather than the records as of a specific date or time.)

•	Making a backup copy of a table.

•	Creating a history table that contains old records. For example, you could create a table that stores all your old orders before deleting them from your current Orders table.

•	Improving performance of forms and reports based on multiple-table queries or SQL statements. For example, suppose you want to print multiple reports that are based on a five-table query that includes totals. You may be able to speed things up by first creating a make-table query that retrieves the records you need and stores them in one table. Then you can base the reports on this table or specify the table in an SQL statement as the record source for a form or report so you don’t have to rerun the query for each report. The data in the table, however, is frozen at the time you run the make-table query.

For information on creating make-table queries, click  [image].

Delete query

Deletes a group of records from one or more tables. For example, you could use a delete query to remove products that are discontinued and for which there are no orders. With delete queries, you always delete entire records, not just selected fields within records.

For information on creating delete queries, click  [image].

Append query

Adds a group of records from one or more tables to the end of one or more tables. For example, suppose that you acquire some new customers and a database containing a table of information on those customers. To avoid typing all this information in, you’d like to append it to your Customers table. Append queries are also helpful for:

•	Appending fields based on criteria. For example, you might want to append only the names and addresses of customers with outstanding orders.

•	Appending records when some of the fields in one table don’t exist in the other table. For example, in the Northwind sample database, the Customers table has 11 fields. Suppose that you want to append records from another table that has fields that match 9 of the 11 fields in the Customers table. An append query will append the data in the matching fields and ignore the others.

For information on creating append queries, click  [image].

Update query

Makes global changes to a group of records in one or more tables. For example, you can raise prices by 10 percent for all dairy products, or you can raise salaries by 5 percent for the people within a certain job category. With an update query, you can change data in existing tables.

For information on creating update queries, click  [image].


What is an SQL query and when would you use one?

An SQL query is a query you create using an SQL statement. Some examples of SQL-specific queries are the union query, pass-through query, data-definition query, and subquery.

Union query

This type of query combines fields (columns) from one or more tables or queries into one field or column in the query's results. For example, if you have six vendors that send new inventory lists each month, you can combine these lists into one result set using a union query, and then create a make-table query based on the union query to make a new table. For examples of union queries, click  [image].

Pass-through query

This type of query sends commands directly to ODBC databases, such as Microsoft SQL Server, using commands that are accepted by the server. For example, you can use a pass-through query to retrieve records or change data.

Data-definition query

This type of query creates or alters database objects, such as Microsoft Access or Microsoft SQL Server tables.

Subquery

This type of query consists of an SQL SELECT statement inside another select query or action query. You can enter these statements in the Field row of the query design grid to define a new field, or in the Criteria row to define criteria for a field. You can use subqueries to:

•	Test for the existence of some result from the subquery (using the EXISTS or NOT EXISTS reserved words).

•	Find any values in the main query that are equal to, greater than, or less than values returned by the subquery (using the ANY, IN, or ALL reserved words).

•	Create subqueries within subqueries (nested subqueries).


Save an SQL statement in the RecordSource property of a form or report as a query

By saving the SQL statement, you can run the query independently, or base new forms and reports on the query.

1	In form or report Design view, if the property sheet isn't already displayed, click Properties on the View menu.

2	Next to the RecordSource property box, click the Build button to display query Design view.

3	Click  [image]  on the toolbar.

4	In the Save As dialog box, enter a name that follows Microsoft Access object-naming rules, and then click OK.

Microsoft Access adds the query to the Queries tab in the Database window.


Optimizing query performance

There are several things you can do to make your query run faster. In addition to the following tips, you can use the Performance Analyzer to analyze specific queries in your database. For information on using the Performance Analyzer, click  [image].

•	Index fields on both sides of a join, or create a relationship between these fields, and index any field used to set criteria for the query.

Note   The Microsoft Jet database engine automatically optimizes a query that joins a Microsoft Access table on your hard drive and an ODBC server table when the Microsoft Access table is small and the joined fields are indexed. In this case, Microsoft Access improves performance by requesting only the necessary records from the server. Make sure tables you join from different sources are indexed on the join fields.

•	When defining a field in a table, choose the smallest data type appropriate for the data in the field. Also, give fields you use in joins the same or compatible data types.

•	When creating a query, add only the fields you need. In fields used to set criteria, clear the Show check box if you don't want to display those fields.

•	Avoid calculated fields in nested queries. If you add a query containing a calculated field to another query, the expression in the calculated field slows performance in the top-level query. For example, suppose this is Query1:

SELECT Format$(Field1)As TempField FROM Table1

Query1 is nested in the following query, Query2:

SELECT * FROM Query1 Where TempField = 100

Nesting Query1 in Query2 causes optimization problems due to the expression Format$(Field1) in Query1. For best performance, use calculated fields to show the result of an expression only in the top-level query of nested queries. If that's impractical, use a calculated control on the form or report that's based on the query instead of nesting the query.

•	When grouping records by the values in a joined field, specify Group By for the field that's in the same table as the field you're totaling (calculating an aggregate on). For example, if your query totals the Quantity field in an Order Details table and groups by OrderID, specify Group By for the OrderID field in the Order Details table, not the OrderID field in the Orders table.

For greater speed, use Group By on as few fields as possible. As an alternative, use the First function where appropriate. For more information on the First function, click  [image].

If a totals query includes a join, consider grouping the records in one query and adding this query to a separate query that will perform the join. This improves performance in some queries.

•	Avoid restrictive query criteria on calculated and nonindexed columns whenever possible. For information on optimizing criteria expressions using Rushmore technology, click  [image].

•	If you use criteria to restrict the values in a field used in a join, test whether the query runs faster with the criteria placed on the "one" side or the "many" side of the join. In some queries, you get faster performance by adding the criteria to the field on the "one" side of the join instead of the "many" side.

•	Use field sorting judiciously, especially with nonindexed fields.

•	If your data doesn't change often, use make-table queries to create tables from your query results. Use the resulting tables rather than queries as the basis for your forms, reports, or other queries.

•	Avoid using domain aggregate functions, such as the DLookup function, in a query that accesses table data. Instead, add the table to the query or create a subquery.

If you are creating a crosstab query, use fixed column headings whenever possible. For more information, click  [image].

•	Use the Between...And, the In, and the = operators on indexed columns. This helps optimize queries.


Optimizing criteria expressions in queries using Rushmore technology

Rushmore is a data-access technology that permits sets of records to be queried very efficiently. With Rushmore, when you use certain types of expressions in query criteria, your query will run much faster.

Simple expressions

Microsoft Access can optimize simple expressions in the Criteria row of the query design grid or in a WHERE clause in an SQL SELECT statement. A simple optimizable expression can form an entire expression or can appear as part of an expression.

A simple optimizable expression takes one of the following forms:

Indexed field  Comparison operator  Expression

or

Expression  Comparison operator  Indexed field

In a simple optimizable expression:

•	Indexed field must be a field on which an index is constructed.

•	Comparison operator must be one of the following: <, >, =, <=, >=, <>, Between, Like, In.

Note   For best results, the comparison value in an expression using the Like operator must begin with a character, not a wildcard character. For example, you can optimize Like "m*" but not Like "*m*". For more information, click  [image].

•	Expression can be any valid expression, including constants, functions, and fields from other tables.

For examples of simple optimizable expressions, click  [image].

Complex expressions

Microsoft Access can also optimize complex expressions made by combining simple expressions with the And or Or operator.

A complex optimizable expression takes one of the following forms:

Simple Expression  And  Simple Expression

or

Simple Expression  Or  Simple Expression

An expression created with a combination of simple optimizable expressions is fully optimizable. If one of the simple expressions is not optimizable and the two expressions are combined with And, the complex expression is partially optimizable.

The following rules determine query optimization when combining simple expressions in query criteria.

Expression	Operator	Expression	Query Result
Optimizable	And	Optimizable	Fully optimizable
Optimizable	Or	Optimizable	Fully optimizable
Optimizable	And	Not optimizable	Partially optimizable
Optimizable	Or	Not optimizable	Not optimizable
Not optimizable	And	Not optimizable	Not optimizable
Not optimizable	Or	Not optimizable	Not optimizable
--	Not	Optimizable	Not optimizable
--	Not	Not optimizable	Not optimizable
You can also use parentheses to group combinations of simple expressions. The preceding rules also apply to combinations of expressions grouped with parentheses.

Once you've combined simple optimizable expressions into complex expressions, these complex expressions can, in turn, be combined to form even more complex expressions that might be optimizable according to the preceding rules.

For examples of complex optimizable expressions, click  [image].

Notes

•	The Count (*) function is highly optimized for queries using Rushmore. For more information about the Count function, click  [image].

•	If the index is descending and the comparison operator is other than = the query can't be optimized.

•	Rushmore queries will work with Microsoft Access tables, as well as with Microsoft FoxPro and dBASE tables (.dbf files). You can't use Rushmore with ODBC data sources, since Microsoft Access sends these queries to the ODBC data source instead of processing them locally.

•	You can optimize multiple-field indexes if you query the indexed fields in the order they appear in the Indexes window, beginning with the first indexed field and continuing with adjacent fields (up to and including 10 fields). For example, if you have a multiple-field index on LastName, FirstName, you can optimize a query on LastName or on LastName and FirstName, but you can't optimize a query on FirstName.


Examples of simple optimizable expressions

If you have created indexes for the LastName, Age, and HireDate fields in the Employees table, the following are simple optimizable expressions:

[LastName]="Smith"

[Age]>=21

#12/30/90#<[HireDate]

Employees.[LastName]=Customers.[LastName]

[LastName] In ("Smith", "Johnson", "Jones")

[Age] Between 18 And 65

If you have a multiple-field index on the LastName, FirstName fields, the following expression is optimizable:

(([LastName])="Smith") And (([FirstName])="Pat")

The SQL SELECT statement for the following query is Rushmore optimizable if there are indexes on the LastName and FirstName fields. This query counts the number of employees who are named Pat Smith:

SELECT Count(*)
FROM Employees
WHERE (Employees.[LastName] = "Smith") And (Employees.[FirstName] = "Pat")


Examples of complex optimizable expressions

These examples assume that you created indexes for the LastName and HireDate fields but not the MiddleInitial or FirstName fields. The following table lists examples of combined simple expressions and the extent to which the result is optimized.

Expression	Expression Types, Operator, and Result
[LastName]="Smith" AND [Hire Date]<#12/30/90#	Optimizable And Optimizable = Fully Optimizable
[LastName]="Smith" OR [Hire Date]<#12/30/90#	Optimizable Or Optimizable = Fully Optimizable
[LastName]="Smith" AND [MiddleInitial]="C"	Optimizable And Not Optimizable = Partially Optimizable
[LastName]="Smith" OR [MiddleInitial]="C"	Optimizable Or Not Optimizable = Not Optimizable
[FirstName]="Terry" AND [MiddleInitial]="C"	Not Optimizable And Not Optimizable = Not Optimizable
[FirstName]="Terry" OR [MiddleInitial]="C"	Not Optimizable Or Not Optimizable = Not Optimizable


Create a parameter query that prompts for criteria each time it's run

If you frequently run the same select or crosstab query but you change the criteria each time, you can save time by creating a parameter query. By using a parameter query, you don't have to change the query design grid each time; instead, Microsoft Access prompts you for the criteria you specify. You can specify multiple parameters for a field.

For example, suppose you often run a query to find the total number of orders by a salesperson. You could design a parameter query that prompts you for the name of a salesperson every time you run the query.

1	Create a select or crosstab query.

How?

2	In query Design view, drag the fields from the field list for the query to the query design grid.

3	In the Criteria cell under each field you want to use as a parameter, type a prompt enclosed in square brackets. Microsoft Access displays this prompt when the query is run. The text of the prompt must be different from the field name, although it can include the field name.

To display the prompts "Type the beginning date:" and "Type the ending date:" to specify a range of valid values, type Between [Type the beginning date:] And [Type the ending date:] in the Criteria cell of the OrderDate column.

4	To preview the parameter query before you create it, click  [image]  on the toolbar, and then type a value for the parameter. To return to query Design view, click  [image]  on the toolbar.

5	To run the parameter query, click  [image]  on the toolbar.

Notes

•	You must specify a data type for parameters in a crosstab query or in a parameter query that a crosstab query or chart is based on. In the crosstab query, you must also set the ColumnHeadings property. In other parameter queries, specify a data type for a field with the Yes/No data type and fields that come from a table in an external SQL database. For information on specifying a data type for a parameter, click  [image]. For information on setting the ColumnHeadings property, click  [image].

•	You can print parameters in a report.

How?


Specif$y the data type of a parameter in a parameter query
Specify the data type of a parameter in a parameter query

1	In query Design view after creating a parameter query, click Parameters on the Query menu.

2	In the first Parameter cell, type the first prompt you entered in the query design grid.

3	In the Data Type cell to the right, click the data type you want.

4	Repeat steps 2 and 3 for each parameter you want to specify a data type for.


How field properties in a query relate to those in its underlying table or query

By default, a field in a query inherits all the properties that it has in the underlying table or query. For instance, if you've set the Format property of an OrderDate field to Medium Date, the OrderDate field is formatted in the query results as Medium Date. Only the field properties you can change are displayed on a field's property sheet in a query.

If you change a field property in table Design view, any new or existing query automatically inherits the change unless you previously changed that property in query Design view. Settings you change in query Design view aren't affected by subsequent changes in table Design view, nor is table Design view affected by the changes you make to the properties in query Design view.

Because calculated fields display data that isn't stored in any table, they don't inherit table properties. For example, your query might include a field that calculates a currency value, but the values in this field aren't displayed in currency format unless you set the Format property for this field to Currency.

When you create a form or report based on a query, the form or report fields take on the field properties you've set in the query or underlying table. If you subsequently change the property setting for a control in the form or report, the change doesn't affect the setting of that property for the field in the underlying query. Likewise, if you change the property setting for a field in a query after you've created a form using that field, the property setting for the control isn't updated; you must update this manually.


Set properties for a query, its fields, or its field lists

You can set properties for queries, field lists in a query, and fields you add to the design grid in a query.

1	In query Design view, select the field, field list, or query.

•	To select a field, click the cell in the Field row.

•	To select a field list, click anywhere in the list.

•	To select the whole query, click anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the property sheet for the selected object.

3	In the property sheet, click the property you want to set, and then do one of the following:

•	If an arrow appears in the property box, click the arrow and then click a value from the list.

•	Type a setting or expression in the property box.

If a Build button appears next to the property box, click it to display a builder.

4	If you need more space to enter or edit a property setting, press SHIFT+F2 to open the Zoom box.

Tip   When you click a property in the property sheet, a short description of the property appears in the status bar. For more information on the property and its settings, click the property and then press F1.


Rename a table or query that's added to a query

If you have more than one field list for the same table or query in a query, as you do with a self-join, Microsoft Access appends "_1," " _2," and so on to the name for each additional field list. For example, if you add the Employees table twice, the first field list is titled "Employees," and the second field list is titled "Employees_1." You can rename the table to something more descriptive by setting the Alias property for the field list.

1	In query Design view, click anywhere in the second copy of the field list for the table or query.

2	Click  [image]  on the toolbar to display the property sheet.

3	In the Alias property box, type a new name for the table.

Note   Renaming copies of a table or query in a query doesn't rename the underlying table or query.


Display only the highest or lowest values in the query's results

Using the Top Values box on the toolbar, you can specify how many or what percentage of records with the highest or lowest values in a particular field you want the query to return. For example, the query can display those records with the 10 highest or lowest values in a specific field or the records with the highest or lowest 10 percent of values in the field.

1	In query Design view, add to the design grid the fields you want to display in the query's results, including the field you want to display top values for.

2	In the Sort cell of the field you want to display top values for, click Descending to display the highest values or Ascending to display the lowest values. If you're sorting on other fields in the query's design grid, too, those fields must be to the right of the top values field.

3	Click the arrow on  [image]  on the toolbar.

4	Type the percentage or the number of highest or lowest values you want the query results to display.

Note   To display a percentage, type a number followed by a percent sign.

5	To view the query's results, click  [image]  on the toolbar.

Notes

•	Setting the TopValues property in the query's property sheet works the same as  [image]  on the toolbar.

•	The query returns the first n records that meet the setting you specify in the Top Values box. If you specify that a specific number of records be returned, all records with values that match the value in the last record are also returned. Therefore, a query would return all three of the following records even if you requested to see the employees with the top two sales totals because the query doesn't distinguish between the two 50,000 sales totals.

EmployeeID	Sales
1	60,000
2	50,000
3	50,000
If you don't want duplicate values to be returned, set the UniqueValues property in the query property sheet to Yes.

How?


Permit others to view or run my query but not change data or query design

In a secure workgroup, you can assign others permission to view the data your query returns or, in the case of an action query, to run the query, even if they are otherwise restricted from viewing the query's underlying table or query.

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Set the RunPermissions property to Owner's.

The following are true for this setting:

•	All users have the query owner's permission to view or run the query.

•	Only the query owner can save changes to the query.

•	No one can change the ownership of the query.

Notes

•	If the RunPermissions property is set to User's, the permissions that are defined for that classification of users are in effect instead, and any user with Administer permissions for the query can change its ownership.

•	You can set default permissions for all queries by clicking Options on the Tools menu, clicking the Tables/Queries tab, and then clicking the Run Permissions option you want to use.

•	To give more than one user at the same time the ability to modify a query whose RunPermissions property is set to Owner's, you can set the property to User's, change ownership of the query to a group account, and assign multiple users to the group account. Then set the RunPermissions property back to Owner's. For more information on assigning permissions, click  [image].


Change default permissions for all queries

You can change the default permissions that allow others to view data returned from queries or, in the case of action queries, to run the queries, even if they are otherwise restricted from viewing the underlying table or query.

1	On the Tools menu, click Options, and then click the Tables/Queries tab.

2	Click the Run Permissions option you want to use.

If you select Owner's:

•	All users have the query owner's permissions to view or run the query.

•	Only the query owner can save changes to the query.

•	No one can change the ownership of the query.

If you select User's, the permissions that are defined for that classification of users are in effect instead, and any user with Administer permissions for the query can change its ownership.


 Prevent duplicate records from displaying in query results

Microsoft Access considers a record to be unique as long as the value in any field in a record differs from the value in the same field in any other record. In a query, you aren't necessarily displaying all the fields that make up the records in the underlying tables or queries. Therefore, if the field that distinguishes one record from another isn't in the query design grid, the query's results can appear to include duplicate records. For example, if you add just the LastName field and Country field to the query design grid, it might appear that you have duplicate records when several employees have the same last name and live in the same country. The records are not duplicates in the underlying table, however, because the EmployeeID is unique for each record.

To display unique records as determined by all the fields in the underlying table or query, not just those fields in the query design grid, set the query's UniqueRecords property to Yes (the default). To display unique records as determined instead by just the fields in the query design grid, set the query's UniqueValues property to Yes. If the query's results include more than one field, the combination of values from all fields must be unique for a given record to be included in the results. With either setting, if there are duplicates, the query displays one instance of the record but not the duplicates.

What do you want to do?

Prevent duplicate records in a query based on fields in the underlying table

Prevent duplicate records in a query based on fields in the query design grid


Prevent duplicate records in a query based on fields in the design grid

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Set the UniqueValues property to Yes.

If the query's results include more than one field, the combination of values from all fields must be unique for a given record to be included in the results.

4	To view the query's results, click  [image]  on the toolbar.

Note   When the UniqueValues property is set to Yes, Microsoft Access automatically sets the UniqueRecords property to No.


Prevent duplicate records in a query based on fields in the underlying table

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Set the UniqueRecords property to Yes.

Notes

•	The UniqueRecords property has an effect only when you use more than one table in the query and select fields from those tables.

•	When the UniqueRecords property is set to Yes, Microsoft Access automatically sets the UniqueValues property to No.

•	As an alternative to setting the UniqueRecords property, you can add to the design grid the field that distinguishes one record from another.


Specify how long a query waits before displaying an ODBC timeout error

A query that uses an ODBC database as its underlying source of data might encounter delays due to network traffic or heavy use of the ODBC server.

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Set the ODBCTimeout property to the number of seconds that the query waits before displaying a timeout error. The default is 60 seconds.

Note   If you set the property to zero, no timeout error occurs.


Format data in a query's results

Though you'll want to define the default format for a field's values in table Design view, you might want the same field formatted a different way when you're using it in a specific query. For example, you might want to base a report on the query and have the field's values print differently for the report. Also, in the case of a calculated field, which isn't stored in the underlying table, you must define any format you want to use in the query.

1	In the query design grid, click the field whose data you want to format, and then click  [image]  on the toolbar to display the field's property sheet.

2	Set the Format property to the setting you want to use. For information on creating a custom format, click  [image].

3	To view the query's results, click  [image]  on the toolbar.

Notes

•	Changes you make to the properties in query Design view don't affect the design of the tables on which the query is based.

•	For fields that display numbers, you might also want to set the DecimalPlaces property.

•	Currency values, dates, times, and numbers are displayed according to the settings in the Regional Settings section of the Windows Control Panel.


Specify a record-locking strategy for a specific query in a multiuser environment

You can control whether all records in the underlying table or only the record that you're editing is locked when you edit a record in the query's results.

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Click the RecordLocks property setting you want to use.

For information on specifying a default setting for this property that all your queries will use, click  [image].


Display a custom field description in a query's status bar

You can customize the description that is displayed when you click in a field in a query's results.

1	In query Design view, click the field in the design grid whose description you want to change, and then click  [image]  on the toolbar to display the field's property sheet.

2	In the Description property, type the description you want the status bar to display for that field in the query's results. The maximum length is 255 characters.

3	To view the query's results, click  [image]  on the toolbar, and then click anywhere in the field.


Automatically display all fields from a query's underlying table or query

If you want to use a query to view all the fields from one or more underlying tables or queries, you don't have to add all the fields to the design grid. Instead, you can set the OutputAllFields property for the query.

1	In query Design view, select the query by clicking anywhere in query Design view outside the design grid and the field lists.

2	Click  [image]  on the toolbar to display the query's property sheet.

3	Set the OutputAllFields property to Yes.

Notes

•	If you want to limit the records that the query returns by specifying criteria, or if you want to create a calculated field or specify a sort order in the design grid, you only need to add the fields for these purposes to the design grid. Make sure you clear the Show check box for any of these fields; otherwise, they will display twice in the query's results.

•	You can change the default setting for the OutputAllFields property for all new queries by setting its corresponding option in the Options dialog box. On the Tools menu, click Options, click the Tables/Queries tab, and then select or clear the Output All Fields check box.


Change the default setting for the OutputAllFields property for all new queries

1	On the Tools menu, click Options, and then click the Tables/Queries tab.

2	Select or clear the Output All Fields check box.

Note   This option determines whether the query's results automatically include all the fields from the underlying tables or queries (without adding them to the design grid), or only the fields you add to the design grid. Changing this option only affects the property setting for new queries you create, not existing queries.


 Work with SQL in queries, forms, reports, macros, and modules

You can use SQL, or Structured Query Language, to query, update, and manage relational databases such as Microsoft Access. When you create a query in query Design view, behind the scenes Microsoft Access constructs the equivalent SQL statement. You can view or edit the SQL statement by clicking the arrow next to the View button, and then by clicking SQL View. After you make changes to a query in SQL view, the query might not be displayed the same way it was previously in query Design view.

Sometimes you have to create SQL statements yourself because the design grid won't work for certain types of queries, such as pass-through, data-definition, and union queries. To create these queries, you type the SQL statement directly in SQL view.

You can also use SQL statements in many places in Microsoft Access where you can enter the name of a table, query, or field. In some cases, Microsoft Access does this for you. For example, when you create a form or report using a wizard, Microsoft Access creates the SQL statement automatically and uses it as the setting for the RecordSource property. When you create a list box or combo box with a wizard, Microsoft Access creates the SQL statement and uses it as the setting for the RowSource property of the list box or combo box. You can also use SQL statements in subqueries in the query design grid, in the argument of the RunSQL macro action, and in code.

What do you want to do?

View or modify an SQL statement for an existing query

Generate an SQL statement for copying and pasting elsewhere by creating a query in Design view

Change the SQL statement underlying a form or report

Learn when to base a form or report on a saved query instead of an SQL statement

Use an SQL statement as the row source for a list box or combo box

Create an SQL-specific query (union query, pass-through query, data-definition query, subquery)

Perform action query and data-definition query operations from a macro instead of a saved query

Learn how to use SQL in code


Send commands to an SQL database using a Microsoft Access pass-through query

Use pass-through queries to send commands directly to an ODBC database server (such as Microsoft SQL Server). You send the commands using the syntax required by the particular server. With pass-through queries, you work directly with the tables on the server instead of linking them. Pass-through queries are useful for running stored procedures on an ODBC server.

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	Without adding tables or queries, click Close in the Show Table dialog box.

4	On the Query menu, point to SQL Specific, and then click Pass-Through.

5	On the toolbar, click  [image]  to display the query property sheet.

6	In the query property sheet, set the ODBCConnectStr property to specify information on the database to which you want to connect. You can type the connection information, or click the Build button to use the ODBC Connect String Builder.

For details on the syntax for your query, see the documentation for the SQL database server to which you're sending the query.

7	If the query isn't the type that returns records, set the ReturnsRecords property to No.

8	In the SQL Pass-Through Query window, type your pass-through query.

9	To run the query, click  [image]  on the toolbar. (For a pass-through query that returns records, you can click  [image]  on the toolbar, instead.)

If necessary, Microsoft Access prompts you for information about your SQL server database.

Caution   Don't convert a pass-through query to another type of query, such as a select query. If you do, you'll lose the SQL statement that you entered.

Notes

•	If you don't specify a connection string in the ODBCConnectStr property, or if you delete an existing string, Microsoft Access uses the default string "ODBC;". With this setting, Microsoft Access prompts you for connection information each time you run the query.

•	Some pass-through queries can return messages in addition to data. If you set the LogMessages query property to Yes, Microsoft Access creates a table that contains any returned messages. The table name is the user name concatenated with a hyphen ( - ) and a sequential number starting at 00. For example, the default user name is ADMIN so the tables returned would be named "ADMIN - 00," "ADMIN - 01," and so on.

If you create a pass-through query that returns multiple result sets, you can create a separate table from each result. For more information, click  [image].


Create separate tables for multiple sets of records from a pass-through query

1	After creating the pass-through query, create a make-table query based on the pass-through query.

2	In the make-table query, include all fields from the pass-through query by dragging the asterisk (*) to the design grid.

When you run the make-table query, you get one table for each result. The first table created has the name defined in the query; subsequent tables have that name concatenated with a sequential number starting at 1. For example, if you want four tables created for four result sets and you choose "NewTable" as the new table name, the tables created will be named NewTable, NewTable1, NewTable2, and NewTable3.


Combine data in fields from two or more tables using a union query

Union queries combine corresponding fields from two or more tables or queries into one field. When you run a union query, it returns the records from corresponding fields in the included tables or queries.

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	Without adding tables or queries, click Close in the Show Table dialog box.

4	On the Query menu, point to SQL Specific, and then click Union.

5	Enter SQL SELECT statements combined with either the UNION operation if you don't want to return duplicate records or the UNION ALL operation if you do want to return duplicate records.

Note   Each SELECT statement must return the same number of fields, in the same order. The corresponding fields are required to have compatible data types with one exception: You can use a Number and a Text field as corresponding fields.

For information on SELECT statements, click  [image]. For information on the UNION and UNION ALL operations, click  [image].

6	If you want to specify sorting in a union query, add a single ORDER BY clause to the end of the last SELECT statement. In the ORDER BY clause, specify the field name to sort, which must come from the first SELECT statement.

For information on the ORDER BY clause, click  [image].

7	To see the query's results, click  [image]  on the toolbar.

Caution   Don't convert a union query to another type of query, such as a select query. If you do, you'll lose the SQL statement that you just entered.

Notes

•	The query Customers and Suppliers by City in the Northwind sample database is an example of a union query. To view this query, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Queries tab, click Customers and Suppliers by City, and then click Design. For information on opening Northwind, click  [image].

•	For other examples of union queries, click  [image].

•	A union query takes its column names from the column names in the first table or SELECT statement. If you want to rename the fields in the results, use the AS clause.


Examples of union queries

Union queries combine fields from two or more tables or queries into one field.

Basic union query

The following union query consists of two SQL SELECT statements that return the company names and cities that are in both the Suppliers and Customers tables and are from Brazil.

Sorting in a union query

The following union query selects all company names and cities that are in both the Suppliers and Customers tables, and sorts the data alphabetically by city:

SELECT [CompanyName], [City]
FROM [Suppliers]

UNION SELECT [CompanyName], [City]
FROM [Customers]
ORDER BY [City];

Renaming fields in a union query

The following union query renames the Company Name field to "Supplier/Customer Name" in the query output:

SELECT [CompanyName] AS [Supplier/Customer Name], [City]
FROM [Suppliers]

UNION SELECT [CompanyName] AS [Supplier/Customer Name], [City]
FROM [Customers];

Returning duplicate records in a union query

The following union query uses the UNION ALL statement to retrieve duplicate records:

SELECT [CompanyName], [City]
FROM [Suppliers]

UNION ALL SELECT [CompanyName], [City]
FROM [Customers];


View or modify the SQL statement behind an existing query

You can work directly with a query's underlying SQL statement if you're familiar with SQL.

1	Create a query or open an existing query in Design view.

2	Click the arrow next to the View button on the toolbar, and then click SQL View.

Microsoft Access displays the SQL statement that is equivalent to what you created in Design view.

3	If you want to make changes, type your changes in the SQL statement.

4	To see the changes in the design grid, click the arrow next to the View button on the toolbar, and then click Design View.


Use query Design view to generate an SQL statement that can be pasted elsewhere

You can use SQL statements and clauses in many expressions, as arguments of procedures, and as property settings. For example, you can use an SQL statement to set the RowSource property of a list box to generate a list of items.

Each time you create a query in query Design view, behind the scenes Microsoft Access constructs the equivalent SQL statement. You can see this SQL statement in query SQL view and copy and paste it where you need it.

1	In query Design view, create the query from which you want to generate the SQL statement.

2	Click the arrow next to the View button on the toolbar, and then click SQL View.

3	Select all or part of the SQL statement, and then press CTRL+C to copy the selected text onto the Clipboard.

4	Place the insertion point where you want to paste the SQL statement, such as in the Module window or in a property box.

5	Press CTRL+V.

Notes

•	You can create or edit a query in SQL view instead of Design view. To do so, switch to SQL view and type or modify the SQL statement for your query. If you then switch back to Design view, the SQL statement will be represented in the design grid.

•	Most query properties in the property sheet in query Design view have equivalent clauses and options available in SQL view.

•	If you use the Form Wizard or Report Wizard to create a form or report, or if you use the List Box or Combo Box Wizards to create a list box or combo box, Microsoft Access automatically creates an SQL statement to use as the record source or row source. If you don't want to use a wizard, but you want to specify an SQL statement as the record source or row source, it's easier to use the Query Builder instead of the preceding procedure.

•	You can't use the design grid to create SQL-specific queries, such as subqueries, union queries, and pass-through queries. For these types of queries, you must use SQL view. For more information, click  [image].


Use a subquery to define a field or define criteria for a field

A subquery is an SQL SELECT statement inside another select or action query. You can use a subquery as an expression in a Field cell in the query design grid, or to define criteria for a field. A subquery's SELECT statement can't define a union or crosstab query, however.

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	Add the tables or queries you want.

4	Add the fields you want to the design grid, including the fields you want to use the subquery for.

5	If you're using a subquery to define criteria for a field, type a SELECT statement in the Criteria cell of the field for which you want to set criteria. Place the SELECT statement in parentheses.

If you're using a subquery to define a Field cell, type a SELECT statement enclosed in parentheses in a Field cell. After you leave the cell, Microsoft Access automatically inserts "Expr1:", "Expr2:", and so on, before the SELECT statement.

Note   For more space in which to enter the SELECT statement while in a Criteria cell, press SHIFT+F2 and enter the statement in the Zoom box.

To rename the field, replace "Expr1:" with a field name — for example, "Cat:".

6	To see the results, click  [image]  on the toolbar.

Notes

•	For more examples of subqueries used to define criteria, click  [image].

•	You can't use a field that you define with a subquery to group records.


Create, delete, or alter tables, or create indexes using an SQL data-definition query

Use SQL data-definition queries to create, delete, or alter tables, or create indexes in the current database.

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	Without adding tables or queries, click Close in the Show Table dialog box.

4	On the Query menu, point to SQL Specific, and then click Data Definition.

5	Enter the SQL statement for your data-definition query. Each data-definition query consists of just one data-definition statement. Microsoft Access supports these data-definition statements:

•	CREATE TABLE creates a table. For more information, click  [image].

•	ALTER TABLE adds a new field or constraint to an existing table. For more information, click  [image].

•	DROP deletes a table from a database or removes an index from a field or group of fields. For more information, click  [image].

•	CREATE INDEX creates an index for a field or group of fields. For more information, click  [image].

6	To run the query, click  [image]  on the toolbar.

Caution   Don't convert a data-definition query to another type of query, such as a select query. If you do, you'll lose the SQL statement that you entered.

Notes

•	For an example of a data-definition query, click  [image].

•	To create or change objects in ODBC database servers, such as SQL Server, use pass-though queries instead of data-definition queries.

•	Don't design your data-definition query by using the design grid.  Instead, go directly from Design view to the Data Definition Query window.


Example of a data-definition query

This data-definition statement creates a table named Friends. The statement includes the name and data type for each field in the table and assigns the FriendID field an index that marks it as the primary key.

CREATE TABLE Friends
([FriendID] integer,
[LastName] text,
[FirstName] text,
[Birthdate] date,
[Phone] text,
[Notes] memo,
CONSTRAINT [Index1] PRIMARY KEY ([FriendID]));

This data-definition statement creates a multiple-field index on the LastName and FirstName fields.

CREATE INDEX NewIndex
ON Friends ([LastName], [FirstName]);


Use a builder to create the ODBC connection string for an SQL pass-through query

1	Open a pass-through query.

2	Click  [image]  on the toolbar to display the query property sheet.

3	In the query property sheet, click the Build button to the right of the ODBCConnectStr property box, and then enter information about the server you are connecting to.

4	When you are prompted to save the password in the connection string, select Yes if you want the password and logon stored in the connection string information.

Note   The default ODBC connection string is "ODBC;". After the builder creates the ODBC connection string, it enters the new string into the ODBCConnectStr property in the query property sheet.


Using expressions in SQL

You type expressions in SQL statements when you edit a query in SQL view, and in certain property settings and arguments. For example, you can use an SQL statement to set the RowSource property of a list box to generate a list of items.

Entering an expression in SQL view

To type an expression in SQL view, click the arrow next to the View button on the toolbar, and then click SQL View. Microsoft Access displays the SQL statement that describes the active query.

You can type an expression in an SQL SELECT statement, or in a WHERE, an ORDER BY, a GROUP BY, or a HAVING clause.

For examples of expressions in SQL statements, click  [image].

Entering an SQL expression in property settings and arguments

You can type an SQL expression in several arguments and property settings. You can also copy and paste from SQL view. For example, you can use an SQL expression as an argument of the OpenForm or ApplyFilter action, as a setting for the RowSource property, as a domain or criteria argument in a domain aggregate function, or as a setting for the RecordSource property.


Examples of expressions in SQL statements

You can use an expression in many places in an SQL statement, as the following examples show. Expressions are shown in red.

Expression	Result
SELECT [FirstName],[LastName] FROM Employees WHERE [LastName]="Davolio";	Displays the values in the FirstName and LastName fields for employees whose last name is Davolio.
SELECT [ProductID],[ProductName] FROM Products WHERE [CategoryID]=Forms![New Products]![CategoryID];	Displays the values in the ProductID and ProductName fields in the Products table for records in which the CategoryID value matches the CategoryID value specified in an open New Products form.
SELECT Avg([OrderAmount]) FROM Orders WHERE [OrderAmount]>1000;	Calculates the average sale for orders for which the value in the OrderAmount field is more than 1000.
SELECT Department,Count([Department]) FROM Employees GROUP BY Department HAVING Count([Department])>100;	Displays departments having more than 100 employees.


Considerations for sort orders in the design grid of a query or advanced filter

•	Sort orders are saved with a table, query, or form. If you base a new form or report on a table or query that has a sort order saved with it, the new form or report inherits the sort order.

•	You can sort on as many as 10 fields.

•	Sort order depends on the language setting you specify in the Options dialog box at the time you create your database. To check or change this setting, click Options on the Tools menu, and then click the General tab to see the setting under New Database Sort Order.

•	If the design grid contains the asterisk from the field list, you can't sort records unless you add those fields along with the asterisk to the design grid. For more information, click  [image].

•	Use ascending order to sort dates and times from earlier to later. Use descending order to sort from later to earlier.

•	To sort numeric data in Text fields correctly, all text strings must be the same length with shorter numbers padded with leading zeros.  For example, the result of an ascending sort of the text strings "1", "2", "11", and "22" will be "1", "11", "2", "22".  You must pad the single digit numbers with a leading zero for the strings to be sorted properly: "01", "02", "11", "22".  Another solution would be to sort on the numeric values of the strings by using the Val function. For example, if the name of the column with numeric values in Text fields were [Age], sorting on Val([Age]) would put the records in the correct order.

•	When you sort a field in ascending order, any records in which that field is blank (contains a null value) are listed first. If a field contains both null values and zero-length strings, the fields with null values appear first in the sort order, immediately followed by the zero-length strings.


Sort records using a sort order in the design grid of a query or advanced filter

Before you specify a sort order, there are certain things you should consider. For more information, click  [image].

1	Open a query in Design view or display the Advanced Filter/Sort window for a table, query, or form.

2	To sort on more than one field, first arrange the fields in the design grid in the order you want the sorts performed. Microsoft Access sorts on the leftmost Sort field first, then on the next Sort field to the right, and so on. For example, to sort on the LastName field first and then on the FirstName field, the LastName field must be to the left of the FirstName field in the grid.

3	Click the Sort cell in the design grid for the field on which you want to sort, click the arrow, and then click an option.

4	To sort on additional fields, repeat steps 2 and 3.


Create a crosstab query that summarizes data without using a wizard

For an example of a crosstab query before you begin, click  [image].

1	In the Database window, click the Queries tab, and then click New.

2	In the New Query dialog box, click Design View, and then click OK.

3	In the Show Table dialog box, click the tab that lists the objects whose data you want to work with.

4	Double-click the name of each object you want to add to the query, and then click Close.

5	Add fields to the Field row in the design grid and specify criteria.

6	On the toolbar, click  [image], and then click Crosstab.

7	For the field or fields whose values you want to appear as rows, click the Crosstab row, and then click Row Heading.

You must leave the default Group By in the Total row for these fields.

8	For the field whose values you want to appear as column headings, click the Crosstab row, and then click Column Heading. You can choose Column Heading for one field only, and you must leave Group By in the Total row for this field.

By default, the column headings are sorted in alphabetic or numeric order. If you want them to appear in a different order, or if you want to limit which column headings display, set the query's ColumnHeadings property.

How?

9	For the field whose values you want to use in the cross-tabulation, click the Crosstab row, and then click Value.

Only one field can be set to Value.

10	In the Total row for this field, click the type of aggregate function you want for the cross-tabulation (such as Sum, Avg, or Count).

11	To specify criteria that limit row headings before the calculation is performed, enter an expression in the Criteria row for a field with Row Heading in the Crosstab cell and Group By in the Total cell. For example, you might display sales totals for products in certain categories, such as meat and seafood.

To specify criteria that limit records before the row headings are grouped and before the cross-tabulation is performed, add the field you want to set criteria for to the design grid, click Where in the Total cell, leave the Crosstab cell blank, and then enter an expression in the Criteria row. (The query results won't display fields that have Where in the Total row.) For examples of how criteria affect calculations in queries, click  [image].

12	To view the query's results, click  [image]  on the toolbar.

To stop the query after you start it, press CTRL+BREAK.

Notes

•	The query Quarterly Orders in the Northwind sample database is an example of a crosstab query. To view this query, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Queries tab, click Quarterly Orders, and then click Design. For information on opening Northwind, click  [image].

•	If you include a field in the query design grid, but click the "(not shown)" option in the Crosstab cell and Group By in the Total cell, Microsoft Access groups on it as a Row Heading, but doesn't display the row in the query's results.

•	If your Column Heading values include characters usually not allowed in field names, such as decimals, Microsoft Access replaces the character with an underscore in the datasheet.

•	For information on troubleshooting your crosstab query, click  [image].


Sort or limit column headings displayed in a crosstab query

By setting the query's ColumnHeadings property, you can sort and limit the column heading values that display in the query's results. For example, in a crosstab query that displays the months of the year as column headings, you might want to display them chronologically rather than alphabetically, and you might want to display only the columns for January through June.

1	Design your crosstab query either with or without the help of a wizard.

2	Click the background of query Design view, outside the design grid and the field lists.

3	On the toolbar, click  [image]  to display the query property sheet.

4	In the ColumnHeadings property box, enter the column headings in the order in which you want to display them. Between the column headings, type a semicolon or the list separator for your country. (To find the list separator for your country, check the International section of the Windows Control Panel.)

The column headings you enter must exactly match the column headings in the query datasheet. For example, if a column heading in the datasheet is "USA," you must enter a column heading of "USA" — not "US." (After you press ENTER or move the pointer to a different location, Microsoft Access places quotation marks around each heading.)

5	To view the query's results, click  [image]  on the toolbar.

Notes

•	If you run a crosstab query often, or if you use it as the basis for a form or report, you can speed up the query by using the preceding procedure to specify fixed column headings.

•	If you frequently use the same column headings in different queries, consider creating a table with one Text field to store the column headings. Then open the table and copy the headings into the ColumnHeadings property box as needed.


Performing calculations in a query--an overview
Performing calculations in a query — an overview

There are many types of calculations you can perform in a query. For example, you can calculate the sum or average of the values in one field, multiply the values in two fields, or calculate the date three months from the current date.

When you display the results of a calculation in a field, the results aren't actually stored in the underlying table. Instead, Microsoft Access reruns the calculation each time you run the query so that the results are always based on the most current data in the database. Therefore, you can't manually update the calculated results.

To display the results of a calculation in a field, you can use a predefined calculation that Microsoft Access provides or custom calculations you define. Use the predefined calculations, called "totals," if you want to compute the following amounts for groups of records or for all the records combined: sum, average, count, minimum, maximum, standard deviation, or variance. You choose one totals calculation for each field you want to calculate.

You can calculate these amounts using the Simple Query Wizard or using the Total row in the query design grid, where you select the aggregate function for the calculation you want to perform on a field.

In the query design grid, you can also specify criteria to limit the groups for which totals are calculated, limit the records included in the calculation, or limit the results that are displayed after the calculation is performed.

A custom calculation enables you to perform numeric, date, and text calculations on each record using data from one or more fields. For example, with a custom calculation, you can multiply one field's values by a set amount, find the difference between two date fields, combine several values in a Text field, or create subqueries. Using the options in the Total row in the design grid, you can perform the calculation on groups of records and calculate a sum, average, count, or other type of total on the calculated field.

For custom calculations, you need to create a new calculated field directly in the design grid. You create a calculated field by entering an expression into an empty Field cell in the query design grid. For example, you can create a field that multiplies the values in the UnitPrice field by the values in the Quantity field.

The expression can be made up of multiple calculations — for example, Sum([UnitsInStock]+[UnitsOnOrder]). You can also specify criteria for a calculated field to affect the results of the calculation.

You don't have to display the results of a calculation in a field, however. Instead, you can use them as criteria to determine the records the query selects or to determine which records to perform an action on. For example, you can specify the following expression in the Criteria row to tell the query to return only records that have values in the RequiredDate field that are between today's date and three months from today's date.

You can also use a calculation to update data from an update query. For example, you can enter the following expression in the Update To cell to increase all the values in the UnitPrice field by 5 percent.


Perform calculations in a query

You can display the results of these types of calculations in a field:

•	Predefined calculations, called "totals," to compute the following amounts for groups of records or for all the records combined in the query: sum, average, count, minimum, maximum, standard deviation, or variance.

•	A custom calculation to perform numeric, date, and text calculations on each record using data from one or more fields. For example, with a custom calculation, you can multiply one field's values by a set amount, find the difference between two date fields, combine several values in a Text field, or create subqueries. For custom calculations, you need to create a new calculated field directly in the design grid.

Instead of displaying a calculation's results, you can use them:

•	As criteria to determine the records the query selects or to determine which records to perform an action on.

•	To update data from an update query.

What do you want to do?

Learn more about performing calculations in queries

Learn what each type of totals calculation does

Use the Simple Query Wizard to create a query that calculates a sum, average, count, or other totals on one or more groups of records

Use the query design grid to calculate a sum, average, count, or other total

Create a calculated field for custom calculations

See examples of calculations used as criteria

See examples of calculations used to update data


Calculate a sum, average, count, or other total on records in a query

Using the Total row in query Design view, you can calculate the sum, average, count, minimum, maximum, variance, or standard deviation on values in one or more fields, for all the records in a query, or for one or more groups of records. Using the Criteria row, you can also add criteria to affect the results of the calculation.

Note   You can also use the Simple Query Wizard to perform the calculations listed in the Total row, but if you want to add criteria, you must use the query design grid.

What do you want to do?

Calculate totals on all the records in a query

Calculate totals on groups of records in a query

Learn more about the types of totals calculations and when to use them


Calculate a sum, average, count, or other total on groups of records in a query

1	In query Design view, create a select query. Add the tables whose records you want to use in the calculation, and then add the fields on which you want to perform calculations, define groupings, and specify criteria.

2	Click  [image]  on the toolbar.

Microsoft Access displays the Total row in the design grid.

3	For the field or fields you want to group on, leave "Group By" in the Total cell.

4	For each field you want to calculate, click its cell in the Total row, and then click one of the following aggregate functions: Sum, Avg, Min, Max, Count, StDev, or Var.

For information on each aggregate function, click  [image].  (For special considerations when using the First and Last functions, click  [image]).

5	If you want, enter criteria to affect the results of the calculation.

How?

6	If you want, sort the results.

How?

7	Click  [image]  on the toolbar to view the results.

If you didn't get the results you expected, click  [image].

Notes

•	When you use an aggregate function on a field, Microsoft Access combines the function and the field names to name the field in the datasheet (for example, AvgOfFreight). For information on renaming these fields to better indicate their contents, click  [image].

•	If you add a calculated field that includes one or more aggregate functions in its expression, you must set the calculated field's Total cell to "Expression."

•	To create a crosstab query that calculates totals on groups of records, click  [image].

•	The Category Sales for 1994 query in the Northwind sample database has an example of calculating a sum for groups of records. To view this query, open the Northwind database in your Microsoft Access program folder's Samples subfolder. In the Database window, click the Queries tab, click Category Sales for 1994, and then click Design. For information on opening Northwind, click  [image].


Entering criteria in a query that performs calculations

In the query design grid, where you specify criteria determines when the calculation is performed.

Note   Although the following examples only show queries that calculate totals, these guidelines apply to calculated fields as well.

•	To limit groupings before you perform calculations on groups of records, specify the criteria in the Group By fields.

•	To return only selected results after the calculation is performed, specify criteria in the field that contains the calculation. This rule applies whether you're performing the calculation on each record, groups of records, or all records.

To limit the records before they are grouped and before the calculation is performed, add to the design grid the field whose records you want to limit, and then specify criteria in the field's Criteria cell.

When you're calculating totals, set the Total cell for the field containing the criteria to Where. This rule applies whether you're calculating the total on all records or groups of records. (Microsoft Access automatically clears the Show check box.)

Note   The example below uses the ExtendedPrice field twice, once to limit the records and once to calculate the total. However, you can use a different field to limit records by dragging that field to the design grid and setting its Total cell to Where.

Note   For examples of criteria expressions, click  [image].


Calculate a sum, average, count, or other total on all the records in a query

1	In query Design view, create a select query. Add the tables whose records you want to use in the calculation, and then add the fields on which you want to perform calculations and specify criteria.

2	Click  [image]  on the toolbar.

Microsoft Access displays the Total row in the design grid.

3	For each field in the design grid, click its cell in the Total row, and then click one of the following aggregate functions: Sum, Avg, Min, Max, Count, StDev, or Var.

For information on each aggregate function, click  [image]. (For special considerations when using the First and Last functions, click  [image]).

4	If you want, enter criteria to affect the results of the calculation.

How?

5	If you want, sort the results.

How?

6	Click  [image]  on the toolbar to view the results.

If you didn't get the results you expected, click  [image].

Notes

•	When you use an aggregate function on a field, Microsoft Access combines the function and the field names to name the field in the datasheet (for example, AvgOfFreight). For information on renaming these fields to better indicate their contents, click  [image].

•	If you add a calculated field that includes one or more aggregate functions to a query in which you're calculating totals on all the records, you must set the calculated field's Total cell to "Expression."


Aggregate functions in the query design grid's Total row and when to use them

You display the Total row in the design grid when you want to perform the calculations listed in the following table on all the records in the query or groups of records. For a select query, click  [image]  to add the row to the grid. For a crosstab query, Microsoft Access adds the row automatically.

Choose one of the options from the list in the Total row for every field you include in the query, including hidden fields. Nine of the options are aggregate functions. All but the First and Last functions are explained in the following table. For special considerations when using the First and Last functions, click  [image]. The other three options in the list are explained in the second table.

Note   The aggregate functions won't include records containing blank (null) values in their calculations. For example, the Count function returns a count of all the non-null fields. There is a way to count null values, and you can convert null values to zeroes so they are included in a calculation. For more information, click  [image].

Select	To find the	Use with these  field data types
Sum	Total of the values in a field.	Number, Date/Time, Currency, and AutoNumber
Avg	Average of the values in a field.	Number, Date/Time, Currency, and AutoNumber
Min	Lowest value in a field.	Text, Number, Date/Time, Currency, and AutoNumber
Max	Highest value in a field.	Text, Number, Date/Time, Currency, and AutoNumber
Count	Number of values in a field, not counting null (blank) values.	Text, Memo, Number, Date/Time, Currency, AutoNumber, Yes/No, and OLE Object
StDev	Standard deviation of the values in a field.	Number, Date/Time, Currency, and AutoNumber
Var	Variance of the values in a field.	Number, Date/Time, Currency, and AutoNumber
Select	To
Group By	Define the groups you want to perform the calculations for. For example, to show total sales by category, select Group By for the CategoryName field.
Expression	Create a calculated field that includes an aggregate function in its expression. Usually, you create a calculated field when you want to use multiple functions in an expression.
Where	Specify criteria for a field you aren't using to define groupings. If you select this option for a field, Microsoft Access will hide the field in the query results by clearing the Show check box.


Working with blank fields (null values and zero-length strings) in queries

When a field contains no values, it contains a null value or, for Text or Memo fields, a null value or a zero-length string. If null values exist in a field, they can affect the query's results. Following are some guidelines for working with null values and zero-length strings in queries. (For information on the differences between null values and zero-length strings, click  [image].)

Joining fields that contain null values

When you join tables in a query, the result includes only records that don't have null values in the matching fields. For example, to list Suppliers and Customers who live in the same region, you create a query that includes the Suppliers and Customers tables, and the tables are joined on the Region field. When you view the results, you'll see only the values for records that contain a value in the Region field in both tables.

Searching for null values or zero-length strings

If you're using a query to search for null values or zero-length strings, type Is Null into the Criteria cell to search for null values, or type quotation marks (" ") into the Criteria cell to search for zero-length strings (don't type a space between the quotation marks).

Understanding how null values affect numeric calculations

If you use an aggregate function to calculate the sum, average, count, or another amount on a field's values, records with null values in that field won't be included in the calculation. This is true whether you calculate the aggregate using the Total row in the query design grid, the Simple Query Wizard, or a custom expression. For example, if you use the Count function to count the number of values in a field, it will return a count of all the records with non-null values. If you want to find the total number of records including those with null values, use Count with the asterisk (*) wildcard character, as shown in the following illustration.

If you use an arithmetic operator (such as +, -, *, /) in an expression (such as [UnitsInStock]+[UnitsOnOrder]), and one of the fields in the expression contains a null value, then the result of the entire expression will be null.

Converting null values to zero

When you have fields that contain null values, you can create an expression that converts the null values to zero. You might do this if you want the records containing null values to be included in an aggregate calculation, or if you want to prevent an expression from resulting in a null value when a field that's referenced in the expression contains null values. To convert null values to zero, use the  Nz function. For example:

Nz([Subtotal])+Nz([Freight])

For more information about the Nz function, click  [image].

Combining Text fields that contain null values

If you're using an expression to combine two fields containing text values and one or both of the fields includes null values, use the & operator instead of the + operator to combine the values. The & operator will combine the values even if they contain null values, while the + operator will return a null if either of the two values is a null. For example:

FullName: [LastName] & " " & [FirstName]

Sorting on fields containing null values and zero-length strings

When you sort a field in ascending order, any records in which that field is null are listed first. If a field contains both null values and zero-length strings, the null values appear first in the sort order immediately followed by the zero-length strings.

Using the asterisk (*) wildcard character to return non-null values

If you use the expression Like "*" when defining query criteria for a field, the query results will include zero-length strings in that field, but not null values.


Troubleshoot select queries

What best describes the problem with your select query?

The records aren't the ones I want.

The records are in the wrong order.

The columns are wrong.

The calculations in the query are wrong.

I can't update data in the query.

I designed the query to use AutoLookup, but it isn't filling in data automatically.

I need help specifying criteria.

Microsoft Access automatically joins tables or queries I add to query Design view when I don't want them joined.

I'm getting the error message "Query contains ambiguous outer joins."

I'm getting a "Type mismatch" error.

The query is too slow.


The query doesn't retrieve the records I want.

What best describes the problem?

The query retrieves too many records.

The query retrieves too few records.

The query retrieves the wrong records.


The query retrieves too many records.

•	If you have more than one table or query in the query, connect them with a join line if they aren't already connected.

How?

•	If tables or queries are already joined, check the join properties of each join line to see what type of join is in effect. Join properties determine whether one table or query contributes all of its records or only those records that match records in the other table. For examples of join types, how to change them, and how they affect query results, click  [image].

•	Add criteria to limit the records that the query retrieves. Only records that meet the criteria you define are retrieved. For more information about specifying criteria, click  [image].

•	If you already specified criteria, you may want to specify additional criteria either for the same field using the And operator or for other fields. Also, verify that existing criteria is entered correctly. Check for misspellings, unnecessary spaces, or extra characters. Verify that you set the criteria for the appropriate field and that it's the criteria you want the records to meet. If you're using alternative criteria in the Or row in the query design grid or in criteria expressions that use Or, you may want to remove it. If you need alternative criteria that applies to more than one field, you must repeat the criteria in the Or cell of each of those fields. For examples of specifying multiple criteria, click  [image].

•	Check the data you're trying to find. If the data contains extra spaces or other special characters, the criteria must account for this. You can use wildcard characters in the criteria if you aren't sure of or don't want to specify the exact field values. If you're already using wildcard characters and not getting the records you want, or if you are getting an "Invalid syntax" error, you may be using the wildcard characters on the wrong data type. For more information on wildcard characters, click  [image].

•	Check whether the field you're specifying criteria for is a Lookup field in table Design view. If it is, you may be specifying criteria using the values that display on the lookup list instead of their associated foreign key values. Because the foreign key values are the values actually stored in the underlying table, you should use them when you specify criteria for a field. For more information on Lookup fields, click  [image].

•	In a select, append, or make-table query, if you're using  [image]  on the toolbar in query Design view (or setting the TopValues property in the query's property sheet) to return a specified number of the highest or lowest values in a field, the query might return more records than the number you specified. This is because all records that match the last record are also returned. For more information, click  [image].


The query retrieves too few records.

•	If the query includes more than one table or query, check the join properties of each join line between them. Join properties determine if a table or query contributes all of its records or only those records that match records in the other table. For examples of join types, how to change them, and how they affect query results, click  [image].

If the type of join you're using retrieves only matching records from the two joined tables, any records in which the joined field contains a null value won't be included in the query's results.

•	If you specified criteria, it may be too restrictive. For example, if you specified criteria in the Criteria row for two different fields, both criteria must be true for a record before the query retrieves it. You may want to delete some or all of the criteria to allow the query to return more records.

•	Verify that existing criteria is entered correctly. Check for misspellings, unnecessary spaces, or extra characters. Verify that you set the criteria for the appropriate field and that it's the criteria you want the records to meet.

•	Use wildcard characters in the criteria if you aren't sure of or don't want to specify the exact field values. If you're already using wildcard characters and not getting the records you want, or if you are getting an "Invalid syntax" error, you may be using the wildcard characters on the wrong data type. For more information on wildcard characters, click  [image].

•	Check whether the field you're specifying criteria for is a Lookup field in table Design view. If it is, you may be specifying criteria using the values that display on the lookup list instead of their associated foreign key values. Because the foreign key values are the values actually stored in the underlying table, you should use them when you specify criteria for a field. For more information about Lookup fields, click  [image].

•	Add alternative criteria to select the records you want to work with. You can do this in the query design grid, in the Or row or in the Criteria row using expressions containing the Or operator. For examples of using alternative criteria, click  [image].

•	If you're using criteria to select records containing specific values in a field or fields, any records with null values in that field don't match the value, and therefore won't be included in the records that are returned. To include records containing null values, type Is Null in the Or row. For more information about null values, click  [image].


The query retrieves the wrong records.

•	Verify that existing criteria is entered correctly. Check for misspellings, unnecessary spaces, or extra characters. Verify that you set the criteria for the appropriate field and that it's the criteria you want the records to meet.

•	Verify that the tables and queries you've added to the upper part of query Design view are the correct ones. For information on adding a table or query, click  [image]. For information on deleting a table or query, click  [image].


The records the query retrieves are in the wrong order.

•	Specify a sort order if you haven't already done so.

How?

If you're working in a multiuser environment, someone else may have set a different sort order. Sort orders are saved with the query. You can change the sort order to the one you want.

•	If you've already specified a sort order, it may be set for the wrong field. Delete the sort you specified and specify a new sort order for the correct field.

•	If the sort order is set for the correct field, you may have selected Ascending when you really wanted Descending, or vice versa. Select the correct sort order.

•	If you have sort orders specified for more than one field, you may need to reorder the fields in the query design grid because Microsoft Access performs multiple sorts from left to right in the order the fields appear in the query design grid.

•	The field you specified the sort order for may be hidden. If you want to show the field you're using to sort records, make sure the Show check box is selected in the query design grid.

•	For more considerations when sorting records, click  [image].


The columns the query retrieves are wrong.

What best describes the problem?

The query retrieves too many columns.

The query retrieves too few columns.

The query retrieves the wrong columns.


The query retrieves too many columns.

•	Remove the fields in the query design grid that you don't want to see in the query results, and remove the asterisk (*) if you added it from the top of the field list. The asterisk automatically includes all fields from the underlying table. For more information on removing fields, click  [image].

•	Hide fields that you don't need to display in the query's results.

How?

•	Verify that the Output All Fields check box isn't selected. To see if it is selected, on the Tools menu, click Options, and then click the Tables/Queries tab. If it is, all fields from the underlying table or query will appear in the query's results without being added to the query design grid. If you do add a field to the design grid, say, for setting criteria, you need to clear the Show check box for that field; otherwise, the column appears twice in the query's results. Or if you want, clear the Output All Fields check box. Changing this option affects the property setting for new queries you create only, not existing queries.


The query retrieves too few columns.

•	Add more fields to the query design grid. Or if you add the asterisk from the top of the field list, the query automatically includes all fields from the underlying table or query.

How?

•	Add other tables or queries containing the fields you need.

How?

•	Show hidden fields.

How?

•	If the Output All Fields check box is not selected, only the fields in the design grid are retrieved. To see if it is selected, on the Tools menu, click Options, and then click the Tables/Queries tab. If it is, all fields from the underlying table or query will appear in the query's results without being added to the query design grid. If you do add a field to the design grid, say, for setting criteria, you need to clear the Show check box for that field; otherwise, the column appears twice in the query's results. Or if you want, clear the Output All Fields check box. Changing this option affects the property setting for new queries you create only, not existing queries.


The query retrieves the wrong columns.

•	In the query design grid, remove the fields that you don't want the query to retrieve.

How?

•	If columns are missing, add their fields to the query design grid.

How?

•	Verify that the tables and queries you're retrieving records from are the correct ones. For information on adding a table or query, click  [image]. For information on removing a table or query, click  [image].


The calculations in the query are wrong.

What best describes the problem?

The results of a totals calculation in the query are wrong.

The results of a totals calculation are in the wrong column.

An arithmetic calculation in the query design grid returns a null (blank) value.


The results of a totals (aggregate) calculation are in the wrong column.

In the query design grid, delete the aggregate you specified in the Total cell, and then select one in a different column.


The arithmetic calculation in the query design grid returns a null (blank) value.

If you use an arithmetic operator (such as +, -, *, /) in an expression, such as [UnitsInStock]+[UnitsOnOrder], and one of the fields in the expression contains a null value, then the result of the entire expression will be a null value. To avoid this, you can convert null values to zeros or other numbers.

How?


The results of a totals (aggregate) calculation in the query are wrong.

•	If there are records with null (blank) values in the field you are calculating, those records won't be included in the calculation. For more information on null values, including how to include them in a calculation, click  [image].

•	If the query isn't grouping the records correctly, verify that you have Group By in the Total cell for the field or fields you want to use for grouping calculations. For information on performing calculations on groups of records, click  [image].

•	In a crosstab query, you might have too many or too few Group By fields. Add, remove, or change the fields designated as row headings that group the totals vertically. Verify that you're using the correct field's values as column headings that group the totals horizontally.

•	Where you specify criteria in the query design grid determines if records are limited before the query groups or performs calculations, if groups are limited before the calculation is performed, or if only certain results are returned after the calculation is performed. For more information, click  [image].

•	Verify that the aggregate you selected is the correct one. If not, select a different aggregate from the list in the Total cell. For more information on different aggregate functions, click  [image].


I can't update the data in my query.

There are some types of queries or certain fields in queries that aren't updatable. For information on when you can update data, click  [image].


My AutoLookup query isn't filling in data.

For AutoLookup to work, the joined fields must meet certain conditions, and you must include certain fields from both tables in the query design grid. For more information, click  [image].


I need help specifying criteria.

What do you need help with?

Understanding criteria expressions

Finding records that meet one criteria and/or another criteria for the same or different fields

Finding records that contain values that fall within a range of values

Finding records with values that start or end with certain characters or words, or contain certain characters or words

Finding records that don't match a value

Finding records that contain a value, not blanks (null values)

Finding records that don't contain a value

Finding records that contain the current date

Finding records that contain one value from a list of possible values

Limiting records involved in a calculation

Displaying part of a text field

Displaying part of a date field

Resolving a "Type mismatch" error


I'm getting a "Type mismatch" error.

•	Verify that the criteria you specified is for the same data type as the data in the underlying table or query. For example, the field ReorderLevel has a Number data type. Therefore, if you type the criteria "50", you'll get an error because Microsoft Access interprets values in quotation marks as text, not numbers.

•	Verify that the data type of each pair of joined fields in the query is the same. If not, change the data type of one of the joined fields to match the data type of the other.

How?


The query is too slow.

To speed up queries you can:

•	Use the Performance Analyzer to automatically evaluate the query and recommend changes that might make it run faster.

How?

•	Add indexes to the underlying tables. For information on what an index is and when to use one, click  [image].

Note   If you use the Performance Analyzer Wizard, it will suggest where to create indexes and relationships.

•	Change query design to optimize performance.

How?


Troubleshoot crosstab queries

What best describes the problem with your crosstab query?

The column headings aren't in the order I want, or I want to exclude some of them.

One or more column headings in the query's results are labeled "< >".

I'm getting the error message "Can't bind name name."

The wrong field values are showing as row or column headings.

The records aren't the ones I want.

The records are in the wrong order.

The columns are wrong.

The calculated amounts are wrong.

I need help specifying criteria in the query.

I can't update data in the query.

The query is too slow.


The column headings aren't in the order I want, or I want to exclude some of them.

You can set the query's ColumnHeadings property to specify which column headings are displayed and in what order you want them to appear.

How?


One or more column headings in the query's results are labeled "< >".

Microsoft Access returns "<>" as the column name for any null value in the field with Column Heading in its Crosstab cell. To avoid this you can:

•	Explicitly define your column headings by setting the query's ColumnHeadings property.

How?

•	In the design grid, type Is Not Null in the Criteria cell of the designated Column Heading field.

•	In the Criteria cell of the designated Column Heading field, use the Nz function in an expression that will convert null values to a more meaningful value, such as "Unknown." For more information about the Nz function, click  [image].


The wrong field values are showing as row or column headings.

Verify that the field whose values you want to use as column headings is in the query design grid with Column Heading in the Crosstab cell, and that the field or fields whose values you want to use as row headings are in the query design grid with Row Heading in the Crosstab cell. To change the value in a Crosstab cell, click the cell, and then click a value from the list. If you want to display only certain values as column headings, set the query's ColumnHeadings property.

How?


I can't update the data in my crosstab query.

Data in a crosstab query is not updatable. For information about when you can update data from a query, click  [image].


Retrieve a range of records using a query

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In an expression in the Criteria cell of the appropriate field, identify a range by using the Between...And operator or the comparison operators (<, >, <>, <=, and >=). For example, you can find orders placed before 1-Jan-93 or products that have between 10 and 35 units in stock. The following table shows some examples of operators used in expressions.

Expression	Meaning
>234	Numbers greater than 234
Between #2/2/93# And #12/1/93#	Dates from 2-Feb-93 through 1-Dec-93
<1200.45	Numbers less than 1200.45
>="Callahan"	All names from Callahan through the end of the alphabet
Note   Dates and numbers are displayed in the query design grid in the format appropriate for the country selected in the Regional settings of the Windows Control Panel. For example, the date sequence is month/day/year for the United States, day/month/year for the United Kingdom, and year/day/month for Sweden.


Retrieve records that don't match a value using a query

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In the Criteria cell of the appropriate field, enter an expression using the Not operator. For example, you can type the expression Not T* in the Criteria cell of the CompanyName field to find all customers whose names don't begin with T, or Not 2 to find shippers whose ID isn't 2.


Retrieve records except those containing null values using a query

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In the Criteria cell of the appropriate field, type the expression Not Null or Is Not Null. For example, if you want to see all Northwind suppliers who have a fax number, type Not Null or Is Not Null in the Criteria cell of the Fax field.


Retrieve records that don't contain values using a query

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In the Criteria cell of the appropriate field, type the expression Is Null. For example, if you want to see all Northwind suppliers whose fax number hasn't been entered, type Is Null in the Criteria cell of the Fax field.


Retrieve records with the current date using a query

The current date is the system date Microsoft Access takes from your computer's system clock.

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In the Criteria cell of the appropriate field, type Date(), with no space between the parentheses. For example, you can find all orders that were shipped on the current date.


Retrieve records that include one value from a list of values using a query

1	In query Design view, create a query. Add the tables whose records you want to use, and then add the fields you want to include in the query to the query design grid.

2	In the Criteria cell of the appropriate field, type an expression using the In operator. For example, to find suppliers located in France, Germany, or Japan, type the following expression in the Criteria cell for the Country field of the Suppliers table:

In(France,Germany,Japan)

You can also enter:

France Or Germany Or Japan


Display part of a text field using a calculated field

Often you'll want to get at information that's found in a specific part of a field. For example, if a field contains part ID numbers, such as BAC8956 and RTR8945, you can create a calculated field that uses a function to extract just the first left characters or the last right characters. Or you can find some of the characters in the middle.

1	In query Design view, create a query. Add the tables whose records you want to use.

2	To find values in part of a field, use the Left, Right, or Mid function in an expression in an empty cell in the Field row in the query design grid.

The syntax for these functions is:

Left(stringexpr,n)
Right(stringexpr,n)
Mid(stringexpr,start,n)

The stringexpr argument can be either a field name (enclosed in brackets) or a text expression; n is the number of characters you want to extract; start is the position of the first character you want to extract.

The following table shows examples of these functions.

If the value in  Part ID is	This expression	Returns
BA-7893-R12	Left([PartID],2)	BA
BA-7893-R12	Right([PartID],3)	R12
BA-7893-R12	Mid([PartID],4,4)	7893
3	Add any other fields you want to include in the query to the query design grid.


Display part of a date field using a calculated field

You can create a calculated field that displays part of a date field taken from a table. For example, you may want to print a report that shows sales for June. You can create a query that returns the year "1993" rather than a full date.

1	In query Design view, create a query. Add the tables whose records you want to use.

2	Use the DatePart function in an expression in an empty cell in the Field row in the query design grid.

The syntax for this function is:

DatePart(datepart,date)

The datepart argument is the abbreviation for the part of the date you want returned. Examples are "yyyy" for a four-digit year and "q" for a calendar quarter. The date argument is either a field name with the Date/Time data type or a literal date such as "7-Nov-93".

The following table lists examples of expressions that apply the DatePart function to the OrderDate field from the Orders table.

If the value in  OrderDate is	This expression	Returns
3-Jun-93	DatePart("m",[OrderDate])	6 (month of year)
28-Mar-92	DatePart("yyyy",[Order Date])	1992 (four-digit number of year)
3	Add any other fields you want to include in the query to the query design grid.


Troubleshoot Find Duplicates queries

What best describes the problem?

I want to delete duplicate records after using the Find Duplicates Wizard.

I converted a Find Duplicates query to a delete query, and it deleted all the records in the table.


I want to delete duplicate records after using the Find Duplicates Wizard

You can delete the duplicate record or the original directly in query Datasheet view by clicking the record, and then clicking  [image]  on the toolbar.

If you want Microsoft Access to delete all the duplicates and keep the original records automatically, don't use the Find Duplicates Wizard. For more information, click  [image].


Troubleshoot delete queries

What best describes the problem?

The records aren't the ones I want.

The delete query deleted records from the wrong table.

I can't delete just the duplicate records from a table.

I need help specifying criteria.

I'm getting a "Key violation" error.

I'm getting a "Lock violation" error.

I'm getting a "Type conversion failure" error.

The query is too slow.


The delete query deleted records from the wrong table.

Make sure the delete query includes:

•	The table you want to delete records from. Double-click the asterisk (*) in the field list for that table.

•	The field(s) you want to specify criteria for. In the table's field list, double-click the field you want.

In the query design grid, "From" or "Where" is displayed in the Delete row. "From" is displayed in the Delete cell of the table you'll delete records from, and "Where" is displayed in the Delete cell of the field(s) you specify criteria for.


I can't delete just the duplicate records from a table.

If you want Microsoft Access to automatically delete just the duplicate records from a table without deleting the originals, you don't use a Find Duplicates query or convert a Find Duplicates query to a delete query.

For information on how you can delete just the duplicate records, click  [image].


Delete duplicate records from a table

In this procedure, you create a copy of the structure of the table that contains duplicates, make primary keys of all the fields that contain duplicates, and then run an append query from the original table to the new table. Because fields that are primary keys can't contain duplicate records, this procedure produces a table without duplicate records.

To create a new table

1	In the Database window, click the Tables tab.

2	Click the name of the table you want to delete duplicate records from.

3	Click  [image]  on the toolbar.

4	Click  [image]  on the toolbar.

5	In the Paste Table As dialog box, type a name for the copied table, click Structure Only, and then click OK.

6	Open the new table in Design view, and select the field(s) that contain duplicates.

7	Click  [image]  on the toolbar to create a primary key based on the selected fields.

8	Save and close the table.

To append only unique records to the new table

1	Create a new query based on the original table containing duplicates.

2	In query Design view, click  [image]  on the toolbar, and then click Append.

3	In the Append dialog box, click the name of the new table from the Table Name list, and then click OK.

4	Include all the fields from the original table by dragging the asterisk (*) to the query design grid.

5	Click  [image]  on the toolbar.

6	Click Yes to proceed with the query.

7	Click OK when you receive the message, "Microsoft Access can't append all the records in the append query."  This transfers only unique records to your new table and discards the duplicates.

8	When you're sure the new table has the correct, unique records, you can delete the original table, and then rename the new table using the name of the original table.


I'm getting a "Key violation" error.

A key violation occurs if:

•	You attempt to run a query that appends, deletes, or updates records that violate the rules of referential integrity for related tables.

•	Your query attempts to append or update records that contain primary key values that already exist in the destination table.

If you run such a query, it will not modify the records that cause the key violation.

To modify records that violate referential integrity, you can break the relationship between the affected tables or turn referential integrity off, and then modify the affected tables one at a time. However, the resulting data in the two tables may then conflict. For more information about referential integrity, click  [image].

For more information about setting and changing primary keys, click  [image].


I'm getting a "Lock violation" error.

A lock violation occurs if you're attempting to modify one of the following:

•	Fields in a locked record. If you use Microsoft Access in a multiuser environment and a record is locked by another user, you can't edit the data in the record. When you move to a locked record,  [image]  is displayed in the record selector.

•	Locked or disabled fields. If a control on a form has the Locked property set to Yes or the Enabled property set to No, you can't edit the data in the field.

•	Fields in a read-only form or a locked database. If the form you're using has the AllowEdits property set to No or if the underlying data is read-only or locked by another person, you can't edit data in the form.


I'm getting a "Type conversion failure" error.

•	Verify that the criteria you specified is for the same data type as the data in the underlying table or query. For example, the field ReorderLevel has a Number data type. Therefore, if you try to use a query to change the value to "50", you'll get an error because Microsoft Access interprets values in quotation marks as text, not numbers.

•	Verify that the data type of each pair of joined fields in the query is the same. If not, change the data type of one of the joined fields to match the data type of the other.

How?


I'm getting a "Validation rule violation" error.

A validation rule violation error occurs if you attempt to update or append records that violate the validation rules for a field or record.

For more information about validating data, click  [image].


Troubleshoot make-table queries

What best describes the problem?

The records aren't the ones I want.

The records are in the wrong order.

The columns are wrong.

The calculations in the query are wrong.

I need help specifying criteria.

I'm getting a "Type conversion failure" error.

The query is too slow.


Troubleshoot update queries

What best describes the problem?

The query didn't perform the update I wanted.

The records aren't the ones I want.

I need help specifying criteria.

An arithmetic calculation in the query design grid returns a null (blank) value.

I'm getting the error message "Operation must use an updatable query."

I'm getting a "Key violation" error.

I'm getting a "Lock violation" error.

I'm getting a "Validation rule violation" error.

I'm getting a "Type conversion failure" error.

I need help determining when I can update data from a query.

The query is too slow.


The query didn't perform the update I wanted.

•	You need to specify a different update by changing the expression in the Update To cell.

For example, if you want to raise salaries by 5 percent, you could type [Salary]*1.05 in the Update To cell of the Salary field. For more examples of expressions in update queries, click  [image].

•	If you're updating data in the wrong field, specify an update for a different field. To specify an update for a field, type the expression you want in the Update To cell.


I'm getting the error message "Operation must use an updatable query."

This error occurs when the current query's Update To row includes a field from either a crosstab query or select query in which an aggregate (total) was calculated for the field (using either the Totals row or a domain function in the Field row). To update a field using the aggregate of another field, calculate the aggregate in the update query itself, not a different query.

1	In the current query, remove the field you added from the crosstab or select query (where an aggregate was calculated for the field).

2	In the Update To cell of the field you want to update, enter a domain function that calculates the same aggregate as is calculated for that field in the select or crosstab query.

For example, if you had a field named Sales So Far in your Products table, you could update it with the product of the Quantity field and UnitPrice field by adding it to the design grid in the update query and then entering the following domain function in its Update To cell:

DSum("[Quantity]*[UnitPrice]","OrderDetails","[ProductID]=" & [ProductID])

3	To run the query, click  [image]  on the toolbar.

For more information on creating an update query, click  [image].


Troubleshoot append queries

What best describes the problem?

The records aren't the ones I want.

The calculations in the query are wrong.

The append query appended data to or from the wrong fields.

I'm getting a "Key violation" error.

I'm getting a "Lock violation" error.

I'm getting a "Validation rule violation" error.

I'm getting a "Type conversion failure" error.

I need help specifying criteria.

The query is too slow.


The append query appended data to or from the wrong fields.

You need to choose the field or fields to and from which you want to append data. Add the following fields to the query design grid for your append query:

•	The fields you want to append.

•	The fields you want to specify criteria for.

•	The field corresponding to the primary key field of the table you're appending records to.

You choose the fields to which you want to append data by adding them in the Append To cell of the fields you want to append.

To add a field to the Append To row:

•	In the Append To cell, click the name of the field you want to add data to.

Note   If you added the asterisk (*) in the Field cell, select the asterisk in the Append To cell. All the field names in both tables must be exactly the same. You can't specify criteria for selecting records in the column that contains the asterisk, but you can specify criteria in a separate column.


Troubleshoot parameter queries

What best describes the problem?

I get prompted for a parameter when I don't expect it.

I want the option to return all records with a parameter query.

I'm getting the error message "Can't bind name name."


I get prompted for a parameter when I don't expect it.

If you get prompted to type parameters when you attempt to run a query or report, and you don't expect this prompt, one of the following might apply:

•	You deleted a parameter from the query design grid but not from the Query Parameters dialog box.

•	You renamed or misspelled a field in the query or report but not in the query's underlying table(s).

•	You have a field that refers to a calculated field. If a field in the query performs a calculation based on the calculated value, make sure the Show box is checked for the calculated field in the query design grid.


I want the option to return all records with a parameter query.

In the design grid under the field that contains the prompt in the Criteria cell, type [prompt] Is Null in the Or cell, where prompt is the same prompt that is in the Criteria cell for that field. For example:

Field:	CategoryID
Criteria:	Like [Enter CategoryID:]
or:	[Enter CategoryID:] Is Null
Now when you run the query, if you leave the Query Parameters dialog box blank, the query returns all records.


Work with duplicate records in query Datasheet view

What do you want to do?

Delete duplicate records

Edit the data in a field

Print the datasheet or selected records


Work with unmatched records in query Datasheet view

What do you want to do?

Delete an unmatched record

Add a matching record in the other table

Print the datasheet or selected records


Add a matching record in the other table

Open the table the wizard checked for records that don't match (the second table you specified in the wizard). Add a matching record.

How?


Work with a crosstab query's datasheet

What do you want to do?

Change the font, font color, size, or style

Change the gridline style or background colors

Resize rows

Resize columns

Create a PivotTable for the current query

Print the datasheet or selected records

Note   You can't edit data in a crosstab query.


Customize a crosstab query

What do you want to do?

Change the order in which column headings appear or limit which column headings are displayed

Specify a sort order

Specify criteria to limit certain records

Exclude records with null (blank) values to avoid getting "<>" as a column heading


Customize a Find Duplicates query

What do you want to do?

Add fields

Remove fields

Add a sort order

Note   You can't convert a Find Duplicates query to a delete query to delete duplicate records. This is because the Find Duplicates query returns the original record and any duplicates of the record so that you can choose which version to delete. Therefore, if you convert it to a delete query, it will delete the original and the duplicates.

There is a way, however, to automatically delete duplicate records while retaining the originals. For more information, click  [image].


 Customize a Find Unmatched query

What do you want to do?

Add fields

Remove fields

Move fields


Reset page numbers for each group in a report

Create a macro that resets page numbers

1	Create a macro that uses the SetValue action to change the Page property to 1.

How?

Decide if the page number will appear in the page header or footer, and then use the following values for the SetValue action arguments.

Location of page number	SetValue arguments
Page header	Item:  [Page] Expression:  0
Page footer	Item:  [Page] Expression:  1
2	Save and close the macro.

Modify the report

1	Create a text box for the page number in the page header or footer if you haven't already done so.

How?

2	For the first-level group header and footer, set the following properties, depending on where the page number appears.

If the page number appears in the page header, set the following properties.

Section	Property	Purpose
Group header	ForceNewPage:  Before Section	Starts each group on a new page.
Group footer	OnFormat:  Name of macro you created in the first procedure	Resets the page number to 1 for the new group.
If the page number appears in the page footer, set the following properties.

Section	Property	Purpose
Group header	OnFormat:  Name of macro you created in the first procedure	Resets the page number to 1 for the new group.
Group footer	ForceNewPage:  After Section	Starts each group on a new page.
Note   The Employee Sales by Country report in the Northwind sample database resets the page number for each country. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


 Customize an autoformat for a form or report

1	Open an existing form or report in Design view.

2	On the Format menu, click AutoFormat.

3	In the AutoFormat dialog box, click an autoformat in the list.

4	Click the Options button, and then make sure the attributes you want to modify are selected.

5	Click the Customize button, and then click a customization option. You can do one of the following:

•	Create a new autoformat based on the open form or report.

•	Update the selected autoformat based on the open form or report.

•	Delete the selected autoformat from the list.

6	Click OK twice to close the dialog boxes.


Create a multiple-column report

1	Create a report.

How?

Notes

•	When a multiple-column report is printed, the report header and footer and page header and footer span the full width of the report, so you can place controls anywhere in these sections in Design view.

•	When printed, the group header and footer and detail section of a multiple-column report span the width of one column. For example, if you want to print the data in two three-inch columns, place the controls within the width of one column; in other words, place the controls in the first three inches of these sections in Design view.

2	On the File menu, click Page Setup.

3	In the Page Setup dialog box, click the Layout tab.

4	Under Grid Settings, in the Items Across box, type the number of columns you want on each page.

5	In the Row Spacing box, type the amount of vertical space you want between each record in the detail section.

Note   If you left space between the last control in the detail section and the bottom edge of the detail section, you can leave Row Spacing set to 0.

6	In the Column Spacing box, type the amount of space you want between the columns.

7	Under Item Size, type the width you want for a column in the Width box; for example, 3 inches. You can set the height of the detail section by typing a number in the Height box or by adjusting the height of the section in Design view.

8	Under Layout Items, click the Down, Then Across option or the Across, Then Down option.

9	Click the Page tab.

10	Under Orientation, click Portrait or Landscape.

11	Click OK.

For information on starting each group in a new row or column, click  [image].


Create a crosstab report with fixed-column headings

1	Create a crosstab query.

How?

2	In query Design view, display the query's property sheet by double-clicking anywhere outside the design grid and outside the field lists.

3	In the ColumnHeadings property box, type the column headings you want to appear in the report, separating each one with a semicolon. If a column heading contains spaces, enclose it in double quotation marks (" "). For instance, in a query showing sales by quarter, you would type:

"Qtr 1";"Qtr 2";"Qtr 3";"Qtr 4"

4	Create a blank report that is bound to the crosstab query.

How?

5	Add the controls for the fields you want to appear in the report.

•	Place labels for the row headings and column headings in the page header.

•	Place text boxes for the row headings and column values in the detail section.


Use a form to enter report criteria

Create an unbound form that prompts for report criteria

1	Create an unbound form.

2	In Design view, set the following form properties.

Property	Setting
BorderStyle	Dialog
Caption	Name you want to appear in the title bar of the form
DefaultView	Single Form
NavigationButtons	No
RecordSelectors	No
ScrollBars	Neither
ViewsAllowed	Form
3	Add an unbound text box for each criterion you want to enter.

4	Set the properties for the text boxes as follows.

Property	Setting
Name	Name that describes the type of criterion; for example, BeginningDate.
Format	Format that reflects the data type of the criterion. For example, for a date criterion, select a format such as Medium Date.
5	Save the form, and give it a name, such as Sales Dialog.

You'll add OK and Cancel command buttons to the form after you create macros for them.

Create the macros for the form in a macro group

1	In the Database window, click the Macros tab, and then click New.

For this procedure, you'll create four macros in a macro group.

2	Create a macro that opens the unbound form. To do this, click  [image]  to display the Macro Name column. Type a macro name, such as Open Dialog, in the Macro Name column, and then click the OpenForm action. Then set the action arguments as follows.

Argument	Setting
Form Name	Name of the unbound form; for example, Sales Dialog
View	Form
Data Mode	Edit
Window Mode	Dialog
Add a second action, CancelEvent, that cancels previewing or printing the report when the Cancel button on the form is clicked. Then click  [image]  to display the Condition column, and type the following expression in the Condition column:

Not IsLoaded("Sales Dialog")

IsLoaded is a function defined in the Utility Functions module in the Northwind sample database. It's used to check whether a form is open in Form or Datasheet view. You must define it in your database before you can use it. For information on defining a function, click [image]. For information on opening Northwind, click  [image].

3	Create a macro that closes the form. Give the macro a name, such as Close Dialog. Click the Close action. Then set its action arguments as follows.

Argument	Setting
Object Type	Form
Object Name	Name of the unbound form
Save	No
4	Create a macro for the OK button. This macro hides the form. Give the macro a name, such as OK, and click the SetValue action. Then set its action arguments as follows.

Argument	Setting
Item	[Visible]
Expression	No
5	Create a macro for the Cancel button. This macro closes the form. Give the macro a name, such as Cancel, and click the Close action. Then set its action arguments as follows.

Argument	Setting
Object Type	Form
Object Name	Name of the unbound form
Save	No
6	Save and close the macro group. Give the macro group a name; for example, the same name that you gave the unbound form.

Add OK and Cancel command buttons to the form

1	Reopen the unbound form in Design view.

2	Create an OK command button, and set its properties as follows. (Make sure  [image]  in the toolbox isn't pressed in.)

Property	Setting
Name	OK
Caption	OK
Default	Yes
OnClick	Name of the macro; for example, Sales Dialog.OK
3	Create a Cancel command button, and set its properties as follows.

Property	Setting
Name	Cancel
Caption	Cancel
OnClick	Name of the macro; for example, Sales Dialog.Cancel
4	Save and close the form.

Enter the criteria in the underlying query for the report

1	Open the underlying query for the report in Design view.

2	Enter the criteria for the data. In the expression, use the Forms object, the name of the form, and the names of the controls in the criteria. For example, for a form called Sales Dialog, you would use the following expression to refer to controls named Beginning Date and Ending Date:

Between [Forms]![Sales Dialog]![Beginning Date] And [Forms]![Sales Dialog]![Ending Date]

Attach the macros to the main report

•	In report Design view, set the following report properties.

Property	Setting
OnOpen	Name of the macro that opens the unbound form; for example, Sales Dialog.Open Dialog
OnClose	Name of the macro that closes the unbound form; for example, Sales Dialog.Close Dialog


Print the criteria for a report in the report header

1	Create the criteria parameters in the report's underlying query.

How?

2	In report Design view, create an unbound text box for each parameter you want to display. To do this, click  [image]  in the toolbox, then click in the report header.

3	Double-click the text box to display its property sheet.

4	Set the ControlSource property to the parameter(s) you specified in the Criteria cell in the query.

For example, if the parameters in the query are

Between [Type a beginning date] And [Type an ending date]

and you want to display them in two text boxes, set the ControlSource property of one text box to

[Type a beginning date]

and the ControlSource property of the other text box to:

[Type an ending date]

If you want to display the parameters in one text box, you can use an expression in the ControlSource property box; for example:

="Between " & [Type a beginning date] & " and " & [Type an ending date]

Microsoft Access displays the parameter values exactly as you typed them in the prompt.

5	To see the criteria, print or preview the report.

Note   The Employee Sales by Country report in the Northwind sample database prints the criteria in the report header. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Create mailing and other types of labels

1	In the Database window, click the Reports tab.

2	Click New.

3	In the New Report dialog box, click Label Wizard.

4	Click the table or query that contains the data for the labels, and then click OK.

5	Follow the directions in the wizard dialog boxes.

If the resulting label report doesn't look the way you want, you can delete the report and run the Label Wizard again.

Notes

•	For information on creating labels for a dot-matrix printer, click  [image].

•	The Customer Labels report in the Northwind sample database shows three-across mailing labels. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Customer Labels, and then click Design. For information on opening Northwind, click  [image].


Create mailing and other types of labels for a dot-matrix printer

Creating labels that print on a dot-matrix or tractor-feed printer usually requires some adjustment to the user-defined page size. Before you create a label report for this type of printer, you must first set the default printer and paper size in the Microsoft Windows Control Panel.

Set the default printer and paper size

1	In the Printers folder in the Microsoft Windows Control Panel, click the icon for the dot-matrix printer, and then click Set As Default on the File menu.

2	On the File menu, click Properties, and then click the Paper tab.

3	Under Paper Size, click the Custom icon.

4	In the User Defined Size dialog box, select the unit of measurement, and then type the width and the length of a label.

To determine the width, measure from the left edge of the leftmost label to the right edge of the rightmost label. To determine the length, measure from the top of the first label to the top of the second. For example, if you use two-across labels that measure 3-by-5 inches, with 0.25 inch between them, set Unit to 0.01 inch, and set Width to 625 and Length to 525.

5	Click OK to save the settings in the User Defined Size dialog box.

6	Click OK to save the settings in the printer's Properties dialog box.

Once you set the printer and paper size, you can create a label report for a dot-matrix printer with the Label Wizard or without a wizard in report Design view. For information on using the Label Wizard, click  [image].

Create a label report without a wizard

1	Create a blank report bound to the table or query that contains the data you want to use.

How?

2	In report Design view, click Page Header/Footer on the View menu to remove the page header and footer. (You need only the detail section for this report.)

3	Adjust the height and width of the detail section to match the height and width of one label.

How?

4	Add text boxes to the detail section, making sure that they don't overlap. (To create margins for the labels, place the text boxes at least 0.2 inch from all edges of the detail section.)

How?

5	On the File menu, click Page Setup. Set the following values in the Page Setup dialog box:

•	On the Page tab, if the dot-matrix printer isn't the default printer, click Use Specific Printer. Then click the Printer button, and click the dot-matrix printer in the list.

•	On the Page tab, under Paper, set Size to User-Defined Size, and set Source to Tractor.

•	On the Margins tab, set all the margins to 0.0 inches.

•	On the Layout tab, under Item Size, select the Same As Detail check box.

If there is more than one label across the page, you must also set the following items under Grid Setting on the Layout tab:

•	In the Items Across box, type the number of labels across.

•	In the Row Spacing box, type the amount of space between the bottom of one label and the top of the next.

•	In the Column Spacing box, type the amount of space between the right edge of one label and the left edge of the next.

Note   When a dot-matrix printer is the default in the Microsoft Windows Control Panel and you have Paper Size set to User-Defined Size, Microsoft Access uses that paper size. If you want to create or print a label or report on a page of a different size, change the user-defined page size in the Microsoft Windows Control Panel before you create or print it.


Start each group in a report in a new row or column

1	Create a multiple-column report.

How?

2	In report Design view, click Page Setup on the File menu.

3	Click the Layout tab. Under Layout Items, do one of the following:

•	To start each group in a new column, click the Down, Then Across option.

•	To start each group in a new row, click the Across, Then Down option.

4	Click OK.

5	Double-click the section selector for the group header or footer to display its property sheet.

6	Set the NewRowOrCol property to one of the following settings.

Setting	Description
None	(Default) The row or column breaks are determined by the setting in the Page Setup dialog box and by the available space on the page.
Before Section	Microsoft Access starts printing the current section (the section for which you're setting the property, such as the group header) in a new row or column. It starts printing the next section, for example, the detail section, in the same row or column.
After Section	Microsoft Access starts printing the current section, such as the group header, in the current row or column. It starts printing the next section, such as a detail section, in the next row or column.
Before & After	Microsoft Access starts printing the current section, such as the group header, in a new row or column. It starts printing the next section, such as the detail section, in the next row or column.
Notes

•	To see an example of a report that starts each group in a new column and an example that starts each group in a new row, click  [image].

•	The Products by Category report in the Northwind sample database starts each group in a new column. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Products by Category, and then click Design. For information on opening Northwind, click  [image].


Subreports - What they are and how they work
Subreports — What they are and how they work

A subreport is a report that's inserted in another report. When you combine reports, one of them must serve as the main report. A main report is either bound or unbound; that is, it is or isn't based on a table, query, or SQL statement.

An unbound main report can serve as a container for unrelated subreports that you want to combine.

You bind the main report to an underlying table, query, or SQL statement when you want to insert subreports that contain information that's related to the data in the main report. For example, you can use the main report to show detail records, such as every sale in a year, and then use a subreport to show summary information, such as the total sales for each quarter.

A main report can also contain data common to two or more parallel subreports. In this case, the subreports contain the detail records related to the common data.

A main report can include subforms as well as subreports, and it can include as many subforms and subreports as you want. Additionally, a main report can contain up to two levels of subforms and subreports. For example, a report can contain a subreport, and that subreport can contain a subform or a subreport. The following table shows the possible combinations of subforms and subreports in a main report.

Level 1	Level 2
Subreport 1	Subreport 2
Subreport 1	Subform 1
Subform 1	Subform 2
Note   The Sales by Category and Sales by Year reports in the Northwind sample database use subreports. To view these reports, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click the name of the report, and then click Design. For information on opening Northwind, click  [image].


Understanding how a main report and subreport are linked

When you insert a subreport that contains information related to data in the main report, the subreport control must be linked to the main report. The link ensures that the records printed in the subreport correspond correctly to the records printed in the main report.

When you create a subreport by using a wizard or by dragging a report or datasheet from the Database window to another report, Microsoft Access automatically synchronizes the main report and subreport if:

•	The reports are based on tables that have relationships that you've set in the Relationships window. If the reports are based on a query or queries, Microsoft Access automatically synchronizes the report and subreport if the underlying tables for the query or queries meet the same condition. As long as the query's underlying table is correctly related to the other underlying table or query, Microsoft Access automatically synchronizes the report and subreport.

•	The main report is based on a table with a primary key and the subreport is based on a table that contains a field with the same name as that primary key and with the same or a compatible data type. If you select a query or queries, the underlying tables in the query or queries must meet the same conditions.

Notes

•	Microsoft Access uses the LinkMasterFields and LinkChildFields properties of the subreport control to link the main report and the subreport. If, for some reason, Microsoft Access doesn't link the report and subreport, you can set these properties directly.

How?

•	For information on setting up relationships, click  [image].

•	For information on creating a primary key, click  [image].


Create a subreport

How you create a subreport depends on whether you want to create a subreport in an existing report or add an existing report to another existing report to create a report and subreport.

What do you want to do?

Create a subreport in an existing report

Add an existing report to another existing report

Find out more about subreports


Create a subreport in an existing report

If the subreport will be linked to the main report, make sure you've set up the table relationships correctly before using this procedure. For more information, click  [image].

1	Open the report you want to use as the main report in Design view.

2	Make sure  [image] in the toolbox is pressed in.

3	Click  [image]  in the toolbox.

4	On the report, click where you want to place the subreport.

5	Follow the directions in the wizard dialog boxes.

When you click the Finish button, Microsoft Access adds a subreport control to your report. It also creates a separate report that is displayed as the subreport.

Notes

•	For information on changing the layout of a subreport, click  [image].

•	For information on referring to the value of a control on a subreport, click  [image].

•	For information on troubleshooting subreports, click  [image].


Add an existing report to another existing report to create a subreport

If the subreport will be linked to the main report,  make sure you've set up the table relationships correctly before using this procedure. For more information, click  [image].

1	Open the report you want to use as the main report in Design view.

2	Make sure  [image] in the toolbox is pressed in.

3	Press F11 to switch to the Database window.

4	Drag a report or datasheet from the Database window to the section you want the subreport to appear in on the main report.

Microsoft Access adds a subreport control to the report.

Notes

•	For information on changing the layout of a subreport, click  [image].

•	For information on referring to the value of a control on a subreport, click  [image].

•	For information on troubleshooting subreports, click  [image].


Link a main report and a subreport

If you create a subreport with the Report Wizard or the Subreport Wizard, Microsoft Access automatically links the main report with the subreport under certain conditions. For more information, click  [image]. If your main report and subreport don't meet these conditions, you can use this procedure to link them.

1	In Design view of the main report, click the subreport control.

2	Click  [image]  on the toolbar to display the property sheet for the subreport control.

3	In the LinkChildFields property box, enter the name of the linking field in the subreport, and in the LinkMasterFields property box, enter the name of the linking field in the main report.

Note   You can't use the name of a control in the LinkChildFields property box.

If you're unsure what the linking field should be, click the Build button to open the Subform/Subreport Field Linker. To enter more than one linking field, separate the field names with semicolons.

Notes

•	The linking fields don't have to appear in the main report or the subreport, but they must be included in the underlying record source. If you use the Report Wizard to create the subreport, Microsoft Access automatically includes the linking fields in the underlying record source even if you don't select them in the wizard.

•	The linking fields must contain the same kind of data and have the same or a compatible data type or field size. For example, an AutoNumber field is compatible with a Number field whose FieldSize property is set to Long Integer.

•	For information on troubleshooting subreports, click  [image].


Change the layout of a subreport

1	In Design view of the main report, make sure the subreport control isn't selected.

2	Double-click inside the subreport control.

Microsoft Access opens the subreport in Design view.

3	Change the design of the subreport.

4	Save and close the subreport.

Notes

•	If you change the width of a subreport, you might also need to adjust the width of the subreport control in the main report.

•	You can also change the layout of the subreport by opening the subreport directly from the Database window.


Customize labels created with the Label Wizard

What do you want to do?

If you want to make major changes to the labels, it's better to create a new label report with the Label Wizard.

You can make minor adjustments to the labels by:

Changing the font of the text in the controls

Changing the font size of the text in the controls

Changing the size of controls

Adding controls

Modifying the page setup options


 Hide duplicate data in a report

1	Create a report with one or more group levels.

2	In report Design view, move the text box for the field you're grouping on from the group header to the detail section.

3	Double-click the text box to display its property sheet.

4	Set the HideDuplicates property to Yes.

5	Remove lines and all other controls from the group header.

6	Double-click the section selector of the group header to display its property sheet.

7	Set the Height property of the group header to 0.

The group name will appear only at the beginning of a new group or at the top of a new page if the group continues for more than one page.


Cancel the printing of a report when it doesn't contain any records

1	In report Design view, double-click the report selector to display the report's property sheet.

2	Set the OnNoData property to [Event Procedure] or to the name of a macro that cancels previewing or printing the report.

•	If you use a macro, use the MsgBox action to display a message that describes why there is no data for the report, and use the CancelEvent action to cancel printing or previewing the report. For information on creating a macro, click  [image].

•	If you use an event procedure, use the MsgBox statement to display a message, and set the Cancel argument of the Report_NoData Sub procedure to True. For information about customizing an event procedure, click  [image].

Note   The Employee Sales by Country report in the Northwind sample database uses an event procedure in the OnNoData property. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Optimizing report and subreport performance

There are several things you can do to make your reports print faster. In addition to the tips listed below, you can use the Performance Analyzer to analyze specific reports in your database. For information on using the Performance Analyzer, click  [image].

Performance Tips

•	Avoid overlapping controls.

•	Use bitmaps and other graphic objects sparingly.

•	Convert unbound object frames that display graphics to image controls.

•	Use black-and-white rather than color bitmaps.

•	Avoid sorting and grouping on expressions.

•	Index fields you sort or group on.

•	Base subreports on queries rather than tables, and include only fields from the record source that are absolutely necessary. Extra fields can decrease subreport performance.

•	Index all the fields in the subreport that are linked to the main report.

•	Index any subreport fields used for criteria.


Create a specific type of control on a report

What do you want to do?

Create a label

Create a text box

Create a check box or option button that isn't included in an option group

Create an option group that includes check boxes or option buttons

Draw a line

Draw a rectangle

Create a subreport

Create a control for a picture or other object created with another application

Create a chart

Create a custom control


There's too much white space in my report.

If a report contains too much blank space, you can reduce the blank space by decreasing the space between sections and controls and by shrinking the space within controls.

To reduce the space between sections and controls

•	Reduce the width of the report.

How?

•	Decrease the height of the sections.

How?

•	Move controls closer together.

How?

To reduce the space within a subform, subreport, or text box

•	Set the CanShrink property of the control to Yes.

How?


The column headings in my subreport don't print.

Microsoft Access doesn't print the page header and footer in a subreport, so if you put the labels for the column headings in the subreport's page header, they won't show up when you print the report.

•	If a subreport will always fit on one printed page, you can put the labels for the column headings in the subreport's report header.

•	If a subreport might span several printed pages, put the labels for the column headings in the subreport's group header, and set the RepeatSection property of the group header to Yes.


What's new with printing and previewing?

Microsoft Access for Windows 95 offers the following enhancements for printing and previewing database objects:

•	New User Interface. Some menus and dialog boxes have been redesigned to make them easier to use and to match those used in other Microsoft Windows 95 applications.

•	The Print dialog box is the same as the one used by other Windows 95 applications.

•	The Print Setup command on the File menu is now called Page Setup.

•	  on the toolbar prints the selected object without displaying the Print dialog box.

•	In report Design view, the Sample Preview command is now called Layout Preview and is available on the View menu and by clicking the arrow next to the View button on the toolbar.

•	The Print Definition command is now called the Documentor command and is available by pointing to the Analyze command on the Tools menu.

•	Preview Multiple Pages. The Pages command on the View menu lets you view up to 12 pages at a time.

•	Expanded Previewing Options. New buttons on the Print Preview toolbar increase the options for previewing objects:

•	  displays one full page.

•	  displays two full pages.

•	The Zoom Control box lists zoom percentages at which you can view the object.


What's new about working with other applications?

Microsoft Access for Windows 95 provides many new features for working with other products.

•	Retain Text Formatting. When you copy or cut data from Microsoft Access forms and datasheets, the settings for font, alignment, and number formatting for column headings and data are retained when you paste them into Microsoft Excel spreadsheets.

•	Output Subreports to Other File Formats. When you output a report with a subreport to a .txt, .rtf, or .xls file format, the subreport is output along with the main report.

•	Format and Print Microsoft Excel Data in Microsoft Access Reports. When you need the grouping and formatting functionality of Microsoft Access reports for data you have in a Microsoft Excel spreadsheet, you can click Access Report on the Data menu in Microsoft Excel to start the Microsoft Access Report Wizard. For details, see the Help provided with Microsoft Excel.

•	Enter Microsoft Excel Data Using a Microsoft Access Form. When you want to enter data in a Microsoft Excel spreadsheet using a form that has complex formatting, check boxes, list boxes, and text boxes with specific data types, you can click Access Form on the Data menu in Microsoft Excel to start the Microsoft Access Form Wizard. For details, see the Help provided with Microsoft Excel.

•	Permanently Move Microsoft Excel Data into Microsoft Access. When a Microsoft Excel spreadsheet is no longer the appropriate tool for your data, you can create a Microsoft Access database from the spreadsheet by clicking Convert To Access on the Data menu in Microsoft Excel. For details, see the Help provided with Microsoft Excel.

•	Create a PivotTable Control in a Microsoft Access Form. Using the PivotTable Wizard, you can create a control on a form that allows you to summarize large amounts of data using a format and calculation method you choose. A PivotTable is like a crosstab query, but you can switch the row and column headings dynamically to see a different view of the data. (To take advantage of this wizard, you need to have Microsoft Excel installed.) For information on creating a PivotTable, click  [image].

•	Link a Spreadsheet. You can link data from a Microsoft Excel or a Lotus 1-2-3 spreadsheet as long as the data is arranged in an appropriate tabular format. For information on linking to a spreadsheet, click  [image].

•	Use Microsoft Access as an OLE Automation Server. When you use Microsoft Access as an OLE Automation Server, you can manipulate Microsoft Access objects from another application, such as Microsoft Excel. For more information on OLE Automation, click  [image], and then click Specifics.

•	Drag and Drop Database Objects. The following drag-and-drop functionality is now available in Microsoft Access:

•	You can drag and drop database objects between open Microsoft Access databases. (You must have two instances of Microsoft Access running.)

•	You can drag and drop Microsoft Access tables and queries into other applications, such as Microsoft Word and Microsoft Excel.

•	You can create a table by dragging and dropping a range of cells from a Microsoft Excel spreadsheet into the Database window.

•	You can drag and drop OLE objects into an OLE Object field in a form in Form view or into a form or report in Design view.


Example of a crosstab report with dynamic column headings

The EmployeeSales report in the Solutions sample application prints column headings dynamically. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: EmployeeSales.

For information on opening the Solutions sample application, click  [image].


Example of setting report criteria in a dialog box

The EmployeeSales report in the Solutions sample application uses a dialog box to prompt for criteria. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: EmployeeSales.

For information on opening the Solutions sample application, click  [image].


Example of printing first and last entries on a page in the page header

The CustomerPhoneList report in the Solutions sample application prints the first and last entries on a page in the page header. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: CustomerPhoneList.

For information on opening the Solutions sample application, click  [image].


Example of a form letter

The SalesLetter report in the Solutions sample application prints a standard message as well as information that changes for every recipient.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: SalesLetter.

For information on opening the Solutions sample application, click  [image].


Example of drawing a circle around data

The SalesLetter report in the Solutions sample application draws a circle around data that meets a specified criterion. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: SalesLetter.

For information on opening the Solutions sample application, click  [image].


Example of a multiple-column report

The ShippingLog report in the Solutions sample application prints data in two columns, and repeats a group header when the detail records for the group continue onto another column or page.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: ShippingLog.

For information on opening the Solutions sample application, click  [image].


Example of a multiple-fact crosstab report

The SalesAverages report in the Solutions sample application prints multiple facts for each row heading in a crosstab report. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: SalesAverages.

For information on opening the Solutions sample application, click  [image].


Example of a report that prints on a preprinted form

The Invoice report in the Solutions sample application is designed to print on a preprinted form. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: Invoice.

For information on opening the Solutions sample application, click  [image].


Example of printing a message at the bottom of a preprinted form

The Invoice report in the Solutions sample application prints a message at the bottom of a page when the invoice continues onto another page. This report uses event procedures, which you can copy to your database and customize to fit your needs.

To view this report, open the Solutions sample application. In the opening form, click the entry in the upper list box that reads: Sample reports. In the lower list box, double-click the entry that reads: Invoice.

For information on opening the Solutions sample application, click  [image].


Create a report

You can create a report on your own or you can have Microsoft Access create a report for you using a Report Wizard. A Report Wizard speeds up the process of creating a report because it does all the basic work for you. When you use a Report Wizard, it prompts you for information and creates a report based on your answers. Even if you've created many reports, you may want to use a Report Wizard to quickly lay out your report. Then you can switch to Design view to customize it.

What do you want to do?

Create a report using AutoReport

Create a report with a wizard

Create a report on your own

Create a report based on more than one table


Create a report using AutoReport

AutoReport creates a report that displays all fields and records in the underlying table or query.

1	In the Database window, click the Reports tab.

2	Click New.

3	In the New Report dialog box, click one of the following wizards:

•	AutoReport: Columnar — Each field appears on a separate line with a label to its left.

•	AutoReport: Tabular — The fields in each record appear on one line, and the labels print once at the top of each page.

4	Click the table or query that contains the data you want to base your report on.

5	Click OK.

Notes

•	You can also create a report by selecting a table or query in the Database window and then either clicking AutoReport on the Insert menu or clicking the arrow next to the New Object button on the toolbar, and then clicking AutoReport. Microsoft Access creates a single-column report based on the open table or query or the table or query selected in the Database window.

•	Microsoft Access applies the last autoformat you used to the report. If you haven't created a report with a wizard before or haven't used the AutoFormat command on the Format menu, it uses the Win95 autoformat.


Create a report with a wizard

1	In the Database window, click the Reports tab.

2	Click New.

3	In the New Report dialog box, click the wizard that you want to use. A description of the wizard appears in the left side of the dialog box.

4	Click the table or query that contains the data you want to base your report on.

Note   Microsoft Access uses this table or query as the default record source for the report. However, you can change the record source in the wizard and select fields from other tables and queries.

5	Click OK.

6	If you clicked Report Wizard, Chart Wizard, or Label Wizard in step 3, follow the directions in the wizard dialog boxes. If you click AutoReport: Tabular or AutoReport: Columnar, Microsoft Access automatically creates your report.

If the resulting report doesn't look the way you want, you can change it in Design view.

How?


Create a report without a wizard

1	In the Database window, click the Reports tab.

2	Click New.

3	In the New Report dialog box, click Design View.

4	Click the name of the table or query that contains the data you want to base your report on. (If you want an unbound report, don't select anything from this list.)

Tip   If you want to create a report that uses data from more than one table, base your report on a query.

5	Click OK.

Microsoft Access displays the Report window in Design view. For information on what you can do in Design view, click [image].


Create a report based on more than one table

Using the Report Wizard is the simplest and fastest way to create a report that brings data together from more than one table. The Report Wizard speeds up the process of creating a report because it does all the basic work for you. In the first screen of the Report Wizard, you can pick the fields you want to include in your report. These fields can be from one table or from multiple tables. When you use the Report Wizard to create a multiple-table report, Microsoft Access creates an SQL statement behind the report. The SQL statement includes the information about which tables and fields to use.

If you want to create a report on your own, you can create a query and base the report on it.

What do you want to do?

Create a report with a wizard

Create a query

Create a report on your own and use a query as its record source


Open a report

1	In the Database window, click the Reports tab.

2	Click the report you want to open.

3	Click the Design button to open the report in Design view, or click the Preview button to open the report in Print Preview.

Tip   You can also open a report in Print Preview by dragging the report from the Database window to the application workspace.


Switch between views of a report

Reports have three views: Design view, Print Preview, and Layout Preview. You use Design view to create a report or change the structure of an existing report. You use Print Preview to view the report's data as it will appear on every page. You use Layout Preview to view the report's layout, which includes just a sample of the data in the report.

To view a report's design from Print Preview or Layout Preview

•	On the View menu, click Report Design.

To preview a report from Design view

•	On the toolbar, click the View button, and then click one of the following:

To see	Click
The data on  every page of  the report	Print  Preview
The report's  layout	Layout Preview


Add the current date and time to a form or report

1	In form or report Design view, click Date And Time on the Insert menu.

2	To include a date, select the Include Date check box, and then click a date format.

3	To include the time, select the Include Time check box, and then click a time format.

Microsoft Access adds a text box to the form or report and sets its ControlSource property to an expression. If there is a form or report header, Microsoft Access adds the text box to that section. Otherwise, it adds the text box to the detail section.


Add page numbers to a form or report

1	In form or report Design view, click Page Number on the Insert menu.

2	In the Page Numbers dialog box, select the format, position, and alignment for the page number. For alignment, the following options are available:

•	Left — adds a text box at the left margin.

•	Center — adds a text box centered between the left and right margins.

•	Right — adds a text box at the right margin.

•	Inside — adds text boxes at the left and right margins. Odd page numbers print on the left and even page numbers print on the right.

•	Outside — adds text boxes at the left and right margins. Even page numbers print on the left and odd page numbers print on the right.

3	To show a number on the first page, select the Show Number On First Page check box.

Microsoft Access uses an expression to create the page numbers. For examples of other page number expressions, click  [image].


Examples of expressions for page numbers

The following table lists examples of page number expressions you can use in form or report Design view and the results that you see in other views.

Expression	Result
=[Page]	1, 2, 3
="Page " & [Page]	Page 1, Page 2, Page 3
="Page " & [Page] & " of " & [Pages]	Page 1 of 3, Page 2 of 3, Page 3 of 3
=[Page] & " of " & [Pages] & " Pages"	1 of 3 Pages, 2 of 3 Pages, 3 of 3 Pages
=[Page] & "/"& [Pages] & " Pages"	1/3 Pages, 2/3 Pages, 3/3 Pages
=[Country] & " - " & [Page]	UK - 1, UK - 2, UK - 3
=Format([Page], "000")	001, 002, 003


Make a text box grow or shrink to fit data during printing

1	In form or report Design view, double-click the text box to display the property sheet.

2	Set the CanGrow or CanShrink property to Yes.

•	CanGrow expands the text box vertically to fit the data in the field when the form or report is printed.

•	CanShrink reduces the text box vertically if there is no data in the field when the form or report is printed.

To see examples of text boxes that grow or shrink, click  [image].

Notes

•	When you set the CanGrow property to Yes for a text box, Microsoft Access automatically sets CanGrow to Yes for the section.

•	The Catalog and Invoice reports in the Northwind sample database have examples of text boxes that shrink and grow. To view these reports, open the Northwind database in your Microsoft Access program directory's Samples directory. In the Database window, click the Reports tab, click the report you want to see, and then click Design. For information on opening Northwind, click  [image].


Examples of text boxes that grow or shrink to fit data during printing

You can make a text box adjust vertically to the size of the data in the field for each record by setting the CanGrow and CanShrink properties to Yes. For example, a Memo field can contain values that are very long. You can make the text box large enough to accommodate most of the entries and set CanGrow to Yes, so that when the form or report is printed, the text box grows to fit longer entries. If a field has no values in some records, you can set CanShrink to Yes to avoid blank lines.

When a text box grows or shrinks, the entire section grows or shrinks vertically across its entire width. For that reason, the placement and height of the text box in relation to the controls beside it are important.

A text box can't shrink to a height that's less than the other controls on the same line. For example, if you have a label beside a text box, the label will always have a value (its caption) even when the text box doesn't have a value. The text box will shrink only to the same height as the label.


Add a page break to a report

In reports, you use a page break control to mark where you want to start a new page within a section. For example, if you want a report's title page and introductory message printed on separate pages, place a page break in the report header after the controls that you want to appear on the title page and before the controls for the second page.

1	In Design view, click  [image]  in the toolbox.

2	Click the report where you want to place the page break. Place the page break above or below a control to avoid splitting data in that control.

Microsoft Access marks the page break with a short dotted line on the left edge of the report.

If you want each group or record in a report to start on a new page, set the ForceNewPage property of the group header, group footer, or detail section.

How?

Note   The Catalog report in the Northwind sample database has an example of using a page break in the report header. To view this report, open the Northwind database in your Microsoft Access program directory's Samples directory. In the Database window, click the Reports tab, click Catalog, and then click Design. For information on opening Northwind, click  [image].


Add a background picture to a report

By adding a background picture to a report, you can simulate a watermark. A background picture in a report applies to the entire page.

1	In Design view, double-click the report selector to open the property sheet.

2	Set the Picture property to a .bmp, .ico, .wmf, .dib, or .emf file. If you've installed graphics filters for other applications, you can use any file supported by those filters. If you're not sure of the path or filename, click the Build button.

3	In the PictureType property box, specify whether you want the picture to be embedded or linked. When you embed a picture, it's stored in the database file. If you embed the same picture in another form or report, it's added to the database file again. When you link a picture, you don't store it in the database file, but you must keep a copy of it on your hard disk. If you want to use your hard disk space efficiently, specify the Linked setting.

4	You can determine the proportions of the picture by setting the PictureSizeMode property. This property has three settings.

Setting	Description
Clip	Displays the picture at actual size. If the picture is larger than the area within the margins, the image is cut off.
Stretch	Sizes the picture to fit the area within the margins. This setting may distort the image.
Zoom	Sizes the picture to fill either the height or width of the area within the margins. This setting won't clip the picture or distort its proportions.
5	You can specify the position of the picture on the page by setting the PictureAlignment property. Microsoft Access aligns the picture within the margins of the report. The available settings are Top Left, Top Right, Center, Bottom Left, and Bottom Right.

6	You can repeat the picture across the page by setting the PictureTiling property to Yes. Tiling starts at the position specified in the PictureAlignment property.

Note   Background pictures look best tiled when the PictureSizeMode property is set to Clip.

7	You can determine which pages of the report the picture will appear on by setting the PicturePages property. The available settings are All Pages, First Page, and No Pages.

Notes

•	If the colors in the background picture don't look the same as the original colors, you can specify that Microsoft Access use the colors from the application you used to create the graphic.

How?

•	If you're creating your own background pictures and you have access to a graphics program that creates metafiles, you may want to use a metafile as a background picture rather than a bitmap. For more information, click  [image].

•	The Employee Sales by Country report in the Northwind sample database has an example of a background picture. To view this report, open the Northwind database in your Microsoft Access program directory's Samples directory. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Specify a new template for forms and reports

1	On the Tools menu, click Options.

2	Click the Forms/Reports tab.

3	Type the name of the new template in the Form Template or Report Template box.

Note   You can use an existing form or report as a template, or you can create a form or report specifically for use as a template.

4	Click OK.

For more information about templates, click  [image].


Form and report templates

When you create a form or report without using a wizard, Microsoft Access uses a template to define the default characteristics of the form or report.

The template determines which sections a form or report will have and defines each section's dimensions. The template also contains all the default property settings for the form or report and its sections and controls.

The default templates for forms and reports are called Normal. However, you can use any existing form or report as a template. You can also create a form or report to use only as a template. For information on specifying a new template, click  [image].

Notes

•	Changing the template doesn't have any effect on existing forms or reports.

•	A template doesn't create controls on a new form or report.

•	Microsoft Access saves the settings for the Form Template and Report Template options in your Microsoft Access workgroup information file, not in your user database (the .mdb file). When you change an option setting, the change applies to any database you open or create.

•	To use your templates in other databases, copy or export the templates to them. If your templates are not in a database, Microsoft Access uses the Normal template for any new forms and reports you create. However, the names of your templates appear in the Form Template and Report Template options in every database in your database system, even if the templates are not in every database.


Examples of expressions used in calculated controls

What do you want to do?

See examples of expressions that use text values

See examples of expressions for page numbers

See examples of expressions that use arithmetic operators

See examples of expressions that refer to values of controls

See examples of expressions that count, sum, and average values using aggregate functions

See examples of expressions that count, sum, and look up values using domain aggregate functions

See examples of expressions that use date functions

See examples of expressions that return one of two possible values

Learn how to create an expression


Examples of using text values in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

Expression	Description
="N/A"	Displays N/A.
=[FirstName] & " " & [LastName]	Displays the values of the FirstName and LastName controls separated by a space.
=Left([ProductName], 1)	Uses the Left function to display the first character of the value of the ProductName control.
=Right([AssetCode], 2)	Uses the Right function to display the last 2 characters of the value of the AssetCode control.
=Trim([Address])	Uses the Trim function to display the value of the Address control, removing any leading or trailing spaces.
=IIf(IsNull([Region]), [City] & " " & [PostalCode], [City] & " " & [Region] & "  " & [PostalCode])	Uses the IIf function to display the values of the City and PostalCode controls if Region is null; otherwise, it displays the values of the City, Region, and PostalCode controls, separated by spaces.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.


Examples of using arithmetic operators in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

If you use this expression	Microsoft Access displays
=[Subtotal]+[Freight]	The sum of the values of the Subtotal and Freight controls.
=[RequiredDate]-[ShippedDate]	The difference between the values of the RequiredDate and ShippedDate controls.
=[Price]*1.06	The product of the value of the Price control and 1.06 (adds 6 percent to the Price value).
=[Quantity]*[Price]	The product of the values of the Quantity and Price controls.
=[EmployeeTotal]/[CountryTotal]	The quotient of the values of the EmployeeTotal and CountryTotal controls.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.

•	When you use an arithmetic operator (+, -, *, /) in an expression and the value of one of the controls in the expression is null, the result of the entire expression will be null. If some records in one of the controls you used in the expression might have a null value, you can convert the null value to zero using the Nz function; for example:

=Nz([Subtotal])+Nz([Freight])

For more information on the Nz function, click  [image].


Examples of using aggregate functions in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

Expression	Description
=Avg([Freight])	Uses the Avg function to display the average of the values of the Freight control.
=Count([OrderID])	Uses the Count function to display the number of records in the OrderID control.
=Sum([Sales])	Uses the Sum function to display the sum of the values of the Sales control.
=Sum([Quantity]*[Price])	Uses the Sum function to display the sum of the product of the values of the Quantity and Price controls.
=[Sales]/Sum([Sales])*100	Displays the percentage of sales, determined by dividing the value of the Sales control by the sum of all the values of the Sales control. Note   If the control's Format property is set to Percent, don't include the *100.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.

•	You can't use the name of a control in an expression that uses an aggregate function; you must use only field names from a table, query, or SQL statement. For information on using aggregate functions with calculated controls, click  [image].


Examples of referring to values in controls in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms.

If you use this expression	Microsoft Access displays
=Forms![Orders]![OrderID]	The value of the OrderID control on the Orders form.
=Forms![Orders]![Orders Subform]![OrderSubtotal]	The value of the OrderSubtotal control on the Orders Subform on the Orders form.
=Forms![Orders]![Orders Subform]![Price]*1.06	The product of the value of the Price control on the Orders Subform on the Orders form and 1.06 (adds 6 percent to the value of the Price control).
=Parent![OrderID]	The value of the OrderID control on the main or parent form of the current subform.
The following table lists examples of expressions you can use in calculated controls on reports.

If you use this expression	Microsoft Access displays
=Reports![Invoice]![OrderID]	The value of the OrderID control on the Invoice report.
=Reports![Summary]![Summary Subreport]![SalesTotal]	The value of the SalesTotal control on the Summary Subreport on the Summary report.
=Parent![OrderID]	The value of the OrderID control on the main or parent report of the current subreport.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.


Examples of using domain aggregate functions in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

Expression	Description
=DLookup("[ContactName]", "[Suppliers]", "[SupplierID] = Forms![SupplierID]")	Uses the DLookup function to display the value of the ContactName field in the Suppliers table where the value of the SupplierID field in the table matches the value of the SupplierID control on the active form.
=DLookup("[ContactName]", "[Suppliers]", "[SupplierID] = Forms![New Suppliers]![SupplierID]")	Uses the DLookup function to display the value of the ContactName field in the Suppliers table where the value of the SupplierID field in the table matches the value of the SupplierID control on the New Suppliers form.
=DSum("[OrderAmount]", "[Orders]", "[CustomerID] = 'RATTC'")	Uses the DSum function to display the sum total of values of the OrderAmount field in the Orders table where the CustomerID is RATTC.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.

•	You can't use the name of a control in an expression that uses a domain aggregate function; you must use only field names from a table, query, or SQL statement. For information on using domain aggregate functions with calculated controls, click  [image].


Examples of returning one of two values in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

Expression	Description
=IIf([Confirmed] = "Yes", "Order Confirmed", "Order Not Confirmed")	Uses the IIf function to display the message "Order Confirmed" if the value of the Confirmed control is Yes; otherwise, it displays the message "Order Not Confirmed."
=IIf(IsNull([Country]), " ", [Country])	Uses the IIf function to display an empty string if the value of the Country control is null; otherwise, it displays the value of the Country control.
=IIf(IsNull([Region]), [City] & " " & [Postal Code], [City] & " " & [Region] & "  " & [Postal Code])	Uses the IIf function to display the values of the City and PostalCode controls if Region is null; otherwise, it displays the values of the City, Region, and PostalCode controls.
=IIf(IsNull([RequiredDate] - [ShippedDate]), "Check for a missing date", [RequiredDate] - [ShippedDate])	Uses the IIf function to display the message "Check for a missing date" if the result of subtracting ShippedDate from RequiredDate is null; otherwise, it displays the difference between the values of the RequiredDate and ShippedDate controls.
Notes

•	In a calculated control, precede each expression with the = operator.

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.


Examples of using date functions in calculated control expressions

The following table lists examples of expressions you can use in calculated controls on forms and reports.

Expression	Description
=Date()	Uses the Date function to display the current date in the form of mm-dd-yy, where mm is the month (1 through 12), dd is the day (1 through 31), and yy is the last two digits of the year (1980 through 2099).
=Format(Now(), "ww")	Uses the Format function to display the number of the week of the year the current date represents, where ww is 1 through 53.
=DatePart("yyyy", [OrderDate])	Uses the DatePart function to display the four-digit year of the value of the OrderDate control.
=DateAdd("y", -10, [PromisedDate])	Uses the DateAdd function to display a date that is 10 days before the value of the PromisedDate control.
=DateDiff("d", [OrderDate], [ShippedDate])	Uses the DateDiff function to display the number of days' difference between the values of the OrderDate and ShippedDate controls.
Notes

•	In a calculated control, precede each expression with the = operator .

•	When you set the Name property of a calculated control, make sure you use a unique name. Don't use the name of one of the controls you used in the expression.


 Calculate a total for one record in a report

1	In report Design view, add a calculated text box to the detail section.

How?

2	Double-click the text box to display its property sheet.

3	Do one of the following:

•	In the ControlSource property box, type an appropriate expression.

•	Click the Build button to use the Expression Builder to create the expression.

Notes

•	If a report is based on a query, you can put the expression in the report's underlying query. It may improve the report's performance, and if you are going to calculate totals for groups of records, it's easier to use the name of a calculated field in an aggregate function. For more information, click  [image].

•	For examples of other expressions you can use to calculate values for one record, click  [image].

•	For more information on creating expressions, click  [image].


Calculate a total for a group of records or all records in a report

1	In report Design view, add a calculated text box to one or more of the following sections:

How?

•	To calculate a total for a group of records, add a text box to the group header or footer.

•	To calculate a grand total for all records in the report, add a text box to the report header or footer.

2	Double-click the text box to display its property sheet.

3	Do one of the following:

•	In the ControlSource property box, type an expression that uses the Sum function.

•	Click the Build button to use the Expression Builder to create the expression.

Notes

•	For more information on creating expressions, click  [image].

•	For more information on calculating totals using aggregate functions such as Sum, click  [image].

•	For examples of expressions that use aggregate functions, click  [image].

•	The Employee Sales by Country report in the Northwind sample database has an example of group totals and a grand total. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Number each detail record in a report

1	In report Design view, add a calculated text box to the detail section.

How?

2	Double-click the text box to display its property sheet.

3	Set the ControlSource property to =1.

4	Set the RunningSum property to Over All.

When you preview or print the report, each record number will be incremented by 1 (1, 2, 3...).

Note    The Sales by Year report in the Northwind sample database has an example of numbered detail records. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Sales by Year, and then click Design. For information on opening Northwind, click  [image].


Count the number of records in each group in a report

1	In report Design view, add a calculated text box to the detail section.

How?

2	Double-click the text box to display its property sheet.

3	Set the following properties.

Property	Setting
Name	RecordCount
ControlSource	=1
RunningSum	Over Group
Visible	No
4	Add a calculated text box to the group footer.

5	Double-click the text box to display its property sheet.

6	Set the ControlSource property to the name of the control in the detail section that's tracking the running total; for example, =[RecordCount].


Count the number of records in a report as a whole

1	In report Design view, add a calculated text box to the report header or footer.

How?

2	Set the ControlSource property of the text box to =Count(*). This expression uses the Count function to count all the records in the report even if some fields in some records are null. For information on the Count function, click  [image].


Calculate a running sum in a report

1	In report Design view, add a text box to one or more of the following sections.

How?

•	To calculate a running sum that increases for each record, add a bound text box or a calculated text box to the detail section.

•	To calculate a running sum that increases for each group of records, add a bound text box or a calculated text box to the group header or footer.

2	Double-click the text box to display the property sheet.

3	Set the RunningSum property according to the type of running total you want.

This setting	Creates a running total that
Over Group	Resets to 0 at the beginning of each higher group level.
Over All	Accumulates until the end of the report.
Notes

•	To see an example of a report that calculates running sums, click  [image].

•	When you set the RunningSum property to Over All, you can repeat the grand total in the report footer. Create a text box in the report footer and set its ControlSource property to the name of the text box that calculates the running sum; for example, =[OrderAmount].


Example of a report that calculates running sums

You can calculate running sums that accumulate within each group and are reset each time a new group of records begins. You can also calculate running sums that accumulate throughout the report.

In the following illustration, for the two fields on the right that are bound to the Subtotal field, the RunningSum property is set to Over Group and Over All, respectively.

In the following printed report, you can see how Microsoft Access calculates the running sums.


Calculate percentages in a report

1	In report Design view, add the text boxes that calculate the record total, the group total, and the grand total.

How?

2	To the appropriate section, add the text box that calculates the percentage.

•	To calculate what percentage of a group total or the grand total each item is, place the control in the detail section.

•	To calculate what percentage of the grand total a group of items is, place the text box in the group header or footer.

If your report includes multiple group levels, place the text box in the header or footer of the level for which you want Microsoft Access to calculate a percentage.

3	Double-click the text box to display the property sheet.

4	Do one of the following:

•	In the ControlSource property box, type an expression that divides the smaller total by the larger total of which the smaller total is a part. For example, divide the value of the DailyTotal control by the value of the GrandTotal control.

•	Click the Build button to use the Expression Builder to create the expression.

5	Set the Format property of the text box to Percent.

Notes

•	For more information on creating expressions, click  [image].

•	The Employee Sales by Country report in the Northwind sample database has an example of percentages. To view this report, open the Northwind database in the Samples subfolder of the Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Combine text values from multiple fields on a form or report

1	In form or report Design view, add a calculated text box for the fields you want to combine.

 How?

2	Double-click the text box to display its property sheet.

3	Do one of the following:

•	In the ControlSource property box, type an expression that combines the appropriate fields.

•	Click the Build button to use the Expression Builder to create the expression.

For example, to return an address like

507 20th Ave. E., Seattle WA  98122

type this expression:

=[Address] & ", " & [City] & " " & [Region] & "  " & [PostalCode]

Notes

•	For more information on creating expressions, click  [image].

•	For information on compensating for fields that might include Null values in some records, click  [image].

•	The Employee Sales by Country and Customer Labels reports in the Northwind sample database have examples of combining text values. To view these reports, open the Northwind database in the Samples subfolder of the Microsoft Access program folder. In the Database window, click the Reports tab, click the report's name, and then click Design. For information on opening Northwind, click  [image].


Combining text values from multiple fields when some fields contain no data

When you combine text values from several fields, some records might contain empty fields, resulting in output that might not be what you want. For example, the output might include extra spaces.

To compensate for records that don't have values in certain fields, you can use the IIf function. You use the IIf function when you want the value (or absence of a value) in one field to determine which one of two possible results you want returned.

For example, if you know that not every record will have a value in the Region field, use the following expression:

=[Address] & ", " & [City] & IIf(IsNull([Region]),"", " " & [Region]) & "  " & [PostalCode]

If the Region field is empty, Microsoft Access returns no value, as specified by the argument "". If the Region field contains a value, Microsoft Access returns a space and the region, as specified by the argument " " & [Region].

Notes

•	For more information of the Ilf function, click  [image].

•	The Invoice report in the Northwind sample database has an example of combining values from text fields using the IIf function. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Invoice, and then click Design. For information on opening Northwind, click  [image].


Computing a total for a calculated control on a form or report

When computing a total with an aggregate function such as Sum or a domain aggregate function such as DSum, you can't use the name of a calculated control in the Sum function. You must repeat the expression in the calculated control. For example:

=Sum([Quantity]*[UnitPrice])

However, if you have a calculated field in an underlying query, for example,

=ExtendedPrice: [Quantity]*[UnitPrice]

you can use the name of that field in the Sum function, as shown here:

=Sum([ExtendedPrice])

Notes

•	For information on creating a calculated field in a query, click  [image].

•	For more information on the Sum function, click  [image].

•	For more information on the DSum function, click  [image].


Print the first few letters or numbers of a value as a group header in a report

1	In report Design view, set the properties in the Sorting And Grouping box as follows:

Property	Setting
Field/Expression	(Select a field or type an expression)
GroupHeader	Yes
GroupFooter	Yes or No
GroupOn	Prefix Characters
GroupInterval	(Type the number of characters)
KeepTogether	(Select an option)
2	Add a calculated text box to the group header.

 How?

3	Double-click the text box to display its property sheet.

4	Do one of the following:

•	In the ControlSource property box, type the expression (using the Left or Right function) that will extract the appropriate characters.

•	Click the Build button to use the Expression Builder to create the expression.

For example, if you're tracking office equipment and furniture, and the asset number includes an alphabetic code for distinguishing one type of asset from another (for example, FR100 for furniture), you could use an expression similar to the ones in the following table.

This expression	Returns this value
=Left([AssetCode], 2)	FR
=Right([AssetCode], 3)	100
Notes

•	For more information on creating expressions, click  [image].

•	For more information on the Left function, click  [image].

•	For more information on the Right function, click  [image].

•	The Alphabetical List of Products report in the Northwind sample database has an example of printing the first letter of each group of products in the group header. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Alphabetical List of Products, and then click Design. For information on opening Northwind, click  [image].


Sort records in a report

You can sort on up to 10 fields or expressions in a report. To see an example of sorted records in a report, click  [image].

1	In report Design view, click  [image] on the toolbar to display the Sorting And Grouping box.

2	In the first row of the Field/Expression column, select a field name, or type an expression.

The field or expression in the first row is the first sorting level (the largest set). The second row is the second sorting level, and so on.

When you fill in the Field/Expression column, Microsoft Access sets the Sort Order to Ascending. Ascending order sorts from A to Z or 0 to 99.

3	To change the sort order, select Descending from the Sort Order list. Descending order sorts from Z to A or 99 to 0.

Note   The Customer Labels report in the Northwind sample database sorts records by the values in three fields. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Customer Labels, and then click Design. For information on opening Northwind, click  [image].


Group records in a report

You can group on up to 10 fields or expressions in a report. To see an example of grouped records, click  [image].

1	In report Design view, display the Sorting And Grouping box, and set the sort order for the data in the report.

  How?

2	Click the field or expression whose group properties you want to set.

3	Set the group properties listed in the following table. You must set either GroupHeader or GroupFooter to Yes in order in order to create a group level and set the other grouping properties.

Use this property	To
GroupHeader	Add or remove a group header for the field or expression.
GroupFooter	Add or remove a group footer for the field or expression.
GroupOn	Specify how you want the values grouped. The options you see depend on the data type of the field on which you're grouping. If you group on an expression, you see all the options for all data types.
GroupInterval	Specify any interval that is valid for the values in the field or expression you're grouping on.
KeepTogether	Specify whether Microsoft Access prints all or only part of a group on one page.
For information on grouping on Text fields, click  [image].

For information on grouping on Date/Time fields, click  [image].

For information on grouping on AutoNumber, Currency, or Number fields, click  [image].

Note   The Employee Sales by Country report in the Northwind sample database has two group levels. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Employee Sales by Country, and then click Design. For information on opening Northwind, click  [image].


Change sorting and grouping order in a report

1	In report Design view, click  [image] on the toolbar to display the Sorting And Grouping box.

2	In the Sorting And Grouping box, click the row selector of the field or expression you want to move.

3	Click the selector again, and drag the row to a new location in the list.

If the groups you're rearranging have headers or footers, Microsoft Access moves the headers, footers, and all the controls in them to their new positions. However, you must adjust the locations of the controls in the headers and footers yourself.


Insert an additional sorting or grouping field or expression in a report

1	In report Design view, click  [image] on the toolbar to display the Sorting And Grouping box.

2	In the Sorting And Grouping box, click the selector of the row where you want to insert the new field or expression, and then press INS.

3	In the Field/Expression column of the blank row, select the field you want to sort on, or type an expression.

When you fill in the Field/Expression column, Microsoft Access sets the Sort Order to Ascending.

4	To change the sort order, select Descending from the Sort Order list.


Delete a sorting or grouping field or expression in a report

1	In report Design view, click  [image] on the toolbar to display the Sorting And Grouping box.

2	In the Sorting And Grouping box, click the row selector of the field or expression you want to delete, and then press DEL.

3	Click OK to delete the sorting or grouping level, or click Cancel to keep it.

Note  If the field or expression you delete has a header or footer, Microsoft Access deletes the header or footer and its controls.


Grouping records on text values in a report

When you group records on a Text field, you can set the GroupOn property to the ranges listed in the following table. If you set the GroupOn property to Prefix Characters, you can set the GroupInterval property to any number that's valid for the value in the field you're grouping on. If you set the GroupOn property to Each Value, the GroupInterval value is 1.

Set the GroupOn  property to	To group records
Each Value	That contain the same value in the field or expression.
Prefix Characters	That contain the same first n number of characters in the field or expression.
The following table lists the sorting and grouping specifications for this report. Product Name in the first row of the Field/Expression column in the Sorting And Grouping box groups the records by the first letter of the product names. Product Name in the second row sorts the records alphabetically by product name under each letter.

Field/ Expression	Sort  Order	Group Header	Group Footer	Group  On	Group Interval	Keep Together
Product  Name	Ascending	Yes	Yes	Prefix Characters	1	Whole Group
Product  Name	Ascending	No	No	Each Value	1	No
Notes

•	To print the first letter of each group in the group header, you use the Left function. For more information, click  [image].

•	You can look at the Alphabetical List of Products report in the Northwind sample database. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Alphabetical List of Products, and then click Design. For information on opening Northwind, click  [image].


Grouping records on date or time values in a report

When you group records on a Date/Time field, you set the GroupOn property to one of the ranges listed in the following table. For all ranges except Each Value, you can set the GroupInterval property to any number that is valid for the values in the field or expression you're grouping on. If you set the GroupOn property to Each Value, the GroupInterval value is 1.

Set the GroupOn property to	To group records with
Each Value	The same value in the field or expression.
Year	Dates in the same calendar year.
Qtr	Dates in the same calendar quarter.
Month	Dates in the same month.
Week	Dates in the same week.
Day	Dates on the same day.
Hour	Times in the same hour.
Minute	Times in the same minute.
The following table lists the main sorting and grouping specifications for this report. Shipped Date in the first row of the Field/Expression column in the Sorting And Grouping box groups the records by year. Shipped Date in the second row groups the records for each year by quarter.

Field/ Expression	Sort  Order	Group Header	Group Footer	Group  On	Group Interval	Keep Together
Shipped  Date	Ascending	Yes	Yes	Year	1	Whole Group
Shipped  Date	Ascending	No	Yes	Qtr	1	No
Notes

•	To print the year or quarter instead of a specific date, use the DatePart function. For more information, click  [image].

•	To count the number of orders shipped, use the Count function. For more information, click  [image].

•	The Summary of Sales by Year report in the Northwind sample database prints quarterly sales for each year. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Summary of Sales by Year, and then click Design. For information on opening Northwind, click  [image].

•	The Summary of Sales by Quarter report in the Northwind sample database shows sales from multiple years for each quarter. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Summary of Sales by Quarter, and then click Design.


Grouping records on autonumbered, currency, or numeric values in a report

When you group records on an AutoNumber, Currency, or Number field, you set the GroupOn property to one of the ranges listed in the following table. If you set the GroupOn property to Interval, you can set the GroupInterval property to any number that's valid for the values in the field you're grouping on. If you set the GroupOn property to Each Value, the GroupInterval value is 1.

Set the GroupOn property to	To group records with
Each Value	The same value in the field or expression.
Interval	Values falling in the interval you specify.
Microsoft Access starts AutoNumber, Currency, and Number groups with 0. For example, if you set the GroupOn property to Interval, and set the GroupInterval property to 5, Microsoft Access groups the records like this: 0 to 4, 5 to 9, 10 to 14, and so on.

The following table lists the sorting and grouping specifications for this report. Sale Amount in the first row of the Field/Expression column in the Sorting And Grouping box groups the records in intervals of 100. Sale Amount in the second row sorts the records in ascending amounts within each $100 interval.

Field/ Expression	Sort  Order	Group Header	Group Footer	Group  On	Group Interval	Keep Together
Sale  Amount	Ascending	No	Yes	Interval	100	Whole Group
Sale  Amount	Ascending	No	No	Each Value	1	No
Note   The Sales Totals by Amount report in the Northwind sample database groups records in intervals of 1,000. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Sales Totals by Amount, and then click Design. For information on opening Northwind, click  [image].


Keep the data in a group together on a page or in a column in a report

1	In report Design view, click  [image] on the toolbar to display the Sorting And Grouping box.

2	Set the group levels for the report.

  How?

3	Click the field or expression for the group level that you want to keep together.

4	In the group properties section of the Sorting And Grouping box, set the KeepTogether property.

The setting	Prints
Whole Group	The group header, all detail records, and the group footer on the same page or in the same column.
With First Detail	The group header on a page or in a column only if it can also print the first detail record.
5	Display the property sheet for the report.

 How?

6	Set the GrpKeepTogether property.

The setting	Keeps
Per Page	The group together on the page.
Per Column/Row	The group together in the column or row.
Notes

•	If you want to keep the data in one section together, for example, a record in the detail section, set the KeepTogether property for that section to Yes.

How?

•	The Alphabetical List of Products report in the Northwind sample database keeps the products for each letter together as a group. To view this report, open the Northwind database in the Samples subfolder of your Microsoft Access program folder. In the Database window, click the Reports tab, click Alphabetical List of Products, and then click Design. For information on opening Northwind, click  [image].


Repeat a group header on another page or column

1	In report Design view, display the property sheet for the group header you want to repeat by double-clicking its section selector.

2	Set the RepeatSection property to Yes.


Troubleshoot sorting and grouping in a report

What do you need help with?

I want the records in my report to print in the same order in which they appear in the underlying table or query.

The records in the groups aren't sorted.

The records aren't sorted in the way I expect for my language.

I want the group header to print on the same line as the first detail record.

I want to hide duplicate values that appear in the same group.


Print records in a report in the same order as in its underlying table or query

Set the sort order for a report in the Sorting And Grouping box.

How?


The records in the groups on my report aren't sorted

You must specify a sort order for the records in a group in the Sorting And Grouping box in report Design view. For example, if you want to sort the orders that were shipped each day by Order ID, group on Shipped Date and sort on Order ID.

How?


Sort records correctly for my language

Set the sort order for the database to the correct language in the Options dialog box.

How?


Print the group header on the same line as the first detail record

You can design a report that uses a block layout in one of the following ways:

•	For a new report, use the Report Wizard to create the report and choose Block as the layout.

  How?

•	For an existing report, modify the report's design.

  How?


Hide duplicate values that appear in the same group

Set the HideDuplicates property to Yes for the text box that displays the values you want to hide.

How?


Preview a report

Previewing a report shows you how it will look on the printed page. You can take a quick look at the layout, which includes just a sample of the data in the report. Or you can verify the data by reviewing every page in the report.

What do you want to do?

Preview just the report's layout

Preview all the data in the report page by page


Preview the data in a report

To preview a report from Design view

•	Click  [image] on the toolbar in Design view.

To preview a report from the Database window

1	Click the Reports tab in the Database window.

2	Select the report you want to preview.

3	Click the Preview button.

Note   You can use the navigation buttons at the bottom of the Print Preview window to move between pages, and you can use the scroll bars to move around the current page.

For information on viewing the report at different magnifications, click  [image].

For information on viewing two or more pages at a time, click  [image].


Preview the layout of a report

Layout Preview is a fast way to check the layout of a report because Microsoft Access uses just enough data from the underlying table or query to show you what the report will look like. If you want to review the exact data that will appear in a report, use Print Preview.

How?

•	In report Design view, click the arrow next to the View button on the toolbar and then click Layout Preview.

Notes

•	If the report is based on a parameter query, you don't need to enter any values; just click OK. Microsoft Access ignores the parameters when you choose Layout Preview.

•	You can use the navigation buttons at the bottom of the Print Preview window to move between pages, and you can use the scroll bars to move around the current page.

For information on viewing the report at different magnifications, click  [image].

For information on viewing two or more pages at a time, click  [image].


Preview a table, query, form, or report at different magnifications

•	On the Print Preview toolbar, click the arrow next to the Zoom Control box, and then click a magnification percentage or type the percentage of magnification you want.

Notes

•	When you choose Fit, Microsoft Access adjusts the magnification of the page to best fit in the size of the window.

•	You can switch between the magnification you selected and 100% by placing the pointer on the table, query, form, or report, and then clicking when the pointer turns into a magnifying glass.

•	You can use the navigation buttons at the bottom of the Print Preview window to move between pages, and you can use the scroll bars to move around the current page.


Preview two or more pages at a time

To view two pages

1	Open the table, query, form, report, or module in Print Preview.

2	Click  [image].

To view more than two pages

1	Open the table, query, form, report, or module in Print Preview.

2	On the View menu, click Pages.

3	Select the number of pages to display from the list.

To view one page again

With the table, query, form, report, or module open in Print Preview, click  [image]  on the toolbar.

Note You can use the navigation buttons at the bottom of the Print Preview window to move between pages, and you can use the scroll bars to move around the current page.


Print a report

Before you print a report for the first time, you might want to check the margins, page orientation, and other page setup options.

How?

1	Select the report in the Database window, or open the report in Design view, Print Preview, or Layout Preview.

2	On the File menu, click Print.

3	Enter the settings you want in the Print dialog box.

•	Under Printer, specify a printer.

•	Under Print Range, specify all pages or a range of pages.

•	Under Copies, specify the number of copies and whether they should be collated.

1	Click OK.

Tip   To print a report without bringing up the dialog box, click  [image] on the toolbar.


Set margins, page orientation, and other page setup options

1	Open the database object in one of the views listed in the following table.

Object	Views
Table, query	Datasheet view, Print Preview
Form, report	All views (and from the Database window)
Macro	Not available
Module	All views
2	On the File menu, click Page Setup.

3	Click the tab for the options you want to set.

To set	Click this tab
Margins and whether to print data only	Margins
Orientation, paper size, and printer	Page
Number, size, and layout of items across	Layout
4	Click OK.

Microsoft Access stores the settings for page setup options with a form or report, so you set these options only once for each form or report. For tables, queries, and modules, you must set page setup options every time you print.


Troubleshoot printing and previewing reports

What do you need help with?

My report prints blank pages.

There's too much white space in my report.

Layout Preview displays the wrong data.

My report prompts me for unexpected parameters.

The column headings in my subreport don't print.


My report prints blank pages.

If you get a blank page only at the end of a report or printed form, make sure the Height property is set to zero for the report footer or form footer.

If every other page is blank, make sure that the total width of the form or report plus the widths of the left and right margins don't exceed the paper size specified in the Page Setup dialog box. You can use the following formula as a guide:

form or report width + left margin + right margin <= paper size

You can adjust the form or report in one or both of the following ways:

•	Reduce the width of the form or report.

  How?

•	Reduce the margins or change the page orientation.

  How?


Layout Preview displays the wrong data.

Layout Preview displays all the sections of a report and a few detail records. It sorts and groups the data it displays, but ignores any parameters, criteria, or joins in the underlying query. For example, the detail records you see in a group may not be the records that actually belong in that group.

To verify the accuracy of the data in a report, use Print Preview.

How?


My report prompts me for unexpected parameters.

Make sure that all field names used in the following areas of the report's design are spelled correctly and match field names in the underlying table or query:

•	ControlSource property of bound control

•	Field/Expression column in the Sorting And Grouping box

•	Expressions in controls or in the Sorting And Grouping box

Also, make sure that any aggregate functions reference field names in the underlying table or query, not control names. For more information, click  [image].


Add or remove a report header and footer or a page header and footer

•	In Design view, click Report Header/Footer or Page Header/Footer on the View menu.

Notes

•	You can add a header and footer only as a pair. If you don't want both a header and a footer, you can size the section you don't want to zero height, set its Height property to 0, or set its Visible property to No.

•	If you remove a header and footer, Microsoft Access also removes the controls in the header and footer.

•	For an example of using different types of sections in reports, click  [image].


Change the size of a header, footer, or other section on a form or report

You can increase or decrease the height of form and report sections individually. However, a form or report has only one width. When you change the width of one section, you change the width of the entire form or report.

Change either height or width

1	In form or report Design view, change either the height or width by placing the pointer on the bottom edge or right edge of the section.

2	Drag the pointer up or down to change the height of the section. Drag the pointer left or right to change the width of the section.

Change both height and width

•	Place the pointer in the lower-right corner of the section and drag it diagonally in any direction.


Keep the data in a record together on a page or in a column on a form or report

1	In form or report Design view, double-click the section selector to open the property sheet.

2	Set the KeepTogether property to Yes. Microsoft Access starts printing the section at the top of the next page if it can't print the entire section on the current page. If the section is longer than the print area on the page, the KeepTogether property setting is ignored.

The KeepTogether property is available for all sections except page headers and footers.

Tip   If you want to keep the data in a group together — for example, the group header, detail records, and group footer — set the KeepTogether property for the group.

How?


Print each record, group, or section on a separate page on a form or report

1	In form or report Design view, double-click the section selector to open the property sheet.

2	Set the ForceNewPage property of the section to one of the settings listed in the following table.

This setting	Prints
None	(Default) The section on the current page.
Before Section	The section at the top of a new page.
After Section	The following section at the top of a new page.
Before & After	The section at the top of a new page, and prints the following section at the top of a new page.
Notes

•	The ForceNewPage property is available for all sections except page headers and footers.

•	To print each record on a separate page, set the ForceNewPage property of the detail section to After Section. To print each group on a separate page, set the ForceNewPage property of the group header to Before Section or the ForceNewPage property of the group footer to After Section.


Omit the page header or footer on pages with the report header or footer

1	In Design view, double-click the report selector to open the property sheet.

2	Set the PageHeader or PageFooter property to one of the settings listed in the following table.

Setting	Result
All Pages	(Default) Prints the page header or footer on all pages.
Not With Rpt Hdr	Doesn't print the page header or footer on the same page as the report header.
Not With Rpt Ftr	Doesn't print the page header or footer on the same page as the report footer.
Not With Rpt Hdr/Ftr	Doesn't print the page header or footer on a page that has either a report header or footer.
Note   When you set the PageHeader property to Not With Rpt Ftr or Not With Rpt Hdr/Ftr, Microsoft Access prints the report footer on a new page.


 Protect a database by adding a database password

1	Close the database. If the database is shared on a network, ask all other users to close the database.

2	On the File menu, click Open.

3	Click the Exclusive check box, and then open the database.

4	On the Tools menu, point to Security, and then click Set Database Password.

5	In the Password box, type your password. Passwords are case-sensitive.

6	In the Verify box, confirm your password by typing the password again, and then click OK.

The password is now set. The next time you or any other user opens the database, a dialog box will be displayed that requests a password. Remember that a password is case-sensitive; you must type it exactly as defined.

Caution

•	If you lose or forget your password, it can't be recovered and you won't be able to open your database. Keep a list of your passwords and their databases in a safe place.

•	Do not use a database password if you will be replicating a database. Replicated databases can't be synchronized if database passwords are defined.

Notes

•	If you need more extensive security than provided by a database password, you need to define user-level security. For information, click  [image].

•	You can't set a database password if user-level security has been defined for your database and you don't have Administer permission for the database. Also, a database password is defined in addition to user-level security. If user-level security has been defined, any restrictions based on user-level security permissions remain in effect.

•	If a table from a password-protected database is linked, the password is cached (saved) in the database it is linked to when the link is established. This may have unforeseen consequences. For more information, click  [image].


Remove a database password

1	Open the database.

2	On the Tools menu, point to Security, and then click Unset Database Password. This command is only available if a database password was set previously.

3	In the Unset Database Password dialog box, type your current password. Passwords are case-sensitive.

4	Click OK.


Protecting your Visual Basic for applications code

You can keep anyone from being able to read Visual Basic for applications code in modules by using the User-Level Security Wizard. On the first screen of the Security Wizard, select the Modules check box. After running this procedure, your modules will be secured so that only the administrator user account and any other members of the Admins group of the workgroup information file that was current when you ran the wizard can read them. All users will still be able to execute the code.

To protect Visual Basic code behind forms, reports, and controls, select the Forms and Reports check boxes as well, and then grant only the Open/Run permission to users or groups that you want to be able to use but not modify your forms and reports.

If you give this database to a remote site with a different workgroup information file, members of the Admins group of that file will have no special permissions on any of the secured objects in your database. If you want to grant them special privileges, you can distribute a workgroup information file with groups (and permissions) already set up, and then have members of the Admins group add their own user accounts to those groups. Or, you can assign permissions to a group in your own workgroup information file and have the remote site generate a group using the exact name and PID of the group you've created.

For information on using the Security Wizard, click  [image].

You can also secure an application without requiring users to log on. For more information, click  [image].


Secure a database without requiring users to log on

1	Secure your database using the User-Level Security Wizard.

How?

2	Grant permissions to the Admin user account for all database objects that you want to be available to any user.

How?

3	Turn off the logon dialog box.

How?

When users start Microsoft Access without logging on, Microsoft Access automatically logs them on under the Admin user account. As a result, they will have only the permissions granted in step 2. This works for any workgroup, because the Admin account is the same in every workgroup information file. Only the administrator user account and any other members of the Admins group of the workgroup information file that was current when you ran the wizard in step 1 will have full permissions on your database's objects.

To perform administrative functions, you can either reactivate the logon procedure and log on as a member of the Admins group, or you can use the /Pwd and /User command-line options to specify your password and user name when starting Microsoft Access.


Hide objects in the Database window

1	In the Database window, click the object you want to hide.

2	Click  [image]  on the toolbar.

3	Select Hidden, and then click OK.

Note   To show all hidden objects, click Options on the Tools menu, click the View tab, and then select the Hidden Objects check box. The icons for hidden objects will be displayed with a dimmed outline.


Remove user-level security

This procedure requires a two-stage process. First, you log on as a workgroup administrator and give the Users group permissions on all objects. Then, you return ownership of the database and its objects to the default Admin user by exiting and logging on as Admin, creating a blank database, and then importing all of the objects from the original database into the new database.

1	Make a backup copy of the database you want to remove security from.

2	Start Microsoft Access and log on as a workgroup administrator (a member of the Admins group).

3	Open the database.

4	Give the Users group full permissions on all objects in the database.

How?

5	Exit and restart Microsoft Access, and then log on as Admin.

6	Create a new blank database and leave it open.

7	Import all the objects from the original database into the new database.

How?

8	If users will be using the current workgroup information file when opening the database, you need to clear the password for Admin to turn off the logon dialog box for the current workgroup. This is not necessary if users will be using the default workgroup information file created when installing Microsoft Access.

The new database is now completely unsecured. Anyone who can open the new database has full permissions on all the objects in it. This works for any workgroup because the Admin account is the same in every workgroup information file. The workgroup information file that was current when the new database was created in step 6 defines the Admins group for the new database.


Secure a database

Microsoft Access provides two methods of securing a database: setting a password for opening a database, or user-level security, which can be used to limit what parts of the database the user can access or change.

Setting a password

The simplest method is to set a password for opening the database. Once a password is set, a dialog box that requests the password will be displayed whenever the database is opened. Only users who type the correct password will be allowed to open the database. This method is secure (Microsoft Access encrypts the password so that it can't be accessed by reading the database file directly), but it only applies to opening a database. Once a database is open, all its objects are available to the user (unless user-level security has already been defined, as described later in this topic). For a database that is shared among a small group of users, or on a single computer, setting a password is often all that is required.

Caution   Do not use a database password if you will be replicating a database. Replicated databases can't be synchronized if database passwords are defined.

User-level security

The most flexible and extensive method of securing a database is called user-level security. This form of security is similar to methods used in most network systems. Users are required to identify themselves and type a password when they start Microsoft Access. Within the workgroup information file, they are identified as members of a group. Microsoft Access provides two default groups: administrators (named the Admins group) or users (named the Users group), but additional groups can be defined.

Permissions are granted to groups and users to regulate how they are allowed to work with each object in a database. For example, members of the Users group might be allowed to view, enter, or modify data in a Customers table, but not be allowed to change the design of that table. The Users group might be allowed to only view data in a table containing order data, and be totally denied access to a Payroll table. Members of the Admins group have full permissions on all of a database's objects. You can set up more fine-grained control by creating your own group accounts, assigning appropriate permissions to those groups, and then adding users to those groups.

The three main reasons to use user-level security are to:

•	Protect the intellectual property of your code.

•	Prevent users from inadvertently breaking an application by changing code or objects on which the application depends.

•	Protect sensitive data in the database.

Note   For more information on the Microsoft Access security model, see Chapter 14, "Securing and Delivering Your Application," in Building Applications with Microsoft Access for Windows 95.

What do you want to do?

Secure a database by setting a database password

Secure a database using user-level security


Secure a database using the Security Wizard

Using the Security Wizard is a simple process, but running the wizard alone doesn't perform all the steps required to fully secure your database.

Note   The Security Wizard can take a while to run. For example, on a 486/50, securing the Northwind sample database takes approximately 13 minutes.

1	Join a secure workgroup or create a new workgroup information file.

Important   To make sure your database is completely secure, don't use the default workgroup defined by the Microsoft Access workgroup information file that was created when you installed Microsoft Access. You should make sure the workgroup information file that defines the workgroup you are joining has been created with a unique workgroup ID or, if not, you should create a new workgroup.

For information on joining an existing workgroup, click  [image]. For information on creating a new workgroup information file, click  [image].

2	Activate the logon dialog box.

How?

3	Create the administrator's user account.

How?

4	Exit Microsoft Access and log on as the administrator.

5	Remove the Admin user from the Admins group.

How?

Note   If you want a user other than the administrator account to be the owner of the database and all the objects in it, exit Microsoft Access and log on as that user. This must be a user other than Admin who has at least Read Data and Read Design permissions on all objects in the database you want to secure.

6	Open the database you want to secure.

7	On the Tools menu, point to Security, and then click User-Level Security Wizard.

8	Follow the directions in the wizard dialog boxes.

The Security Wizard creates a new database, exports copies of all of the objects from the original database, secures the object types selected in the first dialog box of the Security Wizard by revoking all permissions of the Users group for those objects in the new database, and then encrypts the new database. The original database is not changed in any way. Table relationships and any linked tables are also re-created in the new database.

At this point, only members of the Admins group in the workgroup you joined in step 1 will have access to the secured objects in the new database. The Users group has no permissions for the secured objects. You need to grant permissions to users and/or groups in order to regulate access to the secured objects. For information on granting permissions and creating user and group accounts, click  [image].


What is a Microsoft Access workgroup?

A Microsoft Access workgroup is a group of users in a multiuser environment who share data. If user-level security is defined, the members of a workgroup are recorded in user and group accounts that are stored in a Microsoft Access workgroup information file. Users passwords are also stored in the workgroup information file. These security accounts can then be assigned permissions for databases and their objects. The permissions themselves are stored in the secure database.

In addition to workgroup information, user preferences defined using the Options command on the Tools menu are recorded in the workgroup information file. If users are required to log on, user preferences are saved for each user in the shared workgroup information file.

Your default workgroup is defined by the workgroup information file that the Setup program automatically creates in the folder where you installed Microsoft Access. Unless you specify another workgroup information file using the Workgroup Administrator utility, Microsoft Access uses the default workgroup information file each time you start Microsoft Access. You can also use the Workgroup Administrator to create a new Microsoft Access workgroup information file.

Before you create security accounts, you should choose a Microsoft Access workgroup information file where those accounts will be stored. You can use the default workgroup information file, specify another one, or create a new one. If you need to make sure that your workgroup and its permissions can't be duplicated, do not use the default workgroup information file; you must make sure the workgroup information file you choose has been created with a unique workgroup ID. If such a workgroup information file doesn't exist, you should create one using the Workgroup Administrator.


Join a Microsoft Access workgroup

1	To start the Workgroup Administrator, do one of the following, depending on which operating system you are using:

•	If you are using Windows 95, use My Computer or Windows Explorer to open the folder where Microsoft Access is installed (MSOffice\Access is the default folder), and then double-click Wrkgadm.exe.

•	If you are using Windows NT, open Program Manager, and then double-click the Workgroup Administrator icon in the program group where you installed Microsoft Access.

Tip   If you are using Windows 95, you can add the Workgroup Administrator to the Start menu: click the taskbar with the right mouse button, click Properties, click the Start Menu Programs tab, click Add, and then follow the directions in the remaining dialog boxes.

2	In the Workgroup Administrator dialog box, click Join.

3	Type the path and name of the workgroup information file that defines the Microsoft Access workgroup you want to join, and then click OK, or click Browse and then use the Select Workgroup Information File dialog box to locate the workgroup information file.

The next time you start Microsoft Access, it uses the user and group accounts, passwords, and user preferences stored in the workgroup information file for the workgroup you joined.

Important   If you are setting up user-level security and need to make sure that your workgroup and its permissions can't be duplicated, you should make sure the workgroup information file that defines the workgroup you are joining has been created with a unique workgroup ID. If such a workgroup information file doesn't exist, you should create one. For information on creating a new workgroup information file, click  [image].

Note   You can also specify a workgroup information file when starting Microsoft Access by using the /wrkgrp command-line option. For information on using start up command-line options, click  [image].


Create a new Microsoft Access workgroup information file

When you install Microsoft Access, the Setup program automatically creates a Microsoft Access workgroup information file that is identified by the name and organization information you specify. Because this information is often easy to determine, it's possible for unauthorized users to create another version of this workgroup information file and consequently assume the irrevocable permissions of an administrator account (a member of the Admins group) in the workgroup defined by that workgroup information file. To prevent this, create a new workgroup information file and specify a workgroup ID (WID). Only someone who knows the WID will be able to create a copy of the workgroup information file.

1	To start the Workgroup Administrator, do one of the following, depending on which operating system you are using:

•	If you are using Windows 95, use My Computer or Windows Explorer to open the folder where Microsoft Access is installed (MSOffice\Access is the default folder), and then double-click Wrkgadm.exe.

•	If you are using Windows NT, open Program Manager, and then double-click the Workgroup Administrator icon in the program group where you installed Microsoft Access.

Tip   If you are using Windows 95, you can add the Workgroup Administrator to the Start menu: click the taskbar with the right mouse button, click Properties, click the Start Menu Programs tab, click Add, and then follow the directions in the remaining dialog boxes.

2	Click Create, and then type your name and organization.

3	In the Workgroup ID box, type any combination of up to 20 numbers and letters, and then click OK.

Caution   Be sure to write down your exact name, organization, and workgroup ID, including whether letters are uppercase or lowercase (for all three entries), and keep them in a secure place. If you have to re-create the workgroup information file, you must supply exactly the same name, organization, and workgroup ID. If you forget or lose these entries, you can't recover them and might lose access to your databases.

4	Type a name for the new workgroup information file, and then click OK. (By default, the workgroup information file is saved in the folder where you installed Microsoft Access. To save in a different location, type a new path or click Browse to specify the new path.)

The new workgroup information file is used the next time you start Microsoft Access. Any user and group accounts or passwords you create, as well as changes to user preferences, are saved in the new workgroup information file. To have others join the workgroup defined by your new workgroup information file, copy it to a shared folder (if you didn't already save it in a shared folder in step 4), and then have each user run the Workgroup Administrator to join the new workgroup information file.


Restore a damaged or deleted Microsoft Access workgroup information file

In rare circumstances, the Microsoft Access workgroup information file can become damaged. If you start Microsoft Access and that file can't be opened, a message will be displayed. How you solve this problem depends on whether you have a backup copy and how your workgroup information file was originally created or specified:

•	If you didn't use the Workgroup Administrator to create or specify a new workgroup information file, and you made a backup copy of it, use Windows Explorer, My Computer, MS-DOS copy or restore commands, or backup software to copy the most recent copy of the file to the folder where you installed Microsoft Access. In this case, if you don't have a backup copy of the file, you must reinstall Microsoft Access to create a default workgroup information file.

•	If you used the Workgroup Administrator to create a new workgroup information file, and have a backup copy of that file, you need to copy the backup copy to the path where you originally saved your workgroup information file. However, if you don't have a backup copy of the workgroup information file you created, you need to run Workgroup Administrator again, typing the same case-sensitive name, organization, and workgroup ID entries you used when you originally created it. For more information on creating a workgroup information file, click  [image].

•	If you used the Workgroup Administrator to join a workgroup on a path other than the folder where Microsoft Access is installed, and have a backup copy of the workgroup information file, you need to copy the backup copy to that path. If you don't have a backup copy, you need to create a new copy using the method that was used to create the original file: by reinstalling Microsoft Access, or by using Workgroup Administrator and typing the same case-sensitive name, organization, and workgroup ID entries used when it was originally created.

Microsoft Access stores security account information in the workgroup information file. So in all cases where you don't have a backup copy and have to re-create a workgroup information file, if you've restricted permissions to your databases, you must re-create security accounts with the same case-sensitive names and personal identifier (PID) entries as before. For more information on creating security accounts, click  [image].

You don't have to redefine permissions or object ownership because this information is stored in the secure databases themselves. However, settings made using the Options command on the Tools menu are stored in the workgroup information file and need to be re-entered.


Set up more than one Microsoft Access workgroup to use the same secure database

You can give users in different Microsoft Access workgroups access to a secure database and its objects by creating a group account with an identical name and personal identifier (PID) in each workgroup you want to share the secure database. You then add users in each workgroup to that group account. This is useful if you want users at remote locations to manage their own workgroup membership.

1	Use the Workgroup Administrator to join one of the workgroups.

How?

2	Start Microsoft Access, log on as a workgroup administrator (a member of the Admins group), and then open a database.

3	Create a group account, making sure to write down the exact case-sensitive group name and PID.

How?

4	Add users to the new group.

How?

Note   You can add users to this group or delete them at any time.

5	Exit Microsoft Access.

6	Repeat steps 1 through 5 for each workgroup that will share the secured database. In step 3, make sure to type exactly the same case-sensitive group name and PID as for the group account you created in the first workgroup.

7	Open the secure database you want to share between the workgroups and assign permissions to the new groups.

How?

Note   You can also have a workgroup administrator at a remote location add the same group to his or her workgroup information file by providing the administrator with the exact case-sensitive group name and PID you used to create that group in your workgroup information file.


Require users to log on to Microsoft Access

Until you activate the logon procedure for a workgroup, Microsoft Access automatically logs on all users at startup using the predefined Admin user account. You require users in a workgroup to log on by adding a password to the Admin user account.

1	Join the workgroup whose logon procedure you want to activate.

How?

2	Start Microsoft Access and then open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	Click the Users tab, and make sure that the predefined Admin user account is highlighted in the Name box.

5	Click the Change Logon Password tab, click the New Password box, and type the new password. Don't type anything in the Old Password box.

To maintain the security of your password, Microsoft Access displays asterisks (*) as you type. Passwords can be 1 to 14 characters and can include any characters except ASCII character 0 (null). Passwords are case-sensitive.

6	Verify the password by typing it again in the Verify box, and then click OK.

The logon dialog box is displayed the next time any member of the workgroup that you joined in step 1 starts Microsoft Access. If no user accounts are currently defined for that workgroup, the Admin user is the only valid account at this point. For information on defining user accounts, click  [image].

Note   When you secure a database, you create user accounts in a Microsoft Access workgroup and then assign permissions for databases and objects to those accounts and to any group accounts to which they belong. When users log on to Microsoft Access using their accounts, they have only the permissions associated with those accounts. Users log on to Microsoft Access by typing a user name and password in the logon dialog box.


Turn off the logon dialog box

1	Join the workgroup whose logon procedure you want to deactivate.

How?

2	Start Microsoft Access and open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	Click the Users tab. In the Name box, select Admin from the list, and then click Clear Password.

The next time any member of the workgroup that you joined in step 1 starts Microsoft Access, it will no longer display the logon dialog box.

Note   This procedure does not remove any user-level security defined for the database. For information on removing user-level security completely, click  [image].


Making a secure application and workgroup available to users

A secure application depends on users having access to both an application database where permissions are stored, and a workgroup where user and group accounts and passwords are stored. Depending on how the application is to be used, you can make the application and workgroup available to users in a variety of ways.

Copy the application files and the workgroup information file that defines the workgroup to a network server location

Using the Workgroup Administrator, users can join the workgroup by specifying the network server path to the workgroup information file, and then run the application directly from the server location. You might want to prevent users from opening the application with exclusive access by removing Open Exclusive permissions for the database from the Users group.

Give each user a copy of the application files and the workgroup information file that defines the workgroup

Using the Workgroup Administrator, users can join the workgroup by specifying the path to the workgroup information file on their computer, and then run their copies of the application on their computers. However, if you have to update the application, its data, or the workgroup information file, you'll have to give each user copies of all updated files.

As an alternative, you might want to split the application into a data database placed on a network server and an application database containing all other database objects placed on each user's computer. Typically in this configuration, you want to keep the workgroup information file on the server as well. Then if you have to update the application, you only have to give users updated versions of the application database file. For information on how to do this, click  [image].

Give users in different Microsoft Access workgroups access to the application by creating the same group in each workgroup

You can create a group account in each workgroup with the identical name and PID, and then add users in each workgroup to that group. For example, a user working on a network on a Microsoft Access workgroup in Honolulu can use an application created for a Microsoft Access workgroup in Melbourne if that user is a member of a group account that was created with an identical name and PID on both workgroups.

To run the application, each user must have a copy of Microsoft Access. To create a Microsoft Access application that doesn't require a copy of Microsoft Access, you must use the Microsoft Access Developer's Toolkit.


Create user or group accounts and grant permissions

If you only need an administrators group and users group for your security purposes, you don't need to create additional groups; you can use the default Admins and Users groups. In this case, you only need to assign the appropriate permissions to the default Users group and add any additional administrators to the default Admins group. Any new users you add are automatically added to the Users group. Typical permissions for the Users group might include Read Data and Update Data for tables and queries, and Open/Run for forms and reports.

If you need more fine-grained control of different groups of users, you can create your own groups, assign different sets of permissions to those groups, and then add users to the appropriate groups. To simplify the management of permissions, it is recommended that you only assign permissions to groups (not users) and then add users to the appropriate groups.

What do you want to do?

Create any new user accounts

Create your own groups (if necessary)

Grant permissions to groups or users for selected objects

Add users to appropriate groups


How permissions work and who can assign them

There are two types of permissions: explicit and implicit. Explicit permissions are those permissions granted directly to a user account; no other users are affected. Implicit permissions are those permissions granted to a group account. Adding a user to that group grants the group's permissions to that user; removing a user from the group takes away the group's permissions from that user.

When a user attempts to perform an operation on a secured database object, that user's set of permissions are based on the intersection of that user's explicit and implicit permissions. A user's security level is always the least restrictive of that user's explicit permissions and the permissions of any and all groups to which that user belongs. For this reason, the least complicated way to administrate a workgroup is to create new groups and assign permissions to the groups, rather than to individual users. Then you can change individual users' permissions by adding or removing them from groups. Also, if you need to grant new permissions, you can grant them to all members of a group in a single operation.

Permissions can be changed for a database object by:

•	Members of the Admins group of the workgroup information file in use when the database was created.

•	The owner of the object.

•	Any user who has Administer permission for the object.

Even though users might not currently be able to perform an action, they might be able to grant themselves permissions to perform the action. This is true if a user is a member of the Admins group, or if a user is the owner of an object.

The user who creates an object is the owner of that object. The same group of users who can change permissions can change the ownership of an object using the User And Group Permissions command on the Security submenu (Tools menu), or can re-create the object. To re-create the object, you do not have to start from scratch. You can make a copy of the object, or import it or export it to another database. If you want to secure an entire database, this is the easiest way to transfer the ownership of all of the objects, including the database itself. The best way to secure an entire database is by using the Security Wizard, which creates a new database and imports all objects into it.

Note   Copying, importing, or exporting doesn't change the ownership of queries whose RunPermissions property is set to Owner's. You can change ownership of a query only if its RunPermissions property is set to User's.

For information on types of permissions, click  [image].


Types of permissions

The following table summarizes the permissions that you can assign.

Permission	Permits a user to	Applies to
Open/Run	Open a database, form, or report, or run a macro.	Databases, forms, reports, and macros
Open Exclusive	Open a database with exclusive access.	Databases
Read Design	View objects in Design view.	Tables, queries, forms, reports, macros, and modules
Modify Design	View and change the design of objects, or delete them.	Tables, queries, forms, reports, macros, and modules
Administer	For databases, set database password, replicate a database, and change startup properties. For database objects, have full access to objects and data, including ability to assign permissions.	Databases, tables, queries, forms, reports, macros, and modules
Read Data	View data.	Tables and queries
Update Data	View and modify but not insert or delete data.	Tables and queries
Insert Data	View and insert but not modify or delete data.	Tables and queries
Delete Data	View and delete but not modify or insert data.	Tables and queries
Note   Some permissions automatically imply the selection of others. For example, the Update Data permission for a table automatically implies the Read Data and Read Design permissions because you need these to modify the data in a table. Modify Design and Read Data imply Read Design. For macros, Read Design implies Open/Run.


Assign or remove permissions for security accounts

After running the Security Wizard, you can assign or remove permissions for user and group accounts in your workgroup for a database and its existing objects.

You can also set the default permissions that Microsoft Access assigns for any new database objects that are created in a database.

What do you want to do?

Assign or remove permissions for a database and existing database objects

 	Assign default permissions for new database objects


Assign or remove permissions for a database and existing database objects

1	Open the database that contains the objects you want to secure.

The workgroup information file in use when you log on must contain the user or group accounts you want to assign permissions for at this time; however, you can assign permissions to groups and add users to those groups later.

2	On the Tools menu, point to Security, and then click User And Group Permissions.

3	On the Permissions tab, click Users or Groups, and then click the user or group whose permissions you want to assign in the User/Group Name box.

4	Click the type of object in the Object Type box, and then click the name of the object to assign permissions for in the Object Name box.

Tip   You can select multiple objects in the Object Name box by dragging through the objects you want to select or by holding down CTRL and clicking the desired objects.

5	Under Permissions, select the permissions you want to assign, or clear the permissions you want to remove for the group or user, and then click Apply. Repeat steps 4 and 5 to assign or remove permissions for additional objects for the current user or group.

For information on all the permissions you can assign, click  [image].

6	Repeat steps 3 through 5 for any additional users or groups, and then click OK when you have finished.

Important   If you assign or remove permissions for Visual Basic code (forms, reports, or modules), those permissions will not take effect until the database is closed and re-opened.

Notes

•	Permissions for an object can be assigned or removed by a user logged on as the object's owner, as a user account that has Administer permissions for the object, or as an administrator account (a member of the Admins group in the workgroup in which the database that contains the object was created). Permissions for a database can be assigned or removed by a user logged on as the owner of the database, or as an administrator account.

•	Some permissions automatically imply the selection of others. For example, the Modify Data permission for a table automatically implies the Read Data and Read Definitions permissions because you need these to modify the data in a table. Modify Definitions and Read Data imply Read Definitions. For macros, Read Definitions implies Execute.

•	Organizing user accounts into groups makes it easier to manage security. For example, rather than assigning permissions to each user for each object in your database, you can assign permissions to a few groups, and then add users to the appropriate group. When users log on to Microsoft Access, they inherit the permissions of any groups to which they belong.

•	When you edit an object and save it, it retains its assigned permissions. However, if an object is saved with a new name using the Save As command on the File menu or by cutting and pasting, importing, or exporting the object, the associated permissions are lost; you have to reassign them. This is because you are creating a new object which is assigned the default permissions defined for that object type.


Assign default permissions for new database objects

1	Open the database that contains the objects.

2	On the Tools menu, point to Security, and then click User And Group Permissions.

3	On the Permissions tab, click Users or Groups, and then click the user or group whose permissions you want to assign in the User/Group Name box.

4	Click the type of object in the Object Type box, and click <New object> in the Object Name list.

The <New object> selection varies depending on the type of object you've selected, either <New Tables/Queries>, <New Forms>, <New Reports>, <New Macros>, or <New Modules>.

5	Select the default permissions you want to assign for that object type, and then click Apply. Repeat steps 4 and 5 to assign default permissions for additional object types for the current user or group.

For information on all the permissions you can assign, click  [image].

6	Repeat steps 3 through 5 for any additional users or groups, and then click OK when you have finished.

Notes

•	Default permissions can be assigned only by an administrator account (a member of the Admins group in the workgroup in which the database that contains the object was created) or the owner of the database.

•	Some permissions automatically imply the selection of others. For example, the Modify Data permission for a table automatically implies the Read Data and Read Definitions permissions because you need these to modify the data in a table. Modify Definitions and Read Data imply Read Definitions. For macros, Read Definitions implies Execute.

•	Organizing user accounts into groups makes it easier to manage security. For example, rather than assigning permissions to each user for each object in your database, you can assign permissions to a few groups, and then add users to the appropriate group. When users log on to Microsoft Access, they inherit the permissions of any groups to which they belong.


Prevent users from replicating or setting a database password or startup options

In many situations, you will want to prevent users from replicating a database. Replicating a database allows a user to make a copy of a shared database and also adds fields and makes other changes to the current database. You will probably want to prevent users from setting a database password, too. If a user sets a database password for a shared database, no other user will be able open the database without providing that password. You might also want to keep users from changing startup properties that specify features such as custom menus, custom toolbars, or the startup form.

If a shared database doesn't have user-level security defined, you can't prevent a user from making any of these changes. Running the Security Wizard on a database defines user-level security, which allows you to control access to certain features and determines how database objects can be used. When user-level security is defined, a user or group must have Administer permission for the database to replicate a database, set a database password, or change its startup properties. After running the Security Wizard, only members of the Admins group of the current workgroup have the Administer permission.

If user-level security is already defined and a user or group currently has Administer permission for a database, removing that permission will prevent the user or group from making any of these changes. If you need to allow a user or group to perform any of these tasks, you can assign the Administer permission to that user or group. You can't control access to these three tasks independently.

What do you want to do?

Secure a database using the Security Wizard

Assign permissions to a secured database


View or transfer ownership of individual objects in a secure database

1	Open the database.

2	On the Tools menu, point to Security, and then click User And Group Permissions.

On the Change Owner tab, Microsoft Access displays a list of the objects that are currently displayed in the Database window, and the current owner of those objects.

3	Click an object type in the Object Type box, or use the existing Object Type.

4	From the Object list, click one or more objects whose ownership you want to change. To select more than one object, either hold down CTRL and click the objects or drag through the ones you want to select.

5	In the New Owner box, click the user or group account that you want to be the new owner of the object or objects.

6	Click the Change Owner button.

If you have Administer permission for the objects, Microsoft Access changes the ownership of the object or objects to the account you've selected.

Note   If you change ownership of an object to a group account, all users who belong to the group automatically receive the permissions associated with ownership of the object.


Transfer ownership of an entire database to another administrator

1	Start Microsoft Access using a secure workgroup that contains the user account that you want to own the database and its objects.

2	Log on using that account.

3	Create a new database.

4	Import all of the objects from the database whose ownership you want to change into the new database.

How?

Note   To import a database, you must have Open/Run permission for the database, and Read Design permission for its objects. To import tables, you must also have Read Data permission. If you have permissions for some objects but not others, Microsoft Access imports only the objects for which you have permissions.


Encrypt or decrypt a database

Encrypting a database compacts the database file and makes it indecipherable by a utility program or word processor. Decrypting a database reverses the encryption.

1	Start Microsoft Access without opening a database.

Important   You can't encrypt or decrypt a database when it is open. In a multiuser environment, the encrypt or decrypt operation fails if another user has the database open.

2	On the Tools menu, point to Security, and then click Encrypt/Decrypt Database.

3	Specify the database you want to encrypt or decrypt, and then click OK.

4	Specify a name, drive, and folder for the encrypted or decrypted database; and then click OK.

You can use the same name as the original for the encrypted or decrypted database file, or you can use a different name to create a separate file. If you use the same name, drive, and folder, and the database is encrypted or decrypted successfully, Microsoft Access automatically replaces the original file with the encrypted or decrypted version. If an error occurs, Microsoft Access doesn't delete the original file.

Notes

•	If user-level security has been defined, to encrypt or decrypt a database, you must have Modify Design permission for all tables in the database. Otherwise, the encrypt or decrypt operation fails.

•	If an object in a version 1.x database includes the backquote character (`) in its object name, you won't be able to encrypt the database. Use Microsoft Access version 1.x to rename it, and then change the references to that object in your queries, forms, reports, macros, and Access Basic code.

•	Encrypting a database doesn't restrict access to objects by authorized users or groups. You control access to objects by defining user-level security. For more information, click  [image].

•	As part of encrypting or decrypting a database, Microsoft Access also compacts the database. To compact the database without encrypting or decrypting it, use the Compact Database command on the File menu.

•	The encrypt or decrypt operation fails if you don't have enough storage space on your disk for both the original and encrypted or decrypted versions of the database.


Troubleshoot problems with passwords

Why can't I delete my password?

Only an administrator account (a member of the Admins group used to manage security for your workgroup) can delete a password. If you have forgotten or lost your password, you must get an administrator to delete it.


Creating and managing security accounts

A Microsoft Access workgroup information file contains the following predefined accounts.

Account	Function
Admin	The default user account. This account is exactly the same for every copy of Microsoft Access and other applications that can use the Microsoft Jet database engine, such as Microsoft Visual Basic for applications and Microsoft Excel.
Admins	The administrator's group account. This account is unique to each workgroup information file. By default, the Admin user is in the Admins group. There must be at least one user in the Admins group at all times.
Users	The group account comprising all user accounts. Microsoft Access automatically adds user accounts to the Users group when a member of the Admins group creates them. This account itself is the same for any workgroup information file, but it contains only user accounts created by members of the Admins group of that workgroup. By default, this account has full permissions on all newly-created objects. The only way to remove a user account from the Users group is for a member of the Admins group to delete that user.
In effect, security in Microsoft Access is always "on." Until you activate the logon procedure for a workgroup, Microsoft Access invisibly logs on all users at startup using the default Admin user account with a blank password. Behind the scenes, Microsoft Access uses the Admin account as the administrator account for the workgroup, as well as the owner of any databases and objects created.

Administrators and owners are important because they have permissions that can't be taken away:

•	Administrators (members of the Admins group), can always get full permissions for objects created in the workgroup.

•	An account that owns an object can always get full permissions for that object.

•	An account that owns a database can always open the database.

Because the Admin user account is exactly the same for every copy of Microsoft Access, the first steps in securing your database are to define administrator and owner user accounts (or use a single user account as both the administrator and owner account), and then to remove the Admin user account from the Admins group. Otherwise, anyone with a copy of Microsoft Access can log on to your workgroup using the Admin account and have full permissions for the workgroup's objects.

For example, to secure a database named Orders you could create your own OrdersAdmin and OrdersOwner user accounts, and then add passwords to these accounts.

You can assign as many user accounts as you want to the Admins group, but only one user account can own the database itself — the user account that is active when the database is created, or when ownership is transferred by creating a new database and importing all of a database's objects into it. However, group accounts can own objects within a database.

Important

•	The accounts you create for users of the database must be stored in the workgroup information file that those users will join when they use the database. If you're using a different file to create the database, change the file before creating the accounts.

•	Make sure to create a unique password for your administrator and owner user accounts. A user who can log on using the administrator account can always get full permissions for any objects created in the workgroup. A user who can log on using an owner account can always get full permissions for the objects owned by that user.

Organizing users in groups of users makes it easier to manage a secure database. With this strategy, rather than assign permissions to each user for each object in your database, you assign permissions to a few groups, and then add users to the appropriate group. When users log on to Microsoft Access, they inherit the permissions from any groups they belong to. Only user accounts can log on to Microsoft Access; you can't log on using a group account.

For example, you could secure an Orders database by creating a Managers group for managers, a Sales Reps group for sales representatives, and a Staff group for staff employees. You can assign the least restrictive set of permissions to the Managers group, a more restrictive set of permissions to the Sales Reps group, and the most restrictive set of permissions to the Staff group. When you create a user account for a new employee, you add that account to the appropriate group. The employee then has the permissions associated with that group.

After you create user and group accounts, you can view the relationships between them by clicking User And Group Accounts on the Security submenu (Tools menu), and then clicking the Print Users And Groups button. Microsoft Access prints a report of the accounts in the workgroup, showing the groups to which each user belongs and the users that belong to each group.


Create a security administrator account

1	Start Microsoft Access using a secure workgroup.

Important   To make sure your database is completely secure, don't use the default workgroup defined by the workgroup information file that was created when you installed Microsoft Access. You should make sure the workgroup information file that defines the workgroup you are using has been created using a unique workgroup ID, and if not, you should create a new file.

For information on joining an existing workgroup, click  [image]. For information on creating a new workgroup information file, click  [image].

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, click New. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

5	In the New User/Group dialog box, type the name of the administrator account and a Personal ID (PID), and then click OK to create the new account.

User names can be 1 to 20 characters long and can include alphabetic characters, accented characters, numbers, spaces, and symbols, with the following exceptions:

•	The characters " / \ [ ] : | < > + = ; , ? *

•	Leading spaces

•	Control characters (ASCII 00 through ASCII 31)

Caution   Be sure to write down the exact account name and PID entries, including whether letters are uppercase or lowercase, and keep them in a secure place. If you ever have to re-create the account, you must supply the same name and PID entries. If you forget or lose these entries, you can't recover them.

1	In the Available Groups box, click Admins, and then click Add.

Microsoft Access adds the new administrator account to the Admins group and displays Admins in the Member Of box.

2	Click OK to create the new administrator account.

Note   The Personal ID entered in step 5 is not a password. Microsoft Access uses the PID and the user name as seeds for an encryption algorithm to generate a secure identifier for the user account. For information on creating passwords, click  [image].


Create a security user account

1	Start Microsoft Access using the workgroup in which you want to use the account.

Important   The accounts you create for users must be stored in the workgroup information file that those users will use. If you're using a different workgroup to create the database, change your workgroup before creating the accounts.

For information on joining an existing workgroup, click  [image]. For information on creating a new workgroup information file, click  [image].

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, click New. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

5	In the New User/Group dialog box, type the name of the new account and a Personal ID (PID), and then click OK to create the new account. It is automatically added to the Users group

User names can be 1 to 20 characters long and can include alphabetic characters, accented characters, numbers, spaces, and symbols, with the following exceptions:

•	The characters " / \ [ ] : | < > + = ; , ? *

•	Leading spaces

•	Control characters (ASCII 00 through ASCII 31)

Caution   Be sure to write down the exact account name and PID, including whether letters are uppercase or lowercase, and keep them in a secure place. If you ever have to re-create an account that has been deleted or created in a different workgroup, you must supply the same name and PID entries. If you forget or lose these entries, you can't recover them.

Notes

•	The Personal ID entered in step 5 is not a password. Microsoft Access uses the PID and the user name as seeds for an encryption algorithm to generate a secure identifier for the user account. For information on creating passwords, click  [image].

•	It is usually easier to manage security if you organize users into groups and then assign permissions to groups rather than to individual users.


Delete a security user account

1	Open a database.

2	On the Tools menu, point to Security, and then click User And Group Accounts.

3	On the Users tab, enter a user in the Name box, and then click Delete. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

4	Click OK to delete the user account.

5	Repeat steps 3 and 4 if you want to delete additional user accounts, and then click OK when you have finished.

Note   The Admin user account can't be deleted.


Create a security group account

As part of securing a database, you can create group accounts in your Microsoft Access workgroup that you use to assign a common set of permissions to multiple users.

1	Start Microsoft Access using the workgroup in which you want to use the account.

Important   The accounts you create for users must be stored in the workgroup information file that those users will use. If you're using a different workgroup to create the database, change your workgroup before creating the accounts. You can change workgroups using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Groups tab, click New. The Groups tab will be unavailable unless you are logged on as a member of the Admins group.

5	In the New User/Group dialog box, type the name of the new account and a Personal ID (PID).

Group names can be 1 to 20 characters long and can include alphabetic characters, accented characters, numbers, spaces, and symbols, with the following exceptions:

•	The characters " / \ [ ] : | < > + = ; , ? *

•	Leading spaces

•	Control characters (ASCII 00 through ASCII 31)

Caution   Be sure to write down the exact account name and PID, including whether letters are uppercase or lowercase, and keep them in a secure place. If you have to re-create an account that has been deleted or created in a different workgroup, you must supply the same name and PID entries. If you forget or lose these entries, you can't recover them.

6	Click OK to create the new group account.


Delete a security group account

1	Start Microsoft Access using the workgroup that contains the account you want to delete.

You can find out which workgroup is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Groups tab, enter the group you want to delete in the Name box, and then click Delete. The Groups tab will be unavailable unless you are logged on as a member of the Admins group.

5	Click OK to delete the group account.

6	Repeat steps 4 and 5 if you want to delete additional group accounts, and then click OK when you have finished.

Note   The Admins and Users group accounts can't be deleted.


Add users to security groups

1	Start Microsoft Access using the workgroup containing the user and group accounts.

You can find out which workgroup is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, enter in the Name box the user you want to add to a group. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

5	In the Available Groups box, click the group you want to add the user to, and then click Add.

The selected group is displayed in the Members Of list.

6	Repeat step 5 if you want to add this user to any other groups. Repeat steps 4 and 5 to add other users to groups. Click OK when you have finished.


Remove users from security groups

1	Start Microsoft Access using the workgroup containing the user and group accounts.

You can find out which workgroup is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, enter the user you want to remove in the Name box. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

5	In the Members Of box, click the group you want to remove the user from, and then click Remove.

6	Repeat step 5 if you want to remove this user from any other groups. Repeat steps 4 and 5 to remove other users from groups. Click OK when you are finished.

Notes

•	You can't remove users from the default Users group. Microsoft Access automatically adds all users to the Users group. To remove any user account from the Users group, you must delete the account. For information on deleting a user account, click  [image].

•	There must be at least one user in the predefined Admins group at all times.


Print information about security users and groups

1	Start Microsoft Access using the workgroup information file whose security information you want to print.

You can find out which workgroup information file is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, click Print Users And Groups.

5	In the Print Security dialog box, click Only Users to print a report showing all users defined for the current workgroup, or Only Groups to print a report showing all groups defined for the current workgroup. Click Both Users And Groups to print both user and group account information.

6	Click OK.

Note   If you are using a workgroup information file created with Microsoft Access version 2.0 or 1.x, you must be logged on as a member of the Admins group to print user and group information. If the workgroup information file was created with Microsoft Access version 7.0, all users in the workgroup can print user and group information.


Create or change passwords

Microsoft Access uses passwords in two contexts:

•	To control opening a database.

•	To verify users when they log on to a workgroup, when user-level security has been defined for that workgroup and one or more of its databases.

The first kind of password is called a "database password." If you set a database password, all users must enter that password before they are allowed to open the database. Adding a database password is an easy way to prevent unwanted users from opening your database; however, once a database is open, no other security measures are provided unless user-level security has been defined as well. If you have user-level security defined for your database, you can prevent users from setting a database password.

The second kind of password is called a "security account password" and is only used when user-level security has been defined for a workgroup. A security account password is created to make sure that no other user can log on using that user name.

By default, Microsoft Access assigns a blank password to the default Admin user account , and to any new user accounts you create in your workgroup. As part of securing a database, it's important to add a password to:

•	The Admin user account (to activate the Logon dialog box).

•	The user account that owns the database and its objects.

•	Any user accounts you add to the Admins group.

In addition, you might want to add passwords to the accounts you create for users, or instruct users to add their own passwords.

Each user can create or change his or her own user account password; however, only an administrator account can clear a password if a user forgets the password.

What do you want to do?

Set a database password

Remove a database password

Prevent users from setting a database password

Create or change a user-level security account password

Clear a user-level security account password


Create or change a security account password

A security account password is created to make sure that no other user can log on using that user name. By default, Microsoft Access assigns a blank password to the Admin user account, and to any new user accounts you create in your workgroup.

1	Start Microsoft Access using the workgroup the user account is stored in, and log on using the name of the account for which you want to create or change the password.

You can find out which workgroup is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Change Logon Password tab, leave the Old Password box blank if a password hasn't been defined previously for this account. Otherwise, type the current password in the Old Password box.

5	Type the new password in the New Password box.

A password can be 1 to 14 characters long and can include any characters except ASCII character 0 (null). Passwords are case-sensitive.

6	Retype the password in the Verify box, and then click OK.

Caution   You can't recover your password if you forget it, so be sure to store it in a safe place. If you forget your password, a user logged on with an administrator account (a member of the Admins group in the workgroup in which the account and password were created) must clear the password before you can log on.


Clear a security account password

1	Start Microsoft Access using the workgroup information file in which the user account (and its password) is stored.

You can find out which workgroup information file is current or change workgroups by using the Workgroup Administrator.

2	Open a database.

3	On the Tools menu, point to Security, and then click User And Group Accounts.

4	On the Users tab, enter the user account name in the Name box. The Users tab will be unavailable unless you are logged on as a member of the Admins group.

5	Click Clear Password.

6	Repeat steps 4 and 5 to clear any additional passwords, and then click OK when you have finished.


Look up Microsoft Access specifications

What do you want to do?

Look up database specifications

Look up table specifications

Look up query specifications

Look up form and report specifications

Look up macro specifications


Database specifications

Attribute	Maximum
Database (.mdb) file size	1 gigabyte. Because your database can include linked tables in other files, its total size is limited only by available storage capacity.
Number of objects in a database	32,768
Number of characters in an object name	64
Number of characters in a password	14
Number of characters in a user name or group name	20
Number of concurrent users	255


Table specifications

Attribute	Maximum
Number of characters in a table name	64
Number of characters in a field name	64
Number of fields in a table	255
Table size	1 gigabyte
Number of characters in a Text field	255
Number of characters in a Memo field	65,535
Size of an OLE Object field	1 gigabyte
Number of indexes in a table	32
Number of fields in an index	10
Number of characters in a validation message	255
Number of characters in a validation rule	2,048
Number of characters in a table or field description	255
Number of characters in a record (excluding Memo and OLE Object fields)	2,000
Number of characters in a field property setting	255


Query specifications

Attribute	Maximum
Number of tables in a query	32
Number of fields in a recordset	255
Recordset size	1 gigabyte
Number of sorted fields in a query	10
Number of levels of nested queries	50
Number of characters in a cell in the query design grid	1,024
Number of characters for a parameter in a parameter query	255
Number of ANDs in a WHERE or HAVING clause	40
Number of characters in an SQL statement	approximately 64,000


Form and report specifications

Attribute	Maximum
Number of characters in a label	2,048
Number of characters in a text box	65,535
Form or report width	22 in. (55.87 cm)
Section height	22 in. (55.87 cm)
Height of all sections plus section headers (in Design view)	200 in. (508 cm)
Number of levels of nested forms or reports	3
Number of fields or expressions you can sort or group on in a report	10
Number of headers and footers in a report	1 report header/footer; 1 page header/footer; 10 group headers/footers
Number of printed pages in a report	65,536


Macro specifications

Attribute	Maximum
Number of actions in a macro	999
Number of characters in a condition	255
Number of characters in a comment	255
Number of characters in an action argument	255


 Work with imported or linked data

What do you want to do?

Customize a table created by the wizard

Work with data in Datasheet view

Troubleshoot importing problems

Set properties for a linked table


Work with Lookup fields

What do you want to do?

Learn about properties I can use to modify a Lookup field

Learn more about Lookup fields and how they work


What should I do after running the Security Wizard?

What do you want to do?

Learn about creating user or group accounts and granting permissions

Learn more about the basics of securing a database


Work with a database

What do you want to do?

Customize the opening switchboard

Learn about databases generally

Learn about tables — what they are and how they work

Learn about queries — what they are and how they work

Learn about forms — what they are and how they work

Learn about reports — what they are and how they work

Learn about macros — what they are and how they work


 Add new data in Datasheet or Form view

1	In Datasheet or Form view, click  [image]  on the toolbar.

2	Type the data you want, and then press TAB to go to the next field.

3	At the end of the record, press TAB to go to the next record.


Save a record

Microsoft Access automatically saves the record you are adding or editing as soon as you move the insertion point to a different record, or close the form or datasheet you are working on.

•	To save the data in a record while you are editing it, click Save Record on the Records menu.


Delete a record in Datasheet or Form view

1	In Datasheet or Form view, click the record you want to delete.

2	Click  [image]  on the toolbar.

Note   When you delete data, you might want to delete related data in other tables. For example, if you delete a supplier, you should also delete the products that the supplier supplies. In some cases, you can make sure the proper data is deleted by enforcing referential integrity and turning on cascade deletions. For more information, click  [image].


Copy or move data from one field to another

1	In Datasheet view, select the data you want to copy or cut.

How?

2	To copy the data, click  [image]  on the toolbar.

To move the data, click  [image]  on the toolbar.

3	To replace the current value of the destination field, select the whole field.

To insert the data into the existing data, position the insertion point where you want to paste the data.

4	Click  [image]  on the toolbar.

For information on troubleshooting paste problems, click  [image].


Copy or move data from multiple fields in Datasheet view

1	In Datasheet view, select the fields or columns you want to copy or cut.

How?

2	To copy the data, click  [image]  on the toolbar.

To move the data, click  [image]  on the toolbar.

3	Select the destination field or fields, or switch to the application you want to paste the data into, and then select the destination.

4	Click  [image]  on the toolbar.

For information on troubleshooting paste problems, click  [image].


Copy or move records to a datasheet

1	In Datasheet view, select the record or records you want to copy or move.

How?

Note   If you're copying or moving records from another application, be sure the data is arranged in a spreadsheet or table, or separated by tab characters, before you select it.

2	To copy records, click  [image]  on the toolbar.

To move records, click  [image]  on the toolbar.

3	Open the datasheet you want to paste the records into. If necessary, rearrange the columns of the datasheet to match the order of the data you are copying or moving.

4	To replace records with the records you selected, select the records you want to replace, and then click  [image]  on the toolbar.

To append records to the end of the datasheet, click Paste Append on the Edit menu.

If the source datasheet has more fields than the destination datasheet, Microsoft Access doesn't paste the extra fields. For information on troubleshooting paste problems, click  [image].


Copy or move records to a form

1	In Datasheet view, select the record or records you want to copy or move.

How?

2	To copy records, click  [image]  on the toolbar.

To move records, click  [image]  on the toolbar.

3	Open the form you want to paste the records into.

4	To replace records with the records you selected, select the records you want to replace, and then click  [image]  on the toolbar.

To append records, click Paste Append on the Edit menu.

Microsoft Access pastes the records into fields with the same name as the source fields, regardless of their order on the form. If the form you are copying or moving records from has fields that don't exist in the form you are copying or moving records to, Microsoft Access asks you if you want to paste only fields with matching names. If there are no matching field names, the fields are pasted according to the tab order in the destination form, which may not be the order you intend. For that reason, it's a good idea to paste fields with different source and destination names into a datasheet instead of a form.

For information on troubleshooting paste problems, click  [image].


Copy or move records from Microsoft Access to another application

1	In Microsoft Access in Datasheet view, select the data you want to copy or move.

How?

2	To copy data, click  [image]  on the toolbar.

To move data, click  [image]  on the toolbar.

3	Open the application in which you want to paste the data.

4	To replace data with the data from Microsoft Access, select the data you want to replace.

To insert the data into the existing data, position the insertion point where you want to paste the data.

Note   If you're pasting into a Microsoft Excel spreadsheet, select the cell in which you want the first column heading to be. If you're pasting into a Microsoft Word for Windows document, move the insertion point to where you want to place the records. The records are pasted as a table in Word.

5	Click Paste on the Edit menu.

When you paste records into another application, Microsoft Access pastes the field names in the first row, followed by the data.


Copy or move records from another application to Microsoft Access

1	In the other application, select one or more rows you want to copy or move. If you're copying from a word-processing application, make sure the records are arranged in a table or separated by tab characters before you select them.

2	If you are pasting to a datasheet, make sure the columns match the order of the data you want to copy or move.

If you are pasting to a form, and the corresponding controls on the form have the same names as the column names of the data you are copying, Microsoft Access will paste the data to the matching controls. If the column names don’t match, or there are no column names, Microsoft Access will paste the data in the tab order of the form.

3	To copy records, click Copy on the Edit menu.

To move records, click Cut on the Edit menu.

Note   If your application doesn't have these commands, use the comparable method for your application.

4	In Microsoft Access, open the datasheet or form in which you want to paste the records.

5	Do one of the following:

•	To replace records, select those records, and then click  [image]  on the toolbar. In a form, if the record selector isn’t visible, to select the current record, click Select Record on the Edit menu.

•	To append the data as new records, click Paste Append on the Edit menu.


Troubleshoot problems when pasting data

What do you need help with?

I can't paste the data. Why not?

The data I pasted is in the wrong field. Why?


Microsoft Access can't paste the data. Why not?

In most cases, if Microsoft Access can’t paste some or all of the data, it creates the Paste Errors table. In that case, Microsoft Access displays a message telling you that data will be added to the Paste Errors table. For information on displaying the Paste Errors table, click  [image].

There are several reasons why Microsoft Access will not paste some or all of your data:

•	You tried to paste an entire field or fields without selecting a destination. You must select the field or fields that you want to paste to. For information on selecting fields, click  [image].

•	You tried to paste more fields than the datasheet you're pasting to has, or more than the number of fields you selected as a destination. Microsoft Access doesn't paste the extra fields.

•	You tried to paste a value that's not compatible with the data type of the field. For example, you tried to paste a combination of letters and numbers into a field with the Number data type.

•	You tried to paste text that's too long for the field. The setting in the FieldSize property determines the maximum size of a field value. Check the field in table Design view to see the setting.

•	You tried to paste a duplicate value into the table's primary key or into a field that has the Indexed property set to No Duplicates. Check the field in table Design view to see the setting.

•	You tried to paste data into a hidden field. This is not permitted. To display hidden columns, click Unhide Columns on the Format menu.

•	You tried to remove data from or paste data into a disabled, locked, calculated, or AutoNumber field. For more information on these types of fields, click  [image].

•	You don't have permissions to add or edit data in the database object.

•	A value you tried to paste isn't allowed in the field based on the settings of the ValidationRule, InputMask, Required, or AllowZeroLength properties.

•	The validation macro specified for the BeforeUpdate or OnInsert properties canceled the update. The data you tried to paste did not meet the validation requirements.


Display the Paste Errors table

1	In the Database window, click the Tables tab.

2	Double-click Paste Errors.


The data I pasted is in the wrong field. Why?

•	When you paste records into a datasheet, Microsoft Access places them in the order they appear in the columns of the datasheet, regardless of the names of the fields. If you want the data to be pasted according to corresponding field names, paste them into a form in Form view.

•	When you paste records into a form, Microsoft Access places them into fields with the same name as the source fields, regardless of their order on the form. However, if there are no matching field names, the data is placed according to the form's tab order, which may not be the order you intend.


Insert a default value in a field

1	In Datasheet view, click in the field in which you want to insert the default value.

2	Press CTRL+ALT+SPACEBAR.

Note   To see the default value, open the table in table Design view and look at the DefaultValue property.


Insert the value that is in the same field in the previous record

1	In Datasheet view, click in the field in which you want to insert the value.

2	Press CTRL+APOSTROPHE (').


Edit the data in a field

1	In Datasheet or Form view, to edit data within a field, click in the field you want to edit.

To replace the entire value, move the pointer to the leftmost part of the field until it changes into  [image], and then click.

2	Type the text you want to insert.

Notes

•	If you make a typing mistake, press BACKSPACE. If you want to cancel your changes in the current field, press ESC. If you want to cancel your changes in the entire record, press ESC again before you move out of the field.

•	When you move to another record, Microsoft Access saves your changes.


Expand a field or text box to make it easier to edit

1	In Datasheet or Form view, click the field you want to edit.

In Design view of tables, queries, forms, reports, and macros, display a property sheet, and then click in the property box you want to edit.

2	Press SHIFT+F2.

Note   To expand a property box in Design view of tables, queries, forms, reports, and macros, you can also click a property box with the right mouse button, and then click Zoom.


Specify a zero-length string to indicate nonexistent data

•	In Datasheet or Form view, type quotation marks ("  ") to enter a zero-length string in the field.

The field remains a zero-length string, even though the quotation marks disappear when you move to another field or object.

If Microsoft Access displays a message saying "Field can't be a zero-length string," then change the AllowZeroLength field property. For information on changing this property, click  [image].


Make a text or memo field accept zero-length strings

1	In table Design view, click the field in which you want to enter a zero-length string.

2	Make sure the AllowZeroLength field property is set to Yes.

Note   Only text and memo fields can accept zero-length strings.


Undo changes when adding or editing records

•	Click  [image]  on the toolbar to retract your most recent change.

•	Click Undo Saved Record on the Edit menu if you have already saved changes to the current record, or have moved to another record.

As soon as you begin editing another record, apply or remove a filter, or switch to another window, you can't use these methods for correcting changes.


How a field's data type and validation checking determine what data you can enter

When you try to move out of a field after changing data, Microsoft Access validates the data, making sure that the value you entered is allowed in that field. If the value isn't allowed, Microsoft Access alerts you. In order to move off the field, you must either change the data to an acceptable value or undo your changes.

A value might not be allowed in a field for the following reasons:

•	The value isn't compatible with the field's data type (such as Number, Text, or Date). If you enter a value that doesn't match the data type, Microsoft Access attempts to convert the entry to the correct data type. However, some data can't be converted to other data types. For example, you can't store a name in a field with the Number data type.

•	The data breaks a rule set in the ValidationRule property for the field.

•	Data is required in the field, and you've tried to leave it blank.

•	The validation macro specified for the BeforeUpdate property canceled the update.

Microsoft Access also validates data when you move out of a record. Before it saves a record, Microsoft Access makes sure it doesn't break any validation rules set in the ValidationRule property for the record. Additionally, if the table you are editing has a primary key or unique index, Microsoft Access makes sure that the record you are editing doesn't have the same value for the field or fields as another record in the table. If the record can't be saved, you must either make any necessary corrections or click  [image]  to cancel all changes you made to the record.


Troubleshoot editing data in a field

There are several kinds of fields in forms or datasheets that you can't edit. The following fields display values just as regular fields do, but if you try to enter data into them, nothing happens:

•	AutoNumber fields. If a field has an AutoNumber data type, Microsoft Access automatically assigns the next consecutive number or unique random number to this field for each record you add. This type of field is often used as a record ID number or primary key. When you start adding a new record, Microsoft Access automatically fills in the field's value for you and you can't edit it.

•	Calculated fields. Calculated fields display values that Microsoft Access calculates. They are usually based on other fields in your tables, but calculated fields are not stored in tables. You can't edit calculated fields.

•	Locked or disabled fields. If a control on a form has the Locked property set to Yes or the Enabled property set to No, you can't edit the data in the field.

•	Fields in a locked record. If you use Microsoft Access in a multiuser environment and a record is locked by another user, you can't edit the data in the record. When you move to a locked record,  [image]  is displayed in the record selector.

•	Fields in snapshots. While most queries return recordsets that you can edit, some queries return snapshots, which can't be edited.

•	Field in a read-only form or a locked database. If the form you're using has the AllowEdits property set to No or if the underlying data is read-only or locked by another person, you can't edit data in the form.


Check the spelling in a table, query, or form in the Database window

1	In the Database window, click the table, query, or form whose spelling you want to check.

2	Click  [image]  on the toolbar.

Note   In the Spelling dialog box, click Add if you want to add the word that is in the Not In Dictionary box to the custom dictionary that is listed in the Add Words To box.


Check the spelling of data in Datasheet view

1	In Datasheet view, select the records, columns, fields, or text within a field whose spelling you want to check.

How?

2	Click  [image]  on the toolbar.

Note   In the Spelling dialog box, click Add if you want to add the word that is in the Not In Dictionary box to the custom dictionary that is listed in the Add Words To box.


Check the spelling of data in Form view

1	In Form view, select the field or text whose spelling you want to check.

2	Click  [image]  on the toolbar.

Notes

•	In the Spelling dialog box, click Add if you want to add the word that is in the Not In Dictionary box to the custom dictionary that is listed in the Add Words To box.

•	You can select only one field at a time in Form view. To select multiple fields or records, switch to Datasheet view.


Choose a custom dictionary for checking spelling

1	Click  [image]  on the toolbar.

2	Click the custom dictionary you want in the Add Words To box.


Correct two capital letters in a row automatically when I'm entering data

1	On the Tools menu, click AutoCorrect.

2	Select the Correct TWo INitial CApitals check box.


Automatically capitalize names of days when I'm entering data

1	On the Tools menu, click AutoCorrect.

2	Select the Capitalize Names Of Days check box.


Automatically correct typing when I'm entering data

Use AutoCorrect to automatically correct text that you frequently mistype, and to automatically replace abbreviations with long names. For example, you can create an entry "esq" for "Martin R. Esquivel." Whenever you type esq followed by a space or punctuation mark, Microsoft Access automatically replaces "esq" with the name Martin R. Esquivel.

1	On the Tools menu, click AutoCorrect.

2	Select the Replace Text As You Type check box.

3	In the Replace box, type the text that you want corrected automatically.

4	In the With box, type the corrected text.

5	Click Add.

Notes

•	AutoCorrect won't correct text that was typed before you selected the Replace Text As You Type check box.

•	If in the preceding example you actually want "esq" to appear in one case, clear the Replace Text As You Type box, type esq in a field and save the field by moving to another record. Then select the Replace Text As You Type box again. Microsoft Access will not change the previously typed and saved "esq."


Stop the automatic correction of a particular entry I make when I'm entering data

1	On the Tools menu, click AutoCorrect.

2	Click the entry you want to delete in the box at the bottom.

3	Click Delete.


Add an AutoCorrect entry while checking spelling

1	In the Spelling dialog box, in the Change To box, type the corrected text.

2	Click AutoCorrect in the Spelling dialog box.

When you type the text that is in the Not In Dictionary box as you add data to tables or forms, Microsoft Access will automatically change it to the text in the Change To box.


Stop automatic corrections that occur when I'm entering data

1	On the Tools menu, click AutoCorrect.

2	Clear the check boxes for the options you want to turn off.


 Import or link data

Important   Before you can import or link data, you must create or open a Microsoft Access database to contain the imported or linked tables. For more information on creating a database, click  [image].

Microsoft Access can import or link table data from other Microsoft Access databases (version 1.x, 2.0, and 7.0), as well as data from other programs and file formats, such as Microsoft Excel, dBASE, Microsoft FoxPro, or Paradox. Importing data creates a copy of its information in a new table in your Microsoft Access database. The source table or file is not altered in this process. Linking data enables you to read and update data in the external data source without importing. The external data source's format is not altered so that you can continue to use the file with the program that originally created it, but you can add, delete, or edit its data using Microsoft Access as well.

Microsoft Access uses different icons to represent linked tables and tables that are stored in the current database. The icon that represents a linked table remains in the Database window along with tables in the current database, so you can open the table whenever you want. Microsoft Access displays a different icon for tables from each type of source database. If you delete the icon for a linked table, you delete the link to the table, not the external table itself.

When importing data, you can't append data to existing tables (except when importing spreadsheet or text files). However, once you have imported a table, you can perform an append query to add its data to another table.

You can also import database objects other than tables, such as forms or reports, from another Microsoft Access database. When importing objects from another Microsoft Access database, you can choose to import all or just a subset of those objects in a single operation.

If you need to perform an import operation on an ongoing basis, you can automate the process of importing data using macros or Visual Basic for applications code.

What do you want to do?

Get more information to help decide whether to import or link tables

Import or link data from other programs and file formats

Import or link tables from another Microsoft Access database

Import database objects other than tables from another Microsoft Access database

Import all objects from another Microsoft Access database

Automate importing data using a macro or Visual Basic code


Should I import or link a table?

Microsoft Access provides two choices for using data from an external source:

•	Import the data into a new Microsoft Access table in the current database.

•	Leave the data in its current location and use it in its current format without importing it — this is called linking.

Examples of external data sources include tables from other Microsoft Access databases located on a network, and data from other programs such as Microsoft Excel, Microsoft FoxPro, Paradox, and Microsoft SQL Server.

If you know you will use your data only in Microsoft Access, you should import it. Microsoft Access generally works faster with its own tables, and if you need to, you can modify the imported table to meet your needs just like any other table created in Microsoft Access.

If the data you want to use is also being updated by a program other than Microsoft Access, you should link it. Using this approach, the current methods of updating, managing, and sharing the data can remain in place, and you can use Microsoft Access to work with the data as well. For example, you can create queries, forms, and reports that use the external data, combine external data with the data in Microsoft Access tables, and even view and edit the external data while others are using it in the original program.

You can also link tables from other Microsoft Access databases. For example, you might want to use a table from another Microsoft Access database that is shared on a network. This is particularly useful if you want to store all of your tables in one database on a network server, while keeping forms, reports, and other objects in a separate database that is copied among users of the shared database. You can easily split an existing database into two databases using the Database Splitter subcommand on the Add-ins command on the Tools menu. For more information, click  [image].


Import or link tables from another Microsoft Access database

1	Open a database, or switch to the Database window for the open database.

2	To import tables, on the File menu, point to Get External Data, and then click Import.

To link tables, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, make sure Microsoft Access (.mdb) is selected.

4	Click the arrow to the right of the Look In box, select the drive and folder where the Microsoft Access database (.mdb) you want to import or link is located, and then double-click the database's icon.

5	Click each table you want to import or link.

6	If you're importing, and you want to import just the selected tables' definitions (not the data they contain), click Options, and then, under Import Tables, click Definition Only.

If you're importing, and you want to include relationships, custom toolbars, or import/export specifications, click Options, and then, under Import, select the items you want to import.

7	Click OK to import or link the selected tables.

Notes

•	If the database you select in step 4 has a database password, you must provide the password before you can continue. Linking tables from such a database may have unforeseen consequences. For more information, click  [image].

•	If you link two tables from the same Microsoft Access database, any relationship that was established between the tables in the other database remains in effect.

•	If you import a table that contains Lookup fields, you should also import the tables or queries that the Lookup fields refer to. If you don’t do this, when you open the imported table in Datasheet view, Microsoft Access displays an error message for each missing table or query. To correct this problem, import the missing tables or queries. If you can’t or don’t want to import the missing tables or queries, open the imported table in Design view, click on a Lookup field that refers to a missing table or query, click the Lookup tab, and then set the DisplayControl property to Text Box. Repeat this procedure for each Lookup field that refers to a missing table or query.


Import database objects other than tables from another Microsoft Access database

1	Open a database, or switch to the Database window for the open database.

2	On the File menu, point to Get External Data, and then click Import. The Import dialog box is displayed.

3	In the Files Of Type box, make sure Microsoft Access (.mdb) is selected.

4	Click the arrow to the right of the Look In box, select the drive and folder where the Microsoft Access database (.mdb) you want to import from is located, and then double-click the database's icon.

5	Click the tab for the kind of object you want to import, and then click each object you want to import. Repeat this step for each kind of object you want to import.

If you're importing select queries, and you want to import them as tables, click Options, and then click As Tables. Action queries import as queries no matter how this option is set.

6	Click OK to import all of the selected objects.


Import all database objects from another Microsoft Access database

You can import all of a database's objects into another database at one time. This can be particularly useful if you have created a secure Microsoft Access database and you want to change the database owner.

1	Open the database into which you want to import the database, or switch to the Database window for the open database.

2	On the File menu, point to Get External Data, and then click Import. The Import dialog box is displayed.

3	In the Files Of Type box, make sure Microsoft Access (.mdb) is selected.

4	Click the arrow to the right of the Look In box, select the drive and folder where the Microsoft Access database (.mdb) you want to import from is located, and then double-click the database's icon.

5	Click Select All to import all tables. If you want to import just the tables' definitions (not the data they contain), click Options, and then click Definition Only. If you want to include relationships, custom toolbars, or import/export specifications, click Options, and then, under Import, select the items you want included.

6	Click the Queries tab to display the available queries, and then click Select All to import all queries.

7	Repeat step 6 for forms, reports, macros, and modules.

8	Click OK to import all of the selected objects.


Import or link data from other programs and file formats

You can import or link data from a broad variety of file formats from other programs. Microsoft Access can import from the following file formats.

Data source	Version or format supported
Microsoft FoxPro	2.0, 2.5, 2.6, and 3.0 (import only)
dBASE	III, III+, IV, and 5
Paradox	3.x, 4.x, and 5.0
SQL tables, and data from programs and databases that support the ODBC protocol	Including but not limited to Microsoft SQL Server
Microsoft Excel spreadsheets	2.0, 3.0, 4.0, 5.0, and 7.0
Lotus 1-2-3 spreadsheets	.WKS, .WK1, and .WK3 formats
Delimited text files	Most files with values separated by commas, tabs, or other characters; must be in MS-DOS or Windows ANSI text format
Fixed-width text files	Most files with values arranged so that each field has a certain width; must be in MS-DOS or Windows ANSI text format
If you have data in any of these programs or formats, you can either import or link these files. If you have a program whose data is not stored in one of these formats, but the program can export, convert, or save its data as one of these formats, you can import that data as well.

If you don't know if you should import or link your data, click  [image].

What do you want to do?

Import or link a FoxPro or dBASE table

Import or link a Paradox table

Import or link an SQL table or other ODBC data sources

Import or link a spreadsheet

Import or link a delimited or fixed-width text file

Import a Microsoft Works database


Import a Microsoft Works database

You can't import a Microsoft Works database (.wdb) directly into Microsoft Access. You must use Microsoft Works to save the file to one of the file formats that Microsoft Access can import first.

1	Open the database using Microsoft Works.

2	On the File menu, click Save As.

3	In the Save File As Type box, select dBASE IV, and then click OK.

4	Import the dBASE IV .dbf file created in step 3 into Microsoft Access.

How?


Import or link Microsoft FoxPro or dBASE files

You can import or link .dbf files in FoxPro 2.0, 2.5, or 2.6, and dBASE III, IV, or 5 formats. You can also import, but not link FoxPro 3.0 format.

1	Open a database, or switch to the Database window for the open database.

2	To import files, on the File menu, point to Get External Data, and then click Import.

To link files, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, select FoxPro or dBASE.

4	Click the arrow to the right of the Look In box, select the drive and folder where the .dbf file is located, and then double-click its icon.

•	If you're importing, Microsoft Access creates a table named after the file you selected and imports the data from the .dbf file. Go to step 7.

•	If you're linking, Microsoft Access displays a dialog box where you can associate FoxPro or dBASE index files. Go to step 5.

5	Double-click each FoxPro index (.idx or .cdx) file or dBASE index (.ndx or .mdx) file you want to use, and then click Close. If there are no indexes, click Cancel to continue.

6	In the Select Unique Record Identifier dialog box, select an index that uniquely identifies each record. This index must contain no duplicate values, or Microsoft Access might not be able to properly update data in queries with joins.

7	If you want to import or link another FoxPro or dBASE file, repeat steps 4 through 6. When you have finished importing or linking, click Close.

Notes

•	After importing or linking a .dbf file, you can set field properties for the table. If you import a .dbf file, you might also want to set a primary key for the table. For more information, click  [image].

•	If you link a .dbf file and associate an index (.idx, .cdx, .ndx, or .mdx) file, Microsoft Access needs the index file in order to open the linked table. If you delete or move FoxPro or dBASE index files or the information (.inf) file that Microsoft Access creates, you won't be able to open the linked table.

•	When you use Microsoft Access to update the data in your .dbf file, it updates the index files to reflect your changes. If you use FoxPro or dBASE to update data, you must update the associated indexes within FoxPro or dBASE as well. Microsoft Access can't use a linked table if the indexes you specified aren't current.

•	If your FoxPro or dBASE tables are stored on a read-only drive or CD-ROM, Microsoft Access can't create an .inf file in the same folder as the .dbf files. To link a table on a read-only drive, you must specify the path where you want Microsoft Access to create the .inf file in the Windows Registry. For more information, click  [image].


Import or link Paradox tables

You can import or link Paradox or Paradox for Windows tables (versions 3.x, 4.x, and 5.0).

1	Open a database, or switch to the Database window for the open database.

2	To import tables, on the File menu, point to Get External Data, and then click Import.

To link tables, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, select Paradox (*.db).

4	Click the arrow to the right of the Look In box, select the drive and folder where the .db file is located, and then double-click its icon.

5	If the Paradox table you select is encrypted, Microsoft Access prompts you for the password. Type the password for the Paradox table, and then click OK.

6	If you want to import or link another Paradox table, repeat steps 4 through 6. When you have finished importing or linking, click Close.

Notes

•	If you link a Paradox table that has a primary key, Microsoft Access needs the associated index (.px) file in order to open the linked table. If you link a Paradox table with a Memo field, Microsoft Access needs the associated memo (.mb) file in order to open the linked table. If you delete or move these files, you won't be able to open the linked table.

•	If you link a Paradox table that doesn't have a primary key, you won't be able to update data in the table using Microsoft Access. If you want the table to be updatable, define a primary key for the table in Paradox.

•	OLE objects stored in a linked or imported Paradox table can't be opened from within Microsoft Access.

•	When you link a Paradox table that resides on a network server and is shared by multiple users, you must set the ParadoxNetPath key in the Windows Registry to the path to the Paradox.net or Pdoxusrs.net file. Additionally, if you use Paradox version 4.x for sharing data in your workgroup, you must set the ParadoxNetStyle key to "4.x." For more information on making these settings, click  [image].


Import or link SQL database tables or data from other ODBC data sources

You can import or link data from ODBC databases such as Microsoft SQL Server and Sybase SQL Server, as well as other programs that provide drivers compliant with ODBC Level 1 to access their data files.

Note   If you chose the Typical option when you installed Microsoft Access, the SQL Server driver and ODBC support files will not be installed, and you will not be able to import or link from any ODBC data source. In this case, re-run Setup to install the SQL Server driver. Additionally, for each ODBC data source that you want to use, you must have the appropriate ODBC driver installed on your computer before you can import or link this database. For more information on installing and configuring ODBC drivers, click  [image].

1	Open a database, or switch to the Database window for the open database.

2	To import tables, on the File menu, point to Get External Data, and then click Import.

To link tables, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, select ODBC Databases.

The SQL Data Sources dialog box is displayed listing all ODBC data sources currently defined for the ODBC drivers installed on your computer. This list might include drivers that have not been tested and verified for use with Microsoft Access. Contact the driver vendor for verification.

If you want to define a new data source for any installed driver, click New, double-click the name of the ODBC driver, enter the data source definition (this will vary depending on the requirements of the ODBC driver), and then click OK.

4	In the SQL Data Sources dialog box, double-click the ODBC data source that contains the data you want to import or link.

5	If the ODBC data source that you selected requires you to log on, enter your logon ID and password (additional information might also be required), and then click OK.

Microsoft Access connects to the ODBC data source and displays the list of tables that you can import or link.

6	If you're linking a table, select the Save The Login ID And Password check box if you want to save this information for the table in the current database and not require users to enter this information. If you leave the check box cleared, all users must enter the logon ID and password every time they open the table in each new session with Microsoft Access. Your SQL database administrator can also choose to disable this check box, requiring all users to enter the logon ID and password each time they connect to the SQL database. For information on how to disable the Save The Login ID And Password check box, click  [image].

If you're importing a table, skip this step.

7	Click each table you want to import or link, and then click OK. If you're linking a table and it doesn't have an index that uniquely identifies each record, Microsoft Access displays a list of the fields in the linked table. Click a field or a combination of fields that will uniquely identify each record, and then click OK. When you have finished importing or linking, click Close.

Notes

•	After importing or linking an SQL database table, you can set field properties for the table. If you import a table, you might want to set a primary key for the table. For more information, click  [image].

•	If you encounter an error while importing, linking, or using an SQL database table, there might be a problem with your account on the SQL database server or with the database itself. If you can't access an SQL database table, contact the SQL database administrator.

•	To edit a linked SQL database table, usually the table must contain a unique index on the server. If you want to edit a table that doesn't have a unique index or you want to edit an SQL view, you can create an index within Microsoft Access that the SQL database isn't aware of. You do that by creating a data-definition query, using the CREATE INDEX statement. Be aware, however, that the index must be created on a field or combination of fields in which each value is unique. If the field contains any duplicate values, all updates to the table will fail. To delete the index, use another data-definition query. For more information on creating such a data-definition query, click  [image].

•	If the structure of an SQL database table changes after you link it, use the Linked Table Manager to refresh the link. For more information, click  [image].


Using the MSysConf table with linked SQL databases

If you are administering an SQL database that uses Microsoft Access as a front end, you can create a table in your SQL database named MSysConf to help you control communication between the two applications. The MSysConf table has two potential functions:

•	It can disable the feature that enables users to save the logon ID and password for a linked SQL database in the Microsoft Access front end.

•	It can optimize how Microsoft Access performs background population of records during idle time by setting the number of rows of data that are retrieved at one time and the number of seconds of delay between each retrieval. Microsoft Access uses a default of 100 records returned every 10 seconds if you don't create the MSysConf table.

The structure of the MSysConf table

The SQL database table MSysConf should have the following structure.

Column name	Data type	Allows null?
Config	A data type that corresponds to a 2-byte integer	No
chValue	VARCHAR(255)	Yes
nValue	A data type that corresponds to a 4-byte integer	Yes
Comments	VARCHAR(255)	Yes
Note   If the data source you're working with is case-sensitive, use the table and column names exactly as shown.

All users must have permission to use the SELECT statement on this table, and only the system administrator should have INSERT/UPDATE/DELETE permission.

The data in the MSysConf table

There are three valid records in the MSysConf table. The following table shows what values you should enter in the Config and nValue field. The other columns are reserved for future use, and their contents are ignored.

Config	nValue	Meaning
101	0	Don't allow local storage of the logon ID and password in linked tables.
101	1	Allow local storage of the logon ID and password in linked tables.
102	D	D is the delay in seconds between each retrieval.
103	N	N is the number of rows retrieved.
Notes

•	Setting a higher delay time decreases network traffic, but increases the amount of time that read-locks are left on data (if the server uses read-locks).

•	If you create an MSysConf table, it must be set up properly or you will not be able to connect to the SQL database table at all.


Delete the link to a linked table

1	In the Database window, click the Tables tab, and then click the linked table.

2	Press the DEL key. Microsoft Access deletes the link and removes the table's name from the list.

Note   When you delete a linked table, you are deleting only the information that Microsoft Access uses to open the table, not the table itself. You can link the same table again later if you want.


View, refresh, or change the filename and path for linked tables

Use this procedure to view or to refresh links when the structure or location of a linked table has changed. The Linked Table Manager lists the paths to all currently linked tables.

To view or refresh links

1	Open the database that contains links to tables.

2	On the Tools menu, point to Add-ins, and then click Linked Table Manager.

3	Select the check box for the tables whose links you want to refresh.

4	Click OK to refresh the links.

Microsoft Access confirms a successful refresh or, if the table wasn't found, displays the Select New Location of <table name> dialog box in which you specify its new location.

If several selected tables have moved to the new location you specify, the Linked Table Manager searches that location for all selected tables, and updates all links in one step.

To change the path for a set of linked tables

1	Open the database that contains links to tables.

2	On the Tools menu, point to Add-ins, and then click Linked Table Manager.

3	Select the Always Prompt For A New Location check box.

4	Select the check box for the tables whose links you want to change, and then click OK.

5	In the Select New Location dialog box, specify the new location, and then click OK.

Notes

•	The Linked Table Manager doesn't move database or table files. If you want to move database or table files to a new location, use the Windows Explorer, My Computer, or the MS-DOS Copy or Move commands. Once you have moved a database or table, you can use the Linked Table Manager to refresh links to its linked tables.

•	The Linked Table Manager can't refresh links to Microsoft Access tables whose names were changed after they were linked. You must delete the current link, and then link such tables again.


Renaming and setting properties for linked tables

When you open a linked table in Design view, it looks much like a regular Microsoft Access table. Although you can't change the way the linked table and its fields are defined in the external database, you can set the properties that control the way the fields appear in Microsoft Access. Changes you make to properties for linked tables affect only how Microsoft Access handles and displays data from the linked table; no changes are made to the source table. Field properties you can set for linked tables are listed in the following table.

Property	Effect
Format	Controls how data is displayed in a field
DecimalPlaces	Controls the number of decimal places displayed
InputMask	Is used to create a data input mask with separator characters and blanks to fill in
Caption	Changes the name used for a field's datasheet column heading, and specifies a default name to be used as a label when adding a field to a form
For information on setting field properties, click  [image].

You can't change other field properties for linked tables. However, to help make data entry more efficient and reliable, you can create forms that you use to add or edit data in your linked tables and set properties for controls that are bound to fields from your linked tables. For example, you might want to set the DefaultValue, ValidationRule, and ValidationText properties for controls in those forms.

Note   If you link tables from another Microsoft Access database, the tables use the property settings from the database they are stored in. For example, if a table has validation rules in the original database, data you enter in the linked table must follow these rules as well. If you need to change these properties, you must open the table in the database it is stored in.

Renaming linked tables

You might want to rename linked tables. Since Microsoft Access table names can contain up to 64 characters and can contain spaces, you might want to give a linked table a more descriptive name after you link it. For example, if you link a dBASE table named SLSDATA, you could rename the linked table "Sales Data 1995 (from dBASE)." Note that this won't rename the table itself, just the name Microsoft Access uses to refer to the link to that table.

Rename a linked table using the same procedure as renaming other database objects. For more information, click  [image].


Achieving optimal performance with linked tables

Although you can use linked tables as if they're regular Microsoft Access tables, it's important to keep in mind that they aren't actually in your Microsoft Access database. Each time you view data in a linked table, Microsoft Access has to retrieve records from another file. This can take time, especially if the linked table is on a network or in an SQL database.

If you're using a linked table on a network or in an SQL database, follow these guidelines for best results:

•	View only the data you need. Don't page up and down unnecessarily in the datasheet. Avoid jumping to the last record in a large table. If you want to add new records to a large table, use the Data Entry command on the Records menu to avoid loading existing records into memory.

•	Use filters or queries to limit the number of records that you view in a form or datasheet. This way, Microsoft Access can transfer less data over the network.

•	In queries that involve linked tables, avoid using functions in query criteria. In particular, avoid using domain aggregate functions, such as Dsum, anywhere in your queries. When you use a domain aggregate function, Microsoft Access retrieves all of the data in the linked table to execute the query.

•	If you often add records to a linked table, create a form for adding records that has the DataEntry property set to Yes. When you open the form to enter new data, Microsoft Access doesn't display any existing records. This property setting saves time because Microsoft Access doesn't have to retrieve all the records in the linked table.

•	Remember that other users might be trying to use an external table at the same time you are. When a Microsoft Access database is on a network, you should avoid locking records longer than necessary.


Import or link a spreadsheet

You can import or link data from a Microsoft Excel (versions 2.x, 3.0, 4.0, 5.0, and 7.0) spreadsheet. You can only import from a Lotus (1-2-3 or 1-2-3/W) spreadsheet. In both cases, the data in the spreadsheet must be arranged in an appropriate tabular format. Before you proceed, make sure that the spreadsheet has the same type of data in each field (column) and the same fields in every row.

You can import or link all the data from a spreadsheet, or just the data from a named range of cells. Although you normally create a new table in Microsoft Access for the data, you can also append the data to an existing table as long as your spreadsheet column headings match the table's field names, or its column order is the same.

1	Open a database, or switch to the Database window for the open database.

2	To import a spreadsheet, on the File menu, point to Get External Data, and then click Import.

To link a spreadsheet, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, select Microsoft Excel or Lotus 1-2-3. If you clicked Link in step 2, Lotus 1-2-3 won’t be available; you can’t link Lotus 1-2-3 spreadsheets.

4	Click the arrow to the right of the Look In box, select the drive and folder where the spreadsheet file is located, and then double-click its icon.

5	Follow the directions in the Import Spreadsheet Wizard dialog boxes. If you are importing from a Microsoft Excel version 5.0 or 7.0 workbook, you can import from one worksheet within a workbook. You can't import from any other multiple-spreadsheet files, such as Microsoft Excel version 4.0 workbooks or Lotus notebooks. To import from these files, you must first save each spreadsheet as an individual file.

Notes

•	If importing a spreadsheet takes an unexpectedly long time, it might be because many errors are occurring. To cancel importing, press CTRL+BREAK.

•	Microsoft Access attempts to assign the appropriate data type to imported fields, but you should check your fields to make sure they are set to the data type you want. For example, a phone number or postal code field might be imported as a Number field, but should be changed to a Text field in Microsoft Access because it is unlikely that you will perform any calculations on these types of fields. You should also check and set field properties, such as formatting, as necessary.

•	You can import data from other programs' spreadsheets, as long as they are in the Microsoft Excel or Lotus 1-2-3 format.


Import or link a delimited or fixed-width text file

You can import or link data from a delimited text file or fixed-width text file. Before you import or link, make sure that the file has the same type of data in each field and the same fields in every row. Although you usually create a new table in Microsoft Access for the data, you can append the data to an existing table as long as the first row of your text file contains matching field names, or its column order is the same.

1	Open a database, or switch to the Database window for the open database.

2	To import data, on the File menu, point to Get External Data, and then click Import.

To link data, on the File menu, point to Get External Data, and then click Link.

3	In the Import (or Link) dialog box, in the Files Of Type box, select Text Files.

4	Click the arrow to the right of the Look In box, select the drive and folder where the file is located, and then double-click its icon.

5	Follow the directions in the Text Import Wizard dialog boxes.

Notes

•	If importing a text file takes an unexpectedly long time, it might be because many errors are occurring. To cancel importing, press CTRL+BREAK.

•	In a fixed-width text file, you can ignore fields at the end of a record that contain no data. In addition, the last field with data in the record can be less than the maximum width.

•	If all the records in a fixed-width text file are the same length, there can be an embedded row separator (such as a carriage return and linefeed) in the middle of a record. If the records aren't all the same length, embedded row separators should not be used because Microsoft Access will treat the embedded row separator as the end of the record.


Troubleshoot text or spreadsheet import errors

If Microsoft Access can't import one or more records, it reports the number of errors it encountered.

What do you need help with?

Errors are reported when I import a spreadsheet or text file. Why?

Errors are reported when I append a spreadsheet or text file to an existing table. Why?


Errors are reported when I import a spreadsheet or text file. Why?

For each record that causes an error, Microsoft Access adds a row to a table called Import Errors. To view the list of errors that were encountered, open the Import Errors table in the Database window. For more information on the Import Errors table error messages, click  [image].

Here are the most typical reasons for encountering errors:

•	There is data in a field that can't be stored in the data type Microsoft Access has assigned to that field. For example, you might have accidentally included a text value in a field that should only contain numbers or dates. Or perhaps a row in your text file or spreadsheet contains summary information or extraneous characters.

If you think Microsoft Access assigned the correct data type for this field, edit your text file or spreadsheet to correct errors, and then import again. Otherwise, import again and specify the appropriate data type.

•	Microsoft Access has assigned an incorrect data type to a field. Microsoft Access assigns the data type for each field based on the data in the first row it imports. For example, if a field that contains mostly text values has a number in the first row, Microsoft Access assigns the Number data type and then can't import the rest of the records.

Import again and specify the appropriate data type when importing.

•	One or more rows in the text file or spreadsheet contain more fields than the first row. For example, the second row in a file might have an extra field delimiter character followed by a value that Microsoft Access can't fit in the new table.

Edit your text file or spreadsheet so that each row has the same number of fields, and import again.


Errors are reported when I append a spreadsheet or text file. Why?

For each record that causes an error, Microsoft Access adds a row to a table called Import Errors. To view the complete list of errors that were encountered, open the Import Errors table in the Database window. For more information on the Import Errors table error messages, click  [image].

Appended records must be compatible with the existing table's structure: Each field must have the same data type as the corresponding field in the destination table, and the fields must be in the same order (unless you're using the first row of the file as field names, in which case the field names must match). If you suspect that the problem is with the data you're appending, edit your spreadsheet or text file, and then import again. Alternatively, you might need to change the destination table itself (reorder the fields or change data types, for example).

Here are the most typical reasons for encountering errors:

•	The data in a field is inappropriate for the data type of the destination field. For example, the destination field has the Date/Time data type, but the data contains a text value that Microsoft Access can't recognize as a date or time.

•	The data in a numeric field is too large for the field size of the destination field. For example, the destination field has the FieldSize property set to Byte, but the data contains a value greater than 255.

•	Records you are importing contain duplicate values that can't be stored in the primary key of the destination table or in any field in the table that has the Indexed property set to Yes (No Duplicates).

•	One or more rows in the text file or spreadsheet contain more fields than the destination table.


Import Errors table messages

The Import Errors table contains descriptions of the errors Microsoft Access encounters when trying to import your text file or spreadsheet. The table includes field names and row numbers that indicate which data has caused errors.

If Microsoft Access reports errors, open the Import Errors table and try to determine why Microsoft Access can't import all of the records. The following table lists the possible import errors and describes their causes.

Error	Description
Field Truncation	A text value in the file is longer than the FieldSize property setting for this field.
Type Conversion Failure	A value in the text file or spreadsheet is the wrong data type for this field.
Key Violation	This record's primary key value is a duplicate — it already exists in the table.
Validation Rule Failure	A value breaks the rule set using the ValidationRule property for this field or for the table.
Null in Required Field	A null value isn't allowed in this field because the Required property for the field is set to Yes.
Unparsable Record	A text value contains the text delimiter character (usually quotation marks). Whenever a value contains the delimiter character, the character must be repeated twice in the text file; for example: "10 - 3 1/2"" disks/box"
If you suspect that the problem is with your data, edit your text file or spreadsheet. If you're appending records to an existing table, you might need to change the table itself (reorder the fields or change data types, for example). When you have solved the problem, import the data again.


Troubleshoot problems with linked tables

What do you want help with?

I can't open or update a linked FoxPro or dBASE table. Why?

I can't open or update a linked Paradox table. Why?

I can't open or update a linked SQL table. Why?


I can't open or update a linked FoxPro or dBASE table. Why?

•	If you link a .dbf file and associate an index (.idx, .cdx, .ndx, or .mdx) file, Microsoft Access needs the index file in order to open the linked table. If you delete or move FoxPro or dBASE index files or the information (.inf) file Microsoft Access creates, you won't be able to open the linked table.

•	If you link a FoxPro or dBASE table with a memo field, Microsoft Access needs the associated memo (.dbt) file in order to open the linked table. If you delete or move this file, you won't be able to open the linked table.

•	When you use Microsoft Access to update the data in your .dbf file, it updates the index files to reflect your changes. If you use FoxPro or dBASE to update data, you must update the associated indexes within FoxPro or dBASE as well. Microsoft Access can't use a linked table if the indexes you specified aren't current.

•	You can't update a FoxPro or dBASE table if its data (.dbf) or index (.idx, .cdx, .ndx, or .mdx) files are set to read-only. To check this, use My Computer or Windows Explorer to display the folder where the files are located, click a file with the right mouse button, click Properties, and then click the General tab. If the Read-only check box is selected, clear it and then click OK.

•	If your FoxPro or dBASE tables are stored on a read-only drive or CD-ROM, Microsoft Access can't create an .inf file in the same folder as the .dbf files, and you won't be able to link them. To link a table on a read-only drive, you must specify the path where you want Microsoft Access to create the .inf file in the Windows Registry. For more information, click  [image].


I can't open or update a linked Paradox table. Why?

•	If you link a Paradox table that has a primary key, Microsoft Access needs the associated index (.px) file in order to open the linked table. If you link a Paradox table with a memo field, Microsoft Access needs the associated memo (.mb) file in order to open the linked table. If you delete or move these files, you won't be able to open the linked table.

•	If you link a Paradox table that doesn't have a primary key, you won't be able to update data in the table using Microsoft Access. If you want the table to be updatable, define a primary key for the table in Paradox.

•	OLE objects stored in a linked or imported Paradox table can't be opened from within Microsoft Access.

•	You can't update a table if its data (.dbf) or index (.idx, .cdx, .ndx, or .mdx) files are set to read-only. To check this, use My Computer or Windows Explorer to display the folder where the files are located, click a file with the right mouse button, click Properties, and then click the General tab. If the Read-only check box is selected, clear it and then click OK.

•	You can't update a Paradox table if its data (.db) or index file (.px) is set to read-only. To check this, use My Computer or Windows Explorer to display the folder where the files are located, click a file with the right mouse button, click Properties, and then click the General tab. If the Read-only check box is selected, clear it and then click OK.

•	When you link a Paradox table that resides on a server and is shared by multiple users, you must set the ParadoxNetPath key in the Windows Registry to the path to the Paradox.net or Pdoxusrs.net file. Additionally, if you use Paradox version 4.x for sharing data in your workgroup, you must set the ParadoxNetStyle key to "4.x." For more information on making these settings, click  [image].


I can't open or update a linked SQL table. Why?

•	Microsoft Access requires a unique index to update, delete, or insert data in a linked SQL table or view. When you link a Microsoft SQL Server updatable view, or an SQL database table that doesn't have a unique index, Microsoft Access asks you to select one or more fields to generate a unique index. However, Microsoft Access doesn't test to make sure the field or fields you selected actually uniquely identify each record. If there are duplicates in the index Microsoft Access builds, you won't be able to update those records.

If you think the field or fields you selected did not create a unique index, delete the link to the table, link it again, and then select the appropriate field or fields to establish a unique index.

Alternatively, you can create an index within Microsoft Access by creating a data-definition query, using the CREATE INDEX statement. Again, be sure to select a field or combination of fields that will uniquely identify each record. If the index generated contains any duplicate values, all updates to the table will fail. To delete the index, use another data-definition query. For more information on creating such a data-definition query, click  [image].

•	If you link an SQL table that has its own unique index, and that index is defined for a field that is a floating-point number, it might not be updatable. Because servers vary in how precisely they handle floating-point data, sometimes precision loss can occur. The actual difference is usually slight enough to be inconsequential, but if the data forms part of the SQL table's bookmark, affected records might appear to Microsoft Access to be deleted.

If you encounter other errors while importing, linking, or using an SQL database table, there might be a problem with your account on the SQL database server or with the database itself. If you can't access an SQL database table, contact the SQL database administrator.


Switch between views of a table

After you open a table, you can switch between two views: Design view to create and modify the structure of a table, or Datasheet view to view, add, delete, and edit data in a table. The toolbar button to switch views is a toggle button: when your table is displayed in Datasheet view, only the button to switch to Design view is displayed, and vice versa.

To switch to Design view from Datasheet view

•	Click  [image]  on the toolbar.

To switch to Datasheet view from Design view

•	Click  [image]  on the toolbar.


Create a table

Microsoft Access provides two ways to create a table. You can create a blank (empty) table for entering your own data, or you can create a table using existing data from another source.

What do you want to do?

Create a new blank table

Create a new table from existing data

Find out more about what tables are and how they are used


Create a new blank table

Microsoft Access provides four ways to create a blank (empty) table:

•	Use a Database Wizard to create in one operation all the tables, forms, and reports required for an entire database. A Database Wizard creates a new database; it can't be used to add new tables, forms, or reports to an existing database.

•	Use the Table Wizard to choose the fields for your table from a variety of predefined table types such as business contacts, household inventory, or medical records.

•	Enter data directly into a blank datasheet. When you save the new datasheet, Microsoft Access will analyze your data and automatically assign the appropriate data type and format for each field.

•	Use Design view to specify all of your table details from scratch.

Regardless of which method you use to create a table, you can use table Design view at any time to customize your table further, such as adding new fields, setting default values, or creating input masks.

What do you want to do?

Create a database using a Database Wizard

Create a table using the Table Wizard

Create a table by entering data in a datasheet

Create a table from scratch using Design view


 Create a new table from existing data

Microsoft Access provides two ways to create a table from existing data:

•	You can import or link data from another Microsoft Access database or data in a variety of file formats from other programs.

•	You can perform a make-table query to create a table based on data in a current table. For example, you can use make-table queries to archive old records, to make backup copies of your tables, to select a group of records to export to another database, or to use as a basis for reports that display data from a specific time.

What do you want to do?

Create a table by importing or linking data

Create a new table using a make-table query


Create a table using the Table Wizard

1	In the Database window, click the Tables tab, and then click New.

2	Double-click Table Wizard.

3	Follow the directions in the Table Wizard dialog boxes.

Note   If you want to modify or extend the resulting table, you can do so in Design view when you are finished using the Table Wizard.


Create a table from scratch using Design view

1	In the Database window, click the Tables tab, and then click New.

2	Double-click Design View.

3	Define each of the fields in your table.

How?

4	It is recommended that you designate a primary key field before saving your table. If you don't, Microsoft Access asks if you want it to create one for you when you save the table.

How?

5	When you are ready to save your table, click  [image]  on the toolbar, and then type a name for the table following Microsoft Access object-naming rules; click OK.

If you'd like to see an overview of the elements that you can customize in a Microsoft Access table, click  [image].


Open a table in Design view

•	If the table is already open in Datasheet view, click  [image]  on the toolbar to switch to Design view.

If the table isn't open, go to the Database window, click the Tables tab, click the desired table, and then click Design.


Open a table in Datasheet view

•	If the table is open in Design view, click  [image]  on the toolbar to switch to Datasheet view.

If the table isn't open, go to the Database window, click the Tables tab, and double-click the desired table.


Create a table by entering data in a datasheet

1	In the Database window, click the Tables tab, and then click New.

2	Double-click Datasheet View. A blank datasheet with 20 columns and 30 rows is displayed. The default column names are Field1, Field2, and so on.

3	Rename each column you will use: double-click the column name, type a name for the column following Microsoft Access object-naming rules, and then press ENTER.

4	If you need more than 20 columns, you can insert additional columns at any time: click in the column to the right of where you want to insert a new column, and then on the Insert menu, click Column. Rename the column as described in step 3.

5	Enter your data in the datasheet.

Enter each kind of data in its own column (each column is called a field in Microsoft Access). For example, if you are entering names, enter the first name in its own column and the last name in a separate column. If you are entering dates, times, or numbers, enter them in a consistent format so that Microsoft Access can create an appropriate data type and display format for the column. Any columns you leave empty will be deleted when you save the datasheet.

6	When you've added data to all the columns you want to use, click  [image]  on the toolbar to save your datasheet.

7	Microsoft Access asks you if you want to create a primary key. If you have entered data that can be used to uniquely identify each row in your table, such as part numbers or ID numbers, click No. Otherwise, it is recommended that you click Yes. For information on how to set such a field as the primary key, click  [image].

Microsoft Access will assign data types to each field (column) based on the kind of data you entered. If you want to customize a field's definition further — for example, to change its data type, or define a validation rule, use Design view.

Note   In addition to renaming and inserting columns, you can delete or reorder columns at any time, before or after saving your new datasheet. For information on deleting a column, click  [image]. For information on reordering columns, click  [image].


Add a field to a table in Design view

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image].

To add the field to the end of the table, click in the first blank row.

2	Click in the Field Name column and type the name for the field, following Microsoft Access object-naming rules.

Or click in the Field Name column, click the Build button on the toolbar, and then select a field from the Field Builder. The Field Builder sets the field name, data type, and other properties automatically, but you can change them if you want.

3	In the Data Type column, keep the default (Text); or click in the Data Type column, click the arrow, and select the data type you want.

For information on selecting an appropriate data type, click  [image].

4	In the Description column, type a description of the information this field will contain. This description is displayed on the status bar when adding data to the field and is included in the Object Definition of the table. The description is optional.

5	If you want, set field properties for the field in the bottom part of the window.

How?

Note   If this is a linked table, you can't add a new field in the current database. If the linked table is a Microsoft Access table, you must open its source database to add a field. If the linked table is from another application, you must open the source file with that application to add a field.


Add a field to a table in Datasheet view

1	In table Datasheet view, click in the column to the right of where you want to insert a new column, and then on the Insert menu, click Column.

2	Double-click the new column's name, and then type a name for the column following Microsoft Access object-naming rules

If you want to customize a field's definition further — for example, to change its data type, or define a validation rule, use table Design view.

Note   If this is a linked table, the Column command will be unavailable. If the linked table is a Microsoft Access table, you must open its source database to add a field. If the linked table is from another application, you must open the source file with that application to add a field.


What data type should I use for a field in my table?

Decide what kind of data type to use for a field based on these considerations:

•	What kind of values do you want to allow in the field? For example, you can't store text in a field with a Number data type.

•	How much storage space do you want to use for values in the field?

•	What types of operations do you want to perform on the values in the field? For example, Microsoft Access can sum values in Number or Currency fields, but not values in Text or OLE Object fields.

•	Do you want to sort or index a field? Memo or OLE Object fields can't be sorted or indexed.

•	Do you want to use a field to group records in queries or reports? Memo or OLE Object fields can’t be used to group records.

•	How do you want to sort values in a field? In a Text field, numbers sort as strings of characters (1, 10, 100, 2, 20, 200, and so on), not as numeric values. Use a Number or Currency field to sort numbers as numeric values. Also, many date formats will not sort properly if entered in a Text field. Use a Date/Time field to ensure proper sorting.

The following table summarizes all the field data types available in Microsoft Access, their uses, and their storage sizes.

Data type	Use for	Size
Text	Text or combinations of text and numbers, such as addresses. Also numbers that do not require calculations, such as phone numbers, part numbers, or postal codes. For more information on defining a Text field, click  [image].	Up to 255 characters. Microsoft Access only stores the characters entered in a field; it does not store space characters for unused positions in a Text field. To control the maximum number of characters that can be entered, set the FieldSize property.
Memo	Lengthy text and numbers, such as notes or descriptions. For more information on defining a Memo field, click  [image].	Up to 64,000 characters.
Number	Numeric data to be used for mathematical calculations, except calculations involving money (use Currency type). Set the FieldSize property to define the specific Number type. For more information on defining a Number field, click  [image].	1, 2, 4, or 8 bytes (16 bytes for Replication ID only). For more information on number field sizes, click  [image].
Date/Time	Dates and times. For more information on defining a Date/Time field, click  [image].	8 bytes.
Currency	Currency values. Use the Currency data type to prevent rounding off during calculations. Accurate to 15 digits to the left of the decimal point and 4 digits to the right. For more information on defining a Currency field, click  [image].	8 bytes.
AutoNumber	Unique sequential (incrementing by 1) or random numbers automatically inserted when a record is added. For more information on defining an AutoNumber field, click  [image].	4 bytes (16 bytes for Replication ID only).
Yes/No	Fields that will contain only one of two values, such as Yes/No, True/False, On/Off. For more information on defining a Yes/No field, click  [image].	1 bit.
OLE Object	Objects (such as Microsoft Word documents, Microsoft Excel spreadsheets, pictures, sounds, or other binary data), created in other programs using the OLE protocol, that can be linked to or embedded in a Microsoft Access table. You must use a bound object frame in a form or report to display the OLE object. For more information on defining an OLE Object field, click  [image].	Up to 1 gigabyte (limited by disk space).
Lookup Wizard	Creates a field that allows you to choose a value from another table or from a list of values using a combo box. Choosing this option in the data type list starts a wizard to define this for you. For more information on defining a Lookup field, click  [image].	The same size as the primary key field used to perform the lookup, typically 4 bytes.
Note   Number, Date/Time, Currency, and Yes/No data types provide predefined display formats. Set the Format property to choose from the formats available for each data type. You can also create a custom display format for all data types except the OLE Object data type. For information on how to define a custom display format, click  [image].


Change a field's data type

Tip   If your table contains data, you should make a backup copy of your table before you change data types or field sizes.

1	In table Design view, click the Data Type column of the field you want to change, click the arrow, and select the new data type.

2	Click  [image]  on the toolbar.

Caution   If the data type conversion would result in lost values, Microsoft Access displays a message telling you that errors occurred during conversion before it actually saves the changes. Click Cancel to cancel the changes. Click OK to continue and save the changes anyway.

For more information on the consequences of changing a field's data type, click  [image].

Note   In large tables, changing a data type might take a long time. If you want to cancel the conversion process at any point while it is running, press CTRL+BREAK, and then click OK.


Consequences of changing a field's data type

At some point, you may need to change data types for fields that already contain data. Perhaps you imported data and Microsoft Access didn't set the data types as you intended. Or maybe the data type you set for a field is no longer appropriate.

Before converting from one data type to another, consider how the change will affect your entire database. Which queries, forms, and reports use the field that is being converted? You may need to change expressions that depend on the changed field.

The most common data type changes fall into the following four categories: converting to Text from other data types; converting from Text to Number, Currency, Date/Time, or Yes/No; converting between Currency and Number or between Text and Memo; and changing the FieldSize property setting for Number fields.

Converting to Text from other data types

While you should store numbers that will used in calculations in a Number or Currency field, you may find that a field that was originally just numbers now requires the use of letters and other non-numeric characters. For example, suppose you have a Number field that stores code numbers. If you later find you need to include letters, hyphens, parentheses, or other non-numeric characters as part of the code, you'll need to change the field's data type to Text.

Microsoft Access converts number values to text using a General Number format, and date values to text using a General Date format. The converted values will not include any currency symbols or other special formatting characters you set for the field.

Converting from Text to Number, Currency, Date/Time, or Yes/No

If you have data stored in a Text field and want to change the field to another data type, Microsoft Access can convert values that are appropriate for the new data type. For example, if you have numbers stored in a Text field and you want to do mathematical calculations on your data, you must convert the field to the Number or Currency data type. As long as all the data stored in the field consists of only numbers, you can change the data type without losing data.

For Text to Number data type conversions, decimal points and thousands separators are interpreted appropriately. Currency symbols are interpreted according to the Regional Settings in the Windows Control Panel.

For Text to Date/Time conversions, most date and time formats are converted correctly. Date and time formats are interpreted according to the Regional Settings in the Windows Control Panel.

For Text to Yes/No conversions, the words Yes, True, or On are converted to a Yes value, and No, False, or Off to a No value. (You can also convert from Number to Yes/No data type: zero or null values convert to No and nonzero values to Yes.)

Converting between Currency and Number or between Text and Memo

You can always convert between the Currency and Number data types. You should always store monetary values using the Currency data type to ensure that calculations are correct. You should also use a Currency data type if you plan to perform many calculations on a field that contains numbers with one to four decimal places. Currency fields use a fixed-point calculation method that avoids rounding errors. You can always convert between the Text and Memo data types. For example, if you want to store longer text values than you originally intended, you can change a field to the Memo data type. However, if a field doesn't have to store more than 255 characters, you should use the Text data type, keeping in mind that you can't index or sort on Memo fields.

Changing the FieldSize property setting for Number fields

For fields with the Number data type, the FieldSize property setting determines the specific number type: Byte, Integer, Long Integer, Single, Double, or Replication ID. If you convert a field to the Number type, consider whether you need to change the FieldSize setting for the values you store in the field. If you change the FieldSize setting from a larger size, such as Double, to a smaller value, such as Integer, you must make sure that the values stored in the field fit in the new field size. If you change to a FieldSize setting that doesn't allow the number of decimal places included in your current values, the numbers are rounded. For example, if you change a field from Double to Long Integer, decimal numbers are rounded to the nearest whole number. Additionally, if the values are too large to be stored in the new size, they will be deleted and replaced with null values.

To view a summary of data type conversion results, click  [image].

For information on the range of values each field size can store, click  [image].


Field data type conversion results

The following is a list of the results and considerations of common data type conversions when the table contains data.

From	To	Results	Considerations
All data types	AutoNumber	Prohibited by Microsoft Access	None.
Text	Number, Currency, Date/Time, Yes/No	Converts text to appropriate values	Make sure values fit in the new data type; inappropriate values are deleted.
Memo	Text	Simple conversion	Data longer than the FieldSize setting is truncated.
Number	Text	Converts values to text	Numbers adopt General Number format.
Number	Currency	Converts numbers to currency	Values may be truncated.
Date/Time	Text	Converts values to text	Dates or times adopt General Date format.
Currency	Text	Converts values to text	Text doesn't include currency symbols, such as $.
Currency	Number	Simple conversion	Values may be truncated.
AutoNumber	Text	Converts values to text	Values may be truncated depending on FieldSize setting.
AutoNumber	Number	Simple conversion	Values may be truncated depending on FieldSize setting.
Yes/No	Text	Converts values to text	None.


What kind of primary key should I use?

The power of a relational database system such as Microsoft Access comes from its ability to quickly find and bring together information stored in separate tables using queries, forms, and reports. In order to do this, each table should include a field or set of fields that uniquely identify each record stored in the table. This information is called the primary key of the table. Once you designate a primary key for a table, to ensure uniqueness Microsoft Access will prevent any duplicate or null values from being entered in the primary key fields.

There are three kinds of primary keys that can be defined in Microsoft Access: AutoNumber, single-field, and multiple-field.

AutoNumber primary keys

An AutoNumber field can be set to automatically enter a sequential number as each record is added to the table. Designating such a field as the primary key for a table is the simplest way to create a primary key. If you don't set a primary key before saving a newly created table, Microsoft Access will ask if you want it to create a primary key for you. If you answer Yes, Microsoft Access will create an AutoNumber primary key. There are additional considerations if your table will be used with database replication. For more information, click  [image].

Single-field primary keys

If you have a field that contains unique values such as ID numbers or part numbers, you can designate that field as the primary key. If the field you select as primary key does have duplicate or null values, Microsoft Access won't set the primary key. You can run a Find Duplicates query to determine which records contain duplicate data. If you can't readily eliminate duplicate entries by editing your data, you can either add an AutoNumber field and set it as the primary key or define a multiple-field primary key.

Multiple-field primary keys

In situations where you can't guarantee the uniqueness of any single field, you may be able to designate two or more fields as the primary key. The most common situation where this arises is in the table used to relate two other tables in a many-to-many relationship. The Order Details table in the Northwind sample database is such a table, relating the Orders and Products tables. Its primary key consists of two fields: OrderID and ProductID. The Order Details table can list many products and many orders, but each product can only be listed once per order, so combining the OrderID and ProductID fields produces an appropriate primary key. Another example would be an inventory database that uses a field part number of two or more fields (part and subpart).

Note   If you are in doubt about whether you can select an appropriate combination of fields for a multiple-field primary key, you should probably add an AutoNumber field and designate it as the primary key instead. For example, combining FirstName and LastName fields to produce a primary key is not a good choice, since you may eventually encounter duplication in the combination of these two fields.

For information on setting a primary key, click  [image].

For an example of different types of primary keys, click  [image].


Set or change the primary key

1	In table Design view, select the field or fields you want to define as the primary key.

To select one field, click the row selector for the desired field.

To select multiple fields, hold down the CTRL key and then click the row selector for each field.

2	Click  [image]  on the toolbar.

For more information on how to choose a primary key, click  [image].

Notes

•	You can specify a primary key for a field that already contains data, but Microsoft Access generates an error message when you save the table if it finds duplicate values or nulls in the field. If you encounter this error message, you have three choices: use a Find Duplicates query to locate records with duplicate values or nulls and then edit the field to remove them; choose a different field; or add an AutoNumber field and set it as the primary key. For more information on finding duplicate records, click  [image].

•	In a multiple-field primary key, field order may be important to you. The fields in a multiple-field primary key are sorted according to their order in table Design view. If you want a different order, first specify the fields for the primary key as described in the preceding procedure, and then click  [image]  to display the Indexes window and reorder the field names for the index named PrimaryKey.


Remove the primary key

In some situations, you may need to temporarily remove the primary key for a table. For example, importing records into a table may result in some duplicate records. Until you eliminate the duplicates, you should remove the primary key (use a Find Duplicates query to list duplicate records). This procedure doesn't delete the field or fields that are designated as the primary key, it simply removes the primary key features from the table. For more information on finding duplicate records, click  [image].

•	In table Design view, click the row selector for the current primary key and then click [image] on the tool bar.

Note   If the primary key is used in a relationship, you must delete the relationship before you can remove the primary key. For information on how to delete a relationship, click  [image].


Change a field name

You can change a field name at any time without affecting the data in the field. However, changing a field name can have consequences for other parts of your database. If other database objects contain references to the field name you changed, you need to update those references to reflect the new name. For example, if you have created a text box in a form that is bound to the changed field, the text box won't display the field until you update the ControlSource property for the text box to reflect the new name.

You can change a field name in either Design view or Datasheet view.

What do you want to do?

Change a field name in Design view

Change a field name in Datasheet view


Change a field name in Design view

1	In table Design view, double-click the field name you want to change.

2	Type the new field name, following Microsoft Access object-naming rules.

3	Click  [image]  to save your changes.

Caution   If you have queries, forms, reports, expressions, or Visual Basic for applications code that contain references to a field whose name you are changing, you must update all of those references to the new name.


Change a field name in Datasheet view

1	In table Datasheet view, double-click the column selector of the field that you want to change.

Note   If the Caption property has been set for this field, the text displayed in the column selector will be different from the actual field name. In this case, when you double-click the column selector, the caption text will be cleared and replaced with the field name. If you continue, you'll be editing the field name, and when you press ENTER to save this change, the caption text will be deleted. If you don't want to delete the caption text, press ESC immediately after double-clicking the column selector to cancel editing. For more information on using the Caption property, click  [image].

2	Type the new field name, following Microsoft Access object-naming rules.

3	Press ENTER to save the new name.

Caution   If you have queries, forms, reports, expressions, or Visual Basic for applications code that contain references to a field whose name you are changing, you must update all of those references to the new name.


Copy a field in table Design view

1	In table Design view, select the fields you want to copy.

To select one field, click that field's row selector.

To select a group of fields, drag through the row selectors of those fields.

2	Click  [image]  and then click in the first blank row.

3	Click  [image].

4	Type a new name for the copied field.

Note   This procedure only copies a field's definition; it doesn't copy any values in the field.


Move a field in table Design view

1	In table Design view, select the fields you want to move.

To select one field, click that field's row selector.

To select a group of fields, drag through the row selectors of those fields.

2	Click and hold down the mouse button in the row selector again. Microsoft Access displays a thin horizontal bar just above the last selected row.

3	Drag the horizontal bar to the row just below where you want to move the fields.

Note   Changing field order in table Design view changes the order fields are stored in the table and also changes the column order in the table's datasheet.

For information on how to change only the datasheet's column order, click  [image].

To undo the move

•	Click  [image] on the toolbar.


Delete a field

You can delete a field at any time in either table Design view or Datasheet view.

What do you want to do?

Delete a field from a table in Design view

Delete a field from a table in Datasheet view


Delete a field from a table in Design view

1	In table Design view, select the fields you want to delete.

To select one field, click that field's row selector.

To select a group of fields, drag through the row selectors of those fields.

2	Click  [image]  on the toolbar.

3	Microsoft Access asks if you want to continue.

To delete the fields and any data they contain, click Yes.

To cancel the deletion, click No.

Caution   You cannot undo the deletion of fields after clicking Yes. If you do click Yes, Microsoft Access permanently deletes both the field definitions and any data they contain. To cancel the deletion, click No when Microsoft Access asks if you want to continue.

Notes

•	If other database objects contain references to a deleted field, you need to delete those references as well. For example, if a report includes a control to print a field that has been deleted, Microsoft Access won't be able to find the data from the field and will generate an error message.

•	You can't delete a field that's part of a relationship. You must delete the relationship first.


Delete a field from a table in Datasheet view

1	In table Datasheet view, click the field selector of the column you want to delete.

2	On the Edit menu, click Delete Column.

3	Microsoft Access asks if you want to continue.

To delete the field and any data it contains, click Yes.

To cancel the deletion, click No.

Caution   You cannot undo the deletion of a field after clicking Yes. If you do click Yes, Microsoft Access permanently deletes both the field definition and the data it contains. To cancel the deletion, click No when Microsoft Access asks if you want to continue.

Notes

•	If other database objects contain references to a deleted field, you need to delete those references as well. For example, if a report includes a control to print a field that has been deleted, Microsoft Access won't be able to find the data from the field and will generate an error message.

•	You can't delete a field that's part of a relationship. You must delete the relationship first.


Create a field for text or memos

Microsoft Access provides two field data types to store data with text or combinations of text and numbers: Text or Memo.

Use a Text data type to store data such as names, addresses, and any numbers that do not require calculations, such as phone numbers, part numbers, or postal codes. A Text field can store up to 255 characters, but the default field size is 50 characters. To control the maximum number of characters that can be entered in a Text field, set the FieldSize property.

Use the Memo data type if you need to store more than 255 characters. A Memo field can store up to 64,000 characters. Memo fields can't be indexed or sorted.

Both Text and Memo data types store only the characters entered in a field; space characters for unused positions in the field aren't stored.

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select either Text or Memo.

4	Set the other field properties, if desired.

How?

Notes

•	The default field size for Text fields is 50 characters. You can change this for a particular field by setting the FieldSize property. You can change the default field size itself by choosing the Options command on the Tools menu, and then clicking the Tables/Queries tab.

•	If you want to store formatted text or long documents, you should create an OLE field instead. To find out more about OLE fields, click  [image].

•	You can create a custom display format for Text or Memo fields. For information on how to define a custom display format, click  [image].


Create a field for numbers or currency

Microsoft Access provides two field data types to store data containing numeric values: Number or Currency.

Use a Number field to store numeric data to be used for mathematical calculations, except calculations that involve money or that require a high degree of accuracy. The kind and size of numeric values that can be stored in a Number field is controlled by setting the FieldSize property. For example, the Byte field size will only store whole numbers (no decimal values) from 0 to 255 and occupies 1 byte of disk space.

Use a Currency field to prevent rounding off during calculations. A Currency field is accurate to 15 digits to the left of the decimal point and 4 digits to the right. A Currency field occupies 8 bytes of disk space.

Number and Currency fields also provide predefined display formats. Set the Format property to choose a display format.

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select either Number or Currency.

4	If you are creating a Number field, in the bottom part of the window set the FieldSize property to the size you want. For more information on number field sizes, click  [image].

5	To set a display format for your field, in the bottom part of the window click in the Format box, click the arrow, and select the format you want.

6	Set the other field properties, if desired.

 	How?

Notes

•	You can also create a custom display format, if the predefined formats don't meet your needs. For information on how to define a custom display format, click  [image].

•	Changes made to the currency formats in the Regional Settings of the Windows Control Panel will be automatically reflected in your database for Currency fields. However, this only affects the format; no conversion of currency values will be made.


Create a field that automatically generates numbers

Microsoft Access provides the AutoNumber data type to create fields that automatically enter a number when a record is added. Once a number is generated for a record, it can't be deleted or changed. An AutoNumber field can generate three kinds of numbers: sequential numbers that increment by one, random numbers, and Replication ID numbers. AutoNumbers that increment by one are the most common kind of AutoNumber and are a good choice for use as a table's primary key. Random AutoNumbers will generate a random number that is unique to each record within the table.

Replication ID AutoNumbers are used in database replication to generate unique identifiers for synchronizing replicas. For more information on Replication ID AutoNumbers and when to use them, click  [image].

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image] on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select AutoNumber.

4	To create an incrementing AutoNumber, leave the property settings in the bottom part of the window as they are (the FieldSize property is set to Long Integer and the NewValues property is set to Increment by default).

To create a random AutoNumber, in the bottom part of the window set the NewValues property to Random.

5	Set the other field properties, if desired.

How?


Create a field for dates or times

Storing dates and times in a Date/Time field ensures that dates and times will be sorted properly. Also, changes made to the date or time formats in the Regional Settings of the Windows Control Panel will be automatically reflected in your database for Date/Time fields.

Date/Time fields also provide predefined display formats. Set the Format property to choose a display format.

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	Click in the Field Name column and type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select Date/Time.

4	To set a display format for your field, in the bottom part of the window click in the Format box and select the format you want.

5	Set the other field properties, if desired.

How?

Note   You can also create a custom display format, if the predefined formats don't meet your needs. For information on how to define a custom display format, click  [image].


Create a field to store OLE objects, documents, pictures, and other binary files

OLE Object fields are used to store data such as documents, pictures, sound, and binary data created in other programs. OLE objects can be linked to or embedded in a field in a Microsoft Access table. You must use a control in a form or report to display the OLE object.

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select OLE Object.

To find out more about editing and displaying objects stored in OLE Object fields, click  [image].


Create a field for Yes/No, True/False, and On/Off data

Yes/No fields store data for Yes or No, True or False, and On or Off answers. A Yes/No field stores -1 for a Yes entry, and 0 for a No entry, but uses a display format to display the text "Yes" or "No" in the field. You can select to display Yes/No, True/False, or On/Off by setting the Format property.

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select Yes/No.

4	To set a display format for your field, in the bottom part of the window click in the Format box and select the format you want.

5	Set the other field properties, if desired.

How?

Note   You can also create a custom display format, if the predefined formats don't meet your needs. For information on how to define a custom display format, click  [image].


Create a field that looks up or lists values in tables

Using the Lookup Wizard, you can create a field that displays either of two kinds of lists to make data entry simpler:

•	A lookup list that displays values looked up from an existing table or query

•	A value list that displays a fixed set of values that you enter when you create the field

The Lookup Wizard gives you the option to display the list as a combo box or a list box. If you use the list from a table's or query's datasheet, the list can be displayed only as combo box, regardless of the choice you make. However, if you add the field to a form later, the list will be displayed in the format you select from the wizard.

Note   Once you've created a lookup or value list field, if you add the field to a form, Microsoft Access copies its definition into the form. You won't have to create the combo or list box and its lookup or value list definition for the form. However, if you change the definition of a lookup or value list field in the table after adding it to a form, those changes will not be reflected in that form. To correct this, delete the field from the form and then add it again.

The most common lookup list displays values looked up from a related table. For example, the SupplierID field in the Products table of the Northwind sample database displays this lookup list:

This list is created by looking up the SupplierID values in the Suppliers table and displaying the corresponding Supplier names. Picking a value from a lookup list sets the foreign key value in the current record (SupplierID in the Products table) to the primary key value of the corresponding record in the related table (SupplierID in the Suppliers table). This creates an association to the related table to display (but not store) the Supplier names in the record. (The foreign key (SupplierID) is stored but doesn't display.) For this reason, any updates made to the data in the Suppliers table will be reflected in both the list and records in the Products table. You must define a lookup list field from the table that will contain the foreign key and display the lookup list. In this example, the lookup list field would be defined from the Products table.

A value list looks the same as a lookup list, but consists of a fixed set of values you type in when you create it. A value list should only be used for values that will not change very often and don't need to be stored in a table. For example, a list for a Salutation field containing Mr., Mrs., or Ms. would be a good candidate for a value list. Choosing a value from a value list will store that value in the record — it doesn't create an association to a related table. For this reason, if you change any of the original values in the value list later, they will not be reflected in records added before this change was made.

You can add a new lookup or value list field in either table Design view or table Datasheet view. However, if the field you want to use as the foreign key for a Lookup field already exists, you must open that field's table in Design view to define the Lookup field. For example, if you have a Products table that has a SupplierID field already defined, and you want to change it to a Lookup field to display supplier names from your Suppliers table, you must open the Products table in Design view to change SupplierID to a Lookup field.

The Lookup Wizard sets certain field properties based on the choices you make in the wizard. For information on the properties that the Lookup Wizard sets, click  [image].

What do you want to do?

Create a lookup list field in Design view

Create a lookup list field in Datasheet view

Create a value list field in Design view

Create a value list field in Datasheet view


Create a field that looks up and displays data from another table in Design view

1	Open the table in table Design view.

2	Do one of the following:

•	To insert a new field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar, or to add a new field at the end of the table, click in the first blank row. Type the name for the field in the Field Name column, following Microsoft Access object-naming rules.

•	If the field you want to use as the foreign key for the lookup already exists, click in that field's row. For example, if you have a Products table that has a SupplierID field already defined, and you want to change it to a Lookup field to display supplier names from your Suppliers table, you would click in the SupplierID field's row.

1	In the Data Type column, click the arrow and select Lookup Wizard.

2	Click the option that indicates you want the lookup to look up the values in a table or query.

3	Click Next and follow the directions in the remaining Lookup Wizard dialog boxes.

When you click the Finish button, Microsoft Access creates the Lookup field and sets certain field properties based on the choices you made in the wizard. For information on the properties that the Lookup Wizard sets, click  [image].

Note   It is also possible to add a Lookup field to a table that displays values from the same table that contains the Lookup field. For example, in the Employees table of the Northwind sample database the ReportsTo field is a Lookup field that displays data from the FirstName and LastName fields by looking up the corresponding EmployeeID in the same table.


Create a field that looks up and displays data from another table in Datasheet view

1	In table Datasheet view, to insert the Lookup field within the table, click in the column to the right of where you want to insert the field, and then on the Insert menu, click Lookup Column. This will start the Lookup Wizard.

2	In the first dialog box of the Lookup Wizard, select the option that indicates you want the lookup to look up the values in a table or query.

3	Click Next and follow the directions in the remaining Lookup Wizard dialog boxes.

When the Lookup Wizard is finished, the Lookup field is added to your datasheet. By default, the Lookup field will be given the same name as the primary key field of the table whose data is being displayed by the Lookup field. You can change this name if you want. To find out how to change a field name in Datasheet view, click  [image].

Note   It is also possible to add a Lookup field to a table that displays values from the same table that contains the Lookup field. For example, in the Employees table of the Northwind sample database, the ReportsTo field is a Lookup field that displays data from the FirstName and LastName fields by looking up the corresponding EmployeeID.


Create a value list field in Design view

1	In table Design view, to insert the field within the table, click in the row below where you want to add the field, and then click  [image]  on the toolbar.

To add the field to the end of the table, click in the first blank row.

2	In the Field Name column, type the name for the field, following Microsoft Access object-naming rules.

3	In the Data Type column, click the arrow and select Lookup Wizard.

4	Click the option that indicates you will type in the values that you want.

5	Click Next and follow the directions in the remaining Lookup Wizard dialog boxes.


Create a value list field in Datasheet view

1	In table Datasheet view, to insert a value list field within the table, click in the column to the right of where you want to insert the field, and then on the Insert menu, click Lookup Column. This will start the Lookup Wizard.

2	In the first dialog box of the Lookup Wizard, select the option that indicates you will type in the values that you want.

3	Click Next and follow the directions in the remaining Lookup Wizard dialog boxes.

When the Lookup Wizard is finished, the value list field is added to your datasheet. By default, the new value list field will be given a name in the form, "Field#," where # is some number. You can change this name if you want. To find out how to change a field name in Datasheet view, click  [image].


Define relationships between tables

1	Close any tables you have open. You can't create or modify relationships between open tables.

2	In the Database window, click  [image]  on the toolbar.

3	If your database doesn't have any relationships defined, the Add Tables/Queries box will automatically display. If you need to add the tables you want to relate and the Add Table dialog box isn't displayed, click  [image]  on the toolbar. If the tables you want to relate are already displayed, skip to step 6.

4	Double-click the names of the tables you want to relate, and then close the Add Tables/Queries dialog box.

5	Drag the field that you want to relate from one table to the related field in the other table.

To drag multiple fields, press the CTRL key and click each field before dragging them.

In most cases, you drag the primary key field (which is displayed in bold text) from one table to a similar field (often with the same name) called the foreign key in the other table. The related fields don't have to have the same names, but they must have the same data type (with two exceptions) and contain the same kind of information. In addition, when the matching fields are Number fields, they must have the same FieldSize property setting. The two exceptions to matching data types are that you can match an Increment AutoNumber field with a Long Integer Number field; and you can match a Replication ID AutoNumber field with a Replication ID Number field.

6	The Relationships dialog box is displayed. Check the field names displayed in the two columns to ensure they are correct. You can change them if necessary.

Set the relationship options if necessary. For information about a specific item in the Relationships dialog box, click  [image], and then click the item.

7	Choose the Create button to create the relationship.

8	Repeat steps 5 through 8 for each pair of tables you want to relate.

You can also perform any of the following operations while you are using the Relationships window:

•	Change a table's design.

How?

•	Edit an existing relationship.

How?

•	Delete a relationship.

How?

•	Remove a table from the Relationships window.

How?

•	View all existing relationships or only those for a particular table.

How?

Notes

•	You can create relationships using queries as well as tables. However, referential integrity isn't enforced with queries.

•	When you close the Relationships window, Microsoft Access asks if you want to save the layout. Whether you save the layout or not, the relationships you create are saved in the database.

•	To create a relationship between a table and itself, add that table twice. This is useful in situations where you need to perform a lookup within the same table. For example, in the Employees table in the Northwind sample database, a relationship has been defined between the EmployeeID and ReportsTo fields so that the ReportsTo field can display employee data from a matching EmployeeID.


Change a table's design from the Relationships window

1	In the Relationships window, use the right mouse button to click the table you want to change, and then click Design Table.

2	Make the desired changes to the table's definition.

3	When you have finished making changes, click  [image]  and then click Yes to save your changes and return to the Relationships window.


Display the Relationships window

•	In the Database window, click  [image]  on the toolbar.

The Relationships window is displayed. If the relationship layout was saved previously, the saved layout is displayed. If not, the Add Tables/Queries dialog box is displayed to select tables or queries to add to the Relationships window.


Edit an existing relationship

1	Close any tables you have open. You can't modify relationships between open tables.

2	In the Database window, click  [image]  on the toolbar.

3	If the tables whose relationship you want to edit aren't displayed, click  [image]  on the toolbar and double-click each table you want to add.

4	Double-click the relationship line for the relationship you want to edit.

5	Set the relationship options. For information about a specific item in the Relationships dialog box, click  [image], and then click the item.


Delete a relationship

1	Close any tables you have open. You can't delete relationships between open tables.

2	In the Database window, click  [image]  on the toolbar.

3	If the tables whose relationship you want to delete aren't displayed, click  [image]  on the toolbar and double-click each table you want to add. Then click Close.

4	Click the relationship line for the relationship you want to delete (the line will turn bold when it's selected), and then press the DEL key.

5	Microsoft Access asks you to confirm that you want to delete the relationship.

To delete the relationship, click Yes.

To cancel the deletion, click No.


Remove a table from the Relationships window

1	If the Relationships window isn't currently displayed, click  [image]  on the toolbar.

2	Click the table you want to remove, and then press the DEL key.

Microsoft Access removes the table and its relationship lines from the Relationships window. This action affects only the display of the Relationships window. The table and relationships remain in the database.


View existing relationships

1	If the Relationships window isn't currently displayed, click  [image]  on the toolbar.

2	To view all the relationships defined in the database, click  [image]  on the toolbar.

To view only the relationships defined for a particular table, click the table, and then click  [image]  on the toolbar.

Note   If all of the tables related to the selected table are already displayed in the Relationships window, clicking the Show Direct Relationships button will have no effect because it only adds tables related to the current table. If you want to view only the direct relationships for one table, click  [image]  on the toolbar to remove all tables from the Relationships window (this won't delete the tables or relationships, it just removes them from the Relationships window), add the table back, and then click the Show Direct Relationships button. To add a table, click  [image]  on the toolbar, double-click the table, and then click Close.


Define join types

Defining the join type for a relationship in the Relationships window doesn't affect the relationship itself; it sets the kind of join that will be used by default when creating queries based on the related tables. You can always override the default join type later when defining a query. By default, Microsoft Access creates an inner join between related tables.

1	Display the Relationships window and Relationships dialog box, if they aren't already displayed.

How?

2	Click Join Type, and then click the desired join type.

Option 1 defines an inner join. This is the default.

Option 2 defines a left outer join.

Option 3 defines a right outer join.

For more information on join types, click  [image].


What is referential integrity?

Referential integrity is a system of rules that Microsoft Access will use to ensure that relationships between records in related tables are valid, and that you don't accidentally delete or change related data. You can set referential integrity when all of the following conditions are met:

•	The matching field from the primary table is a primary key or has a unique index.

•	The related fields have the same data type.

•	Both tables belong to the same Microsoft Access database. If the tables are linked tables, they must be tables Microsoft Access format, and you must open the database in which they are stored to set referential integrity. Referential integrity can't be enforced for linked tables from databases in other formats.

When referential integrity is enforced, you must observe the following rules:

•	You can't enter a value in the foreign key field of the related table that doesn't exist in the primary key of the primary table. However, you can enter a null in the foreign key, specifying that the records are unrelated. For example, you can't have an order that is assigned to a customer that doesn't exist, but you can have an order that is assigned to no one by entering a null in the CustomerID field.

•	You can't delete a record from a primary table, if matching records exist in a related table. For example, you can't delete an employee record from the Employees table if there are orders assigned to the employee in the Orders table.

•	You can't change a primary key value in the primary table, if that record has related records. For example, you can't change an employee's ID in the Employees table if there are orders assigned to that employee in the Orders table.

If you want Microsoft Access to enforce these rules for a relationship, select the Enforce Referential Integrity check box when you create the relationship. If referential integrity is enforced and you break one of the rules with related tables, Microsoft Access displays a message and doesn't allow the change.

You can override the restrictions against deleting or changing related records and still preserve referential integrity by setting the Cascade Update Related Fields and Cascade Delete Related Records check boxes. When the Cascade Update Related Fields check box is set, changing a primary key value in the primary table automatically updates the matching value in all related records. When the Cascade Delete Related Records check box is set, deleting a record in the primary table deletes any related records in the related table. For more information on Cascade Delete Related Records and Cascade Update Related Fields check boxes, click  [image].

For information on how to edit an existing relationship and set referential integrity, click  [image].

For information on how to define a new relationship, click  [image].


Why should I use the Cascade Update and Cascade Delete options?
Why should I use the Cascade Update or Cascade Delete options?

For relationships in which referential integrity is enforced, you can specify whether you want Microsoft Access to automatically "cascade" delete and update operations for related records. If you set these options, delete and update operations that would normally be prevented by referential integrity rules are allowed. When you delete records or change primary key values in a primary table, Microsoft Access makes necessary changes to related tables to preserve referential integrity.

If you select the Cascade Update Related Fields check box when defining a relationship, any time you change the primary key of a record in the primary table, Microsoft Access automatically updates the primary key to the new value in all related records. For example, if you change a customer's ID in the Customers table, the CustomerID field in the Orders table is automatically updated for every one of that customer's orders so that the relationship isn't broken. Microsoft Access cascades updates without displaying any message.

Note   If the primary key in the primary table is an AutoNumber field, setting the Cascade Update Related Fields check box will have no effect, because you can’t change the value in an AutoNumber field.

If you select the Cascade Delete Related Records check box when defining a relationship, any time you delete records in the primary table, Microsoft Access automatically deletes related records in the related table. For example, If you delete a customer record from the Customers table, all the customer's orders are automatically deleted from the Orders Table (this includes records in the Order Details table related to the Orders records). When you delete records from a form or datasheet with the Cascade Delete Related Records option set, Microsoft Access warns you that related records may also be deleted. However, when you delete records using a delete query, Microsoft Access automatically deletes the records in related tables without displaying a warning.

For information on how to edit an existing relationship and set referential integrity, click  [image].

For information on how to define a new relationship, click  [image].


Define a many-to-many relationship between tables

1	Create the tables between which you want to define a many-to-many relationship.

How?

2	Create a third table, called a junction table, and add fields with the same definitions as the primary key fields from each of the other two tables to this table. In the junction table, the primary key fields function as foreign keys. You can add other fields to the junction table, just as you can to any other table.

3	In the junction table, set the primary key to include all the primary key fields from the other two tables.

How?

4	Define a one-to-many relationship between each of the two primary tables and the junction table.

How?

Note   In the Northwind sample database, a many-to-many relationship exists between the Orders and Products tables. One order in the Orders table can include multiple products from the Products table. In addition, a single product can appear in many orders.  In the sample database, the Order Details table is a junction table between the Orders table and the Products table.


Set field properties to customize how data is stored, handled, or displayed

Each field has a set of properties that you use to customize how a field's data is stored, handled, or displayed. For example, you can control the maximum number of characters that can be entered into a Text field by setting its FieldSize property. You set a field's properties by displaying a table in Design View, selecting the field in the upper portion of the window, and then selecting the desired property in the lower portion of the window.

The properties that are available for each field are determined by the data type you select for the field.

For examples of using field properties to customize fields, click  [image].

Tip   When you create a bound control on a form or report by dragging a field from the field list, Microsoft Access copies certain properties from that field to the control. This way you can be sure that you have consistent settings whenever you add fields to a form or report. For more information on this, click  [image].

What do you want to do?

Speed up searches on fields that are searched frequently, joined in queries, or sorted

Set the maximum size for a Text field, or the number size for a Number field

Set how many decimal places to display for a Number or Currency field

Define the display format for a field, such as a date's format

Define an input mask with literal characters and blanks to fill in for data such as phone numbers, postal codes, and dates

Define a label that is different from the field name for the field's column heading in Datasheet view, and for controls in forms and reports created by dragging the field from the field list

Define a value that is automatically entered when you add a new record

Limit data entered in a field to values that meet a certain requirement

Require that data be entered in a field

Allow zero-length strings to be stored in a Text or Memo field


Change the field size for text and number fields

You can control the maximum number of characters that can be entered into a Text field, or the range and kind of numeric values that can be entered into a Number field by setting the FieldSize property.

1	In table Design view, in the upper portion of the window, click the field whose FieldSize property you want to set.

2	In the lower portion of the window, click the FieldSize property box.

3	For a Text field, type the maximum number of characters to allow in the field (up to 255).

For a Number field, click the arrow and select the desired field size.

The following table summarizes the field sizes available for Number fields.

FieldSize	Range	Decimal  precision	Storage  size
Byte	0 to 255	None	1 byte
Integer	-32,768 to 32,767	None	2 bytes
Long Integer	-2,147,483,648 to 2,147,483,647	None	4 bytes
Single	-3.402823E38 to 3.402823E38	7	4 bytes
Double	-1.79769313486232E308 to 1.79769313486232E308	15	8 bytes
Replication ID	Globally unique identifier (GUID)	N/A	16 bytes


Define the data display format for a field using a predefined format

You can select from a variety of predefined display formats for fields with AutoNumber, Number, Currency, Date/Time, and Yes/No data types.

1	In table Design view, in the upper portion of the window, click the field you want to format.

2	In the lower portion of the window, click the Format property box, and then click the arrow and select the desired format.

If the predefined formats don't suit your needs, you can create a custom format for any field data type other than OLE Object. For information on how to define a custom format, click  [image].

Notes

•	A field's display format is copied when you use that field in new forms and reports. Existing forms and reports aren't affected when you change a field's display format in table Design view. To match a change you've made to a field's format, you must also change the Format property for existing controls in forms and reports that are bound to that field.

•	To ensure consistency among applications, Microsoft Access uses the regional settings specified in the Windows Control Panel for some predefined number and date/time formats. For more information, click  [image].


Define a custom data display format for a field

You can create a custom format for any field data type other than OLE Object.

1	In table Design view, in the upper portion of the window, click the field you want to format.

2	In the lower portion of the window, click the Format property box, and then type the format's definition in the field. For information on how to create the definition for a custom display format, click  [image].

Note   A field's display format is copied when you use that field in new forms and reports. Existing forms and reports aren't affected when you change a field's display format. To match a change you've made to a field's format, you must also change the Format property for existing controls in forms and reports that are bound to that field.


Create custom data display format definitions

What kind of field do you want to create a custom format definition for?

Number and Currency display formats

Date/Time display formats

Yes/No display formats

Text and Memo display formats


Number and Currency data display formats

If you don't specify a format, or if you specify the General Number format, Microsoft Access displays numbers with no thousands separator or other formatting. If you want numbers in a field to have a thousands separator, choose Standard or Currency setting.

Predefined formats

The following table shows the predefined formats available for fields with the Number or Currency data type and the way they display data by default in a form, report, or datasheet.

With this format	This number	Is displayed this way
General Number (default)	1234.5	1234.5
Currency	1234.5	$1,234.50 (U.S.) £1,234.50 (U.K.)
Fixed	1234.5	1234
Standard	1234.5	1,234.50
Percent	0.824	82.40%
Scientific	1234.5	1.23E+03
The General Number format displays just the number of decimal places necessary for each value. If you specify a format other than General Number, such as Fixed, you can specify the number of decimal places you want to display by setting the DecimalPlaces property. When the DecimalPlaces property has been set to Auto, the default, Microsoft Access displays the default number of decimal places for the format (0 for Fixed, 2 for other formats).

Note   To ensure consistency among applications, Microsoft Access uses the regional settings specified in the Windows Control Panel for some predefined number and date/time formats. For more information, click  [image].

Custom formats

Custom formats for fields containing numbers can have one to four sections separated with semicolons. The sections for custom number formats have the following meanings.

Section	Meaning
First	Positive numbers
Second	Negative numbers
Third	Zero values
Fourth	Null or empty values
For example, the standard Currency format can be created with this custom format:

$#,##0.00;($#,##0.00)[Red]

This number format contains two sections separated by a semicolon and uses a different format for positive numbers (determined by the first section) than for negative numbers (determined by the second section). Both positive and negative numbers have the currency sign and the comma separator for thousands; in addition, negative numbers are red and enclosed in parentheses.

You can create custom formats for Number fields using the following codes.

Setting	Description
. (period)	Decimal separator. Separators are set in the regional settings specified in the Windows Control Panel.
, (comma)	Thousands separator.
0	Digit placeholder. Display digit or 0.
#	Digit placeholder. Display a digit or nothing.
$	Display the literal character $.
%	Percentage. Value is multiplied by 100 and the percent sign is appended.
E- or e-	Scientific notation with a minus sign next to negative exponents and nothing next to positive exponents. It must be used with other symbols, as in 0.00E-00.
E+ or e+	Scientific notation with a minus sign next to negative exponents and a plus sign next to positive exponents. It must be used with other symbols, as in 0.00E+00.
(Space)	Press SPACEBAR to enter spaces as literal characters.
"ABC"	Display anything inside quotation marks as literal characters.
!	Force left alignment instead of right alignment.
[color]	Display in the color named between the brackets. Available colors: Black, Blue, Green, Cyan, Red, Magenta, Yellow, and White.
Note   Use the DecimalPlaces property to display a different number of decimal places than the Format property settings allow. For more information, click  [image].


Date/Time data display formats

Predefined formats

The following table shows the predefined formats available for fields with the Date/Time data type and the way they display data in a form, report, or datasheet.

With this format	Dates and times are displayed this way
General Date	1/31/95 4:30:00 PM (U.S.) 31/01/95 16:30:00 (U.K.)
Long Date	Tuesday, January 31, 1995 (U.S.) 31 January 1995 (U.K.)
Medium Date	31-Jan-95
Short Date	1/31/95 (U.S.) 31/01/95 (U.K.)
Long Time	4:30:00 PM
Medium Time	4:30 PM
Short Time	16:30
Note   To ensure consistency among applications, Microsoft Access uses the regional settings specified in the Windows Control Panel for some predefined number and date/time formats. For more information, click  [image].

Custom formats

The following table shows examples of custom Date/Time formats. The table following these examples shows the Date/Time codes.

Setting	Example of display
ddd", "mmm d", "yyyy	Mon, Jun 2, 1996
mmmm dd", "yyyy	June 02, 1996
mmmm dd", "yyyy - hh:nn	June 02, 1996 - 10:02
"This week is number "ww	This is week number 23
"Today is "dddd	Today is Sunday
Create custom Date/Time formats using the following codes:

Setting	Description
"ABC"	Display anything inside quotation marks as literal characters
: (colon)	Time separator. Separators are set in the regional settings specified in the Windows Control Panel.
/	Date separator.
c	Same as the standard General Date format.
d	Day of the month in one or two numeric digits, as needed (1 through 31).
dd	Day of the month in two numeric digits (01 through 31).
ddd	First three letters of the weekday (Sun through Sat).
dddd	Full name of the weekday (Sunday through Saturday).
ddddd	Same as the standard Short Date format (1/31/95 (U.S.)).
dddddd	Same as the standard Long Date format (Tuesday, January 31, 1995 (U.S.)).
w	Day of the week (1 through 7).
ww	Week of the year (1 through 53).
m	Month of the year in one or two numeric digits, as needed (1 through 12).
mm	Month of the year in two numeric digits (01 through 12).
mmm	First three letters of the month (Jan through Dec).
mmmm	Full name of the month (January through December).
q	Date displayed as the quarter of the year (1 through 4).
y	Number of the day of the year (1 through 366).
yy	Last two digits of the year (01 through 99).
yyyy	Full year (0100 through 9999).
h	Hour in one or two digits, as needed (0 through 23).
hh	Hour in two digits (00 through 23).
n	Minute in one or two digits, as needed (0 through 59).
nn	Minute in two digits (00 through 59).
s	Second in one or two digits, as needed (0 through 59).
ss	Second in two digits (00 through 59).
ttttt	Same as the standard Long Time format.
AM/PM	Twelve-hour clock with the uppercase letters AM or PM, as appropriate.
am/pm	Twelve-hour clock with the lowercase letters am or pm, as appropriate.
A/P	Twelve-hour clock with the uppercase letter A or P, as appropriate.
a/p	Twelve-hour clock with the lowercase letter a or p, as appropriate.
AMPM	Twelve-hour clock with the appropriate morning/afternoon designator as defined in the regional settings specified in the Windows Control Panel.


Yes/No data display formats

By default, Microsoft Access displays "Yes" or "No" for fields with the Yes/No data type. To display True/False or On/Off instead, set the field's Format property. If you delete the text for a Yes/No field's format setting, -1 is displayed for Yes and 0 for No.

Custom formats

You can also create a custom format to display other strings of characters. For example, you could create a format to display "Always" or "Never." Custom formats for Yes/No data types can have one to three sections separated by semicolons, as described in the following table.

Section	Meaning
First	Not used for the Yes/No data type but does require a semicolon placeholder
Second	Values equal to -1 (Yes)
Third	Values equal to 0 (No)
The following example displays the word "Always" in blue text for Yes, True, or On and the word "Never" in red text for No, False, or Off:

;"Always"[Blue];"Never"[Red]


Text and memo data display formats

You can use the symbols in the following table to create custom formats for Text and Memo fields.

Setting	Description
@	Character placeholder. Display a character or a space. In the string being formatted, if there is a character in the position where the @ appears in the format string, display it; otherwise, display a space in that position.
&	Character placeholder. Display a character or nothing. In the string being formatted, if there is a character in the position where the & appears in the format string, display it; otherwise, display nothing in that position.
!	Force placeholders to fill from left to right instead of right to left. Placeholders are filled from right to left unless there is an ! character in the format string.
<	Force all characters to lowercase.
>	Force all characters to uppercase.
(Space)	Press SPACEBAR to enter spaces as literal characters.
"ABC"	Display anything typed inside of quotation marks as literal characters.
*	Fill available space with the character that follows the *. For example, in an eight-character field, a format of "ABCD"*x would display ABCDxxxx.
\	Display the character that follows the \ as a literal character. Used to display the following reserved characters as literal characters: @, &, <, >, !, *, and \.
[color]	Display in the color named between the brackets. Available colors: Black, Blue, Green, Cyan, Red, Magenta, Yellow, and White.
Custom formats for Text or Memo fields can have one or two sections separated with a semicolon (;), as described in the following table.

Section	Meaning
First	Fields with text
Second	Fields with null values (blank fields)
The following table shows examples of Text and Memo formats.

Setting	Data entered	Display
@@@-@@-@@@@	465073799	465-07-3799
@@@@@@@@@@@	465-07-3799	465-07-3799
@@@@@@@@@	465073799	465073799
>	davolio	DAVOLIO   (Force uppercase)
>	DAVOLIO	DAVOLIO
>	Davolio	DAVOLIO
<	davolio	davolio   (Force lowercase)
<	DAVOLIO	davolio
<	Davolio	davolio
@;"Unknown"	Any text	Same text as entered is displayed
@;"Unknown"	Zero-length string	A blank field is displayed
@;"Unknown"	Null value	"Unknown"


Controlling international data display formats

Microsoft Access can display a wide range of international formats. To help ensure consistency among applications, Microsoft Access uses the settings from the Regional Settings icon in the Windows Control Panel for the predefined Number and Date/Time formats listed in the following table.

Microsoft Access  gets the format for	From this setting  in Regional Settings
Standard  (and other number formats)	Number Format
Currency	Currency Format
Short Date	Short Date Format
Long Date	Long Date Format
Short Time	Time Format
If your data isn't displayed in the right format for your country, change the regional settings specified in the Control Panel.

Note   Transferring data between computers with different regional settings can result in incorrect currency data. For example, when using the Currency format, a value of 5,47 kr on a computer set for Denmark converts to $5.47 on a computer set for the United States. To prevent such errors, define a custom format for the currency, such as #,## kr. The custom format overrides the regional settings specified in the Windows Control Panel. Similar problems won't occur when transferring standard number, date, or time data between computers with different regional settings.


Define the number of decimal places to display for a Number or Currency field

1	In table Design view, in the upper portion of the window, click the field you want to define decimal places for.

2	In the lower portion of the window, click the DecimalPlaces property box, click the arrow, and then select the desired number of decimal places.

The DecimalPlaces property provides a default setting, Auto, and the option to specify from 0 to 15 decimal places. When set to Auto, fields with Format property settings of Currency, Fixed, Standard, Percent and Scientific display 2 decimal places.

Notes

•	The DecimalPlaces property setting affects only the number of decimal places that display, not how many decimal places are stored. For example, you can set the DecimalPlaces property to 2 for a Number field with the FieldSize property set to Integer; it will display with two decimal places, but because only whole number (integer) values will stored, zeros will fill the two decimal places. To change the number of decimal places that will be stored, you must change a Number field's FieldSize property. For information on setting a field's FieldSize property, click  [image].

•	The DecimalPlaces property has no effect unless a Number or Currency field has a Format property setting. For information on setting a field's data display format, click  [image].

•	You can also set the DecimalPlaces property for query fields and for text box controls in forms and reports. For example, you might want a Currency field to display 2 decimal places in a table, but display no decimal places in a report. To do this, set the DecimalPlaces property for the field to 2, and set the DecimalPlaces property to 0 for the text box control that prints the field’s value in a report.


  Choose between a data display format and an input mask for a field

Microsoft Access provides two field properties that produce similar results: the Format property and the InputMask property.

Use the Format property to display data in a consistent format. For example, if you set the Format property for a Date/Time field to Medium Date format, all dates entered will display in this form: 12-Jan-95. If a user of your database enters a date in the form, 01/12/95 (or any other valid date format), Microsoft Access will convert the display to the Medium Date format when the record is saved.

The Format property affects only how a value is displayed, not how it is stored in the table. Also, a display format isn't applied until the data entered is saved — nothing is displayed in the field to suggest or control the format in which data is entered. If you need to control how data is entered, use an input mask in addition to, or instead of, a data display format. If you want data to display exactly as entered, don't set the Format property.

Predefined display formats are available for Number, Currency, Date/Time, AutoNumber, and Yes/No fields, and you can define custom formats for them as well. There are no predefined formats for Text and Memo fields, but you can define custom formats. You can't define a display format for OLE Object fields.

Use the InputMask property to display literal display characters in the field with blanks to fill in. For example, if all phone numbers you enter in a field have the same format, you can create an input mask as shown in the following illustration.

An input mask ensures that the data will fit in the format you define, and you can specify the kind of values that can be entered in each blank. For example, the preceding input mask requires that all entries contain exactly enough digits to make up a U.S. area code and telephone number, and that only digits can be entered in each blank. An input mask can be defined with or without a wizard for a Text or Date/Time field. You can also define an input mask without a wizard for a Number or Currency field.

If you define both a display format and an input mask for a field, Microsoft Access uses the input mask when you are adding or editing data, and the Format setting determines how the data is displayed when the record is saved. When using both Format and InputMask properties, be careful that their results don't conflict with each other.

What do you want to do?

Define a display format using a predefined format

Define a custom display format

 	Define an input mask using a wizard

 	Define an input mask without using a wizard


Define an input mask using a wizard

1	In table Design view, in the upper portion of the window, click the field you want to define an input mask for.

2	In the lower portion of the window, click the InputMask property box, and then click the Build button.

3	Answer the questions in the Input Mask Wizard dialog boxes. You can select from a list of predefined input masks, which you can modify if you want. You can also set the placeholder character that will be displayed for entry blanks.

4	In the last dialog box, choose the Finish button to build the input mask.


Define an input mask without using a wizard

1	In table Design view, in the upper portion of the window, click the field you want to define an input mask for.

2	In the lower portion of the window, click the InputMask property box, and then type the input mask definition.

For information on how to define an input mask, click  [image].


Examples of input masks

An input mask is used in fields (in tables and queries) and in text boxes and combo boxes (in forms) to format data and provide some control over what values can be entered. An input mask consists of literal characters (such as spaces, dots, dashes, and parentheses) that separate blanks to fill in. The InputMask property setting consists of literal characters along with special characters that determine the kind of value that can be entered into the blank in that position. Input masks are primarily used in Text and Date/Time fields, but can also be used in Number or Currency fields.

The following table shows some useful input mask definitions and examples of values you can enter into them. Refer to the table at the end of this topic for details on the codes used to create input mask definitions.

Input mask definition	Examples of values
(000) 000-0000	(206) 555-0248
(999) 000-0000!	(206) 555-0248
	(   ) 555-0248
(000) AAA-AAAA	(206) 555-TELE
#999	-20
	2000
>L????L?000L0	GREENGR339M3
	MAY  R 452B7
>L0L 0L0	T2F 8M4
00000-9999	98115-
	98115-3007
>L<??????????????	Maria
	Brendan
ISBN 0-&&&&&&&&&-0	ISBN 1-55615-507-7
	ISBN 0-13-964262-5
>LL00000-0000	DB51392-0493
The input mask definition can contain up to three sections separated by semicolons; for example, (999) 000-0000!;0;" ".

Section	Meaning
First	The input mask itself.
Second	Determines whether to store the literal display characters. 0 = store literal characters with the value entered 1 or leave blank = store only characters entered in blanks
Third	Character that is displayed for blanks in the input mask. You can use any character; type " " to display a space. If you leave this section blank, the underscore ( _ ) is used.
Microsoft Access interprets characters in the first part of the InputMask property definition as shown in the following table. To define a literal character, enter any character other than those shown in the table, including spaces and symbols. To define one of the following characters as a literal character, precede that character with a \.

Character	Description
0	Digit (0 through 9, entry required; plus [+] and minus [-] signs not allowed).
9	Digit or space (entry not required; plus and minus signs not allowed).
#	Digit or space (entry not required; blank positions converted to spaces, plus and minus signs allowed).
L	Letter (A through Z, entry required).
?	Letter (A through Z, entry optional).
A	Letter or digit (entry required).
a	Letter or digit (entry optional).
&	Any character or a space (entry required).
C	Any character or a space (entry optional).
.  ,  :  ;  -  /	Decimal placeholder and thousands, date, and time separators. (The actual character used depends on the regional settings specified in the Windows Control Panel.)
<	Causes all characters that follow to be converted to lowercase.
>	Causes all characters that follow to be converted to uppercase.
!	Causes input mask to fill from right to left, rather than from left to right, when characters on the left side of the input mask are optional. You can include the exclamation point anywhere in the input mask.
\	Causes the character that follows to be displayed as a literal character. Used to display any of the characters listed in this table as literal characters (for example, \A is displayed as just A).
Password	Setting the InputMask property to the word Password creates a password entry text box. Any character typed in the text box is stored as the character but is displayed as an asterisk (*).
Note   Using the ! (fill from right) code doesn't always achieve the desired results. For example, if you define an input mask like this: !(999) 000-0000 for a U.S. area code and phone number with the area code as optional, you can't enter a properly formatted phone number without an area code unless you use the mouse or keyboard to skip to the area code entry.

You can work around this by combining a more generic input mask and a validation rule. If you use the following example input mask and validation rule instead, you can type digits anywhere in the mask, even though the digits still fill from left to right:

Input Mask: !\(999") "999\-9999

Validation Rule: Like "#######" Or Like "##########"

Validation Text: You must enter a 7- or 10-digit phone number

Note that the input mask does not contain any required digits; the required digits are handled by the validation rule.


Define a default value that is automatically entered into a field

You can specify a value that will be automatically entered when you add a new record. You can accept the default value or type a new value over it.

1	In table Design view, in the upper portion of the window, click the field you want to define a default value for.

2	In the lower portion of the window, click the DefaultValue property box, and then type the default value (such as "New York") or an expression (such as Date()).

To view examples of default values, click  [image].

Notes

•	Setting the DefaultValue property for a field has no effect on existing data. However, you can replace a field's current value with the default value by pressing CTRL+ALT+SPACEBAR.

•	If you define a default value for a Yes/No field in a database that will be used internationally, enter an equal sign before the value and Microsoft Access will display the default value in the local language. For example, enter =Yes to have Microsoft Access display "Ja" in Germany.


Examples of default values

Field	Expression	Default field value
Quantity	1	1
Region	"MT"	MT
Fax	" "	A zero-length string to indicate that by default this field should be empty
Order Date	Date( )	Today's date
Month	DatePart("m", Date( ))	The current month


Define validation rules to control what values can be entered into a field

You can ensure that data is entered correctly into a field by defining a field validation rule. A field validation rule is used to check the value entered into a field as the user leaves the field. An error message you define is displayed if the value breaks the validation rule.

1	In table Design view, in the upper portion of the window, click the field you want to define a validation rule for.

2	In the lower portion of the window, click the ValidationRule property box, and then type the validation rule, or click the Build button to create the validation rule using the Expression Builder.

For example, you could define the validation expression ">9" for a Quantity field to prevent a user from placing an order for fewer than 10 units.

3	In the ValidationText property box, type the error message that you want displayed when the rule is broken.

For example, for the validation expression ">9", you could enter "You must order 10 or more units." To view more examples of field validation rules, click  [image].

If you set a validation rule in a field that contains data, Microsoft Access will ask if you want to apply the new rule to existing data when you save the table.

Notes

•	You can't refer to other fields or controls in a field's validation rule, or to user-defined functions, aggregate functions, Microsoft Access or SQL domain aggregate functions, or the CurrentUser or Eval functions. However, you can refer to other fields in the same table using a record validation rule to control when an entire record can be saved. For more information on setting a record validation rule, click  [image].

•	Field validation rules are enforced whenever you add or edit data, whether it is through table Datasheet view, a control on a form that is bound to the field, an append query, an update query, or Microsoft Access code, or by importing data from another table.

•	You can test to see if the data in a table meets validation rules by clicking the right mouse button on the title bar of table Design view, and then clicking Test Validation Rules.


Define validation rules to control when a record can be saved

A record validation rule controls when an entire record can be saved. Unlike field validation rules, record validation rules can refer to other fields. This makes them useful when you want to compare values in different fields.

1	In table Design view, click  [image]  on the toolbar to display the table's property sheet.

2	In the ValidationRule property box, type the validation rule. Or click the Build button to create the validation rule using the Expression Builder.

3	In the ValidationText property box, type the error message that you want Microsoft Access to display when the rule is broken.

If you set a validation rule in a table that contains data, Microsoft Access will ask if you want to apply the new rule to existing data when you save the table.

Notes

•	You can specify only one validation expression for a table. However, if you want to specify more than one rule, you can combine expressions for the ValidationRule property setting with the And operator.

•	Record validation rules are enforced whenever you add or edit data, whether it is through table Datasheet view, a form bound to the table, an append query, an update query, or Microsoft Access code, or by importing data from another table.

•	You can test to see if the data in a table meets validation rules by clicking the right mouse button on the title bar of table Design view, and then clicking Test Validation Rules.


Restrict or validate data

Microsoft Access provides a variety of ways to control how data is entered into your database. For example, you can limit the data that can be entered into a field by defining a validation rule for that field. If the data that is entered into the field breaks the rule, Microsoft Access will display an error message telling the user what kind of entries are allowed. Another method of controlling data entry is to create an input mask to restrict the kind of values that can be entered in positions across the field. You can perform these simple forms of validation and restriction by setting properties for fields in tables, or by setting properties for controls on forms.

In most cases, it is preferable to define data validation and restriction by setting a field's properties in table Design view. This saves you time, because whenever you use that field in a form, the field's validation rule and other properties will apply to data entry performed using the form.

However, if the data entered into a control on a form isn't bound to a field in a table, and you need to restrict or validate data entry, you must define those properties in the form. Additionally, there are situations where you must use macros or Visual Basic for applications code in conjunction with a form to perform more complex validation. For example, you might want to be able to override your validation rule or compare values from different tables.

What do you want to do?

Find out more about validating or restricting data entry using field or table properties

Find out more about validating or restricting data entry using form properties or macros


Validate or restrict data entry in tables

Microsoft Access provides a variety of ways to control how data is entered in fields in your table.

The first thing you should consider is whether a field has an appropriate data type . For example, Date/Time fields only allow entry of valid date and time formats. If you are currently using a Text field for such information, it may be appropriate to change the field to a Date/Time field.

There are also additional properties that you can set for a field to provide further control over the values that can be entered into the field:

•	For Number fields, you can choose from a variety of field sizes to control the kind and range of values that can be entered.

•	For Text fields, you can set the maximum number of characters that can be entered.

•	For all but AutoNumber fields (which generate their own data), you can require that data be entered in the field.

•	For Text, Date/Time, and Number fields, you can define an input mask to provide blanks to fill in and can control what values can be entered in those blanks.

•	For all but Memo and OLE Object fields, you can prevent duplicate values from being entered into a field or combination of fields.

You can also define two kinds of validation rules: field validation rules and record validation rules. Validation rules allow you to define a rule to limit what will be accepted.

•	A field validation rule is used to check the value entered into a field as the user leaves the field. For example, you could define >=10 And <=100 as the validation rule for a Number field to allow only values from 10 to 100 to be entered.

•	A record validation rule controls when an entire record can be saved. Unlike field validation rules, record validation rules can refer to other fields in the same table. This makes them useful when you want to compare values in different fields. For example, you could define [RequiredDate]<=[OrderDate]+30 as the validation rule for an Orders table. This rule will make sure that the date entered into the RequiredDate field is within 30 days of the date in the OrderDate field.

Both kinds of validation rules will display a message that you define when the rule is broken to inform the user how to properly enter data.

What do you want to do?

Find out more about choosing an appropriate data type for a field

Set the field size for a Number or Text field

Require that data be entered in a field

Define an input mask to control data entry

Prevent duplicate entries in a field

Define a field validation rule

Define a record validation rule


Examples of field validation rules

ValidationRule setting	ValidationText setting
<>0	Please enter a nonzero value.
0 Or >100	Value must be either 0 or over 100.
Like "K???"	Value must be four characters beginning with the letter K.
<#1/1/95#	Enter a date before 1995.
>=#1/1/94# And <#1/1/95#	Date must be in 1994.


Require that data be entered for a field

1	In table Design view, in the upper portion of the window, click the field that you want to require data entry for.

2	In the lower portion of the window, click the Required property box, and then select Yes.

When you save changes to your table, Microsoft Access gives you the option to check to see whether the field has a value in all existing records. However, you can require that a value be entered in this field in all new records even if there are existing records with Null (blank) values in the field that aren't going to be changed.

Note   The Required property is enforced at the table level, so if you set this property to Yes, the field must have a value in all instances in which data might be entered in the field — in the table, in forms and datasheets based on the table, when a macro or Visual Basic for applications code sets the value of the field, or when data is imported into the table.


Properties that control how blank fields (null values and zero-length strings) are handled

For Text or Memo fields, you can control how a blank field is handled by setting different combinations of the field's Required and AllowZeroLength properties. The Required property determines whether an entry must be made. If the AllowZeroLength property is set to Yes, Microsoft Access will differentiate between two kinds of blank values: null values and zero-length string values.

The difference between nulls and zero-length strings

Microsoft Access allows you to distinguish between two kinds of blank values, because in some situations, a field may be left blank because the information may exist but is not currently known, or it may be left blank because it doesn't apply to the record at all. For example, if a table has a Fax Number field, you may leave the field blank because you don't know if a customer has a fax number, or you may leave it blank because you know that the customer doesn't have a fax number. In this case, leaving the field blank enters a null which means "I don't know." Entering a zero-length string by typing quotation marks (" ") means "I know that there is no value."

When to allow null values in a field

If you want to allow a field to be left blank and don't need to determine why the field is left blank, set both the Required and AllowZeroLength properties to No. This is the default when creating a new Text or Memo field.

When to allow neither null values or zero-length strings in a field

If you never want a field to be left blank, set the Required property to Yes and the AllowZeroLength property to No.

When to allow both null values and zero-length strings in a field

If you want to be able to distinguish between a field that is blank because the information is unknown and a field that is blank because it doesn't apply, set the Required property to No and the AllowZeroLength property to Yes.

In this case, when adding a record you would leave the field blank (which enters a null value) if the information is unknown, but you would type quotation marks (" ") with no space between them to enter a zero-length string to indicate that the field doesn't apply to the current record.

When to allow only zero-length strings or some value in a field

If you only want a field left blank if you know that a field isn't applicable to a record, set both the Required property and the AllowZeroLength property to Yes.

In this case, the only way to leave a field blank is to type quotation marks (" ") with no space between them to enter a zero-length string.

The following table shows the results of all possible settings of the Required and AllowZeroLength properties.

Required	AllowZeroLength	User's action	Value entered
No	No	Presses ENTER	<Null>
		Presses SPACEBAR	<Null>
		Types " "	(not allowed)
Yes	No	Presses ENTER	(not allowed)
		Presses SPACEBAR	(not allowed)
		Types " "	(not allowed)
No	Yes	Presses ENTER	<Null>
		Presses SPACEBAR	<Null>
		Types " "	<Zero-length string>
Yes	Yes	Presses ENTER	(not allowed)
		Presses SPACEBAR	<Zero-length string>
		Types " "	<Zero-length string>
Setting a field display format to distinguish null values from zero-length strings

When you view data in a field that contains both null values and zero-length strings, the fields look the same — they contain no values. If you want to clearly distinguish null values from zero-length strings, you can set the Format property for that field in the table. For example, you can set the Format property for a Phone field so that entering a null displays "Unknown." To do this, enter the following format for the field:

@;"Unknown"

For more information on defining a field's display format, click  [image].

Finding zero-length strings or null values

You can use the Find command on the Edit menu to locate null values or zero-length strings. In Datasheet view or Form view, select the field in which you want to search. In the Find What box, type Null to find null values, or type quotation marks (" ") with no space between them to find zero-length strings. In the Match box, select Whole Field, and make sure the Search Fields As Formatted check box isn't selected.

For more information on using the Find command, click  [image].


Create a single-field index

1	In table Design view, in the upper portion of the window, click the field that you want to create an index for.

2	In the lower portion of the window, click the Indexed property box, and then select Yes (Duplicates OK) or Yes (No Duplicates).

Select the Yes (No Duplicates) option if you want to ensure that no two records have the same data in this field.


Create a multiple-field index

1	Open the table in Design view.

2	Click  [image]  on the toolbar.

3	In the first blank row in the Index Name column, type a name for the index. You can name the index after one of the index fields, or use some other appropriate name.

4	In the Field Name column, click the arrow and select the first field for the index.

5	In the next row in the Field Name column, select the second field for the index. (Leave the Index Name column blank in that row.) Repeat this step until you have selected all the fields you want to include in this index. You can use up to 10 fields.

6	Click  [image]  when you have finished selecting fields for the index.

Note   The default sort order is Ascending. Select Descending in the Sort Order column of the Indexes Window to sort the corresponding field's data in descending order.


Decide if and when to use an index

An index helps Microsoft Access find and sort records faster. Microsoft Access uses indexes in a table as you use an index in a book: to find data, it looks up the location of the data in the index. You can create indexes based on a single field or on multiple fields. Multiple field indexes enable you to distinguish between records in which the first field may have the same value.

Deciding which fields to index

You'll probably want to index fields you search frequently, fields you sort, or fields that you join to fields in other tables in queries. However, indexes can slow down some action queries such as append queries, when the indexes for many fields need to be updated while performing these operations.

The primary key of a table is automatically indexed, and you can't index a field whose data type is Memo or OLE Object. For other fields, you should consider indexing a field if all the following apply:

•	The field's data type is Text, Number, Currency, or Date/Time.

•	You anticipate searching for values stored in the field.

•	You anticipate sorting values in the field.

•	You anticipate storing many different values in the field. If many of the values in the field are the same, the index may not significantly speed up queries.

Multiple-field indexes

If you think you'll often search or sort by two or more fields at a time, you can create an index for that combination of fields. For example, if you often set criteria for LastName and FirstName fields in the same query, it makes sense to create a multiple-field index on both fields.

When you sort a table by a multiple-field index, Microsoft Access sorts first by the first field defined for the index. If there are records with duplicate values in the first field, Microsoft Access sorts next by the second field defined for the index, and so on.

What do you want to do?

Define a single-field index

Define a multiple-field index

View or edit indexes


View or edit indexes

1	Open the table in Design view.

2	Click  [image]  on the toolbar.

3	Change indexes or index properties as desired. To delete an index, delete its row in the Indexes window. This removes only the index, not the field itself.

4	Click  [image]  when you have finished viewing or editing the indexes and index properties.


Prevent duplicate values from being entered into a field

A single-field primary key prohibits duplicate values in that field to ensure that each record has a unique identifier. However, you may want to prevent duplicate values in other fields as well. For example, you might want to assign computers to employees using a serial number field for the computers.

1	In table Design view, in the upper portion of the window, click the field to prohibit duplicate values for.

2	In the lower portion of the window, click the Indexed property box, and then select Yes (No Duplicates).

To find out how to prevent duplicate entries in a combination of fields, click  [image].


Prevent duplicate values from being entered in a combination of fields

1	Open the table in Design view.

2	Create a multiple-field index using the fields you want to prohibit duplicate values for. Leave the Indexes window open when you have finished defining the index.

How?

3	In the upper portion of the Indexes window, click the new index name.

4	In the lower portion of the Indexes window, click the Unique property box, and then select Yes.


Delete an index

Indexes speed up searches, but they can also slow bulk record updates such as append queries. If you have indexed a field or fields that you don't use to search, sort, or join, and you perform operations that perform bulk record updates that you want to speed up, delete the index. Deleting an index doesn't delete the field or the data in the field.

To delete a single-field index

1	In table Design view, in the upper portion of the window, click the field whose index you want to delete.

2	In the lower portion of the window, click the Indexed property box and select No.

To delete a multiple-field index

1	Open the table in Design view.

2	Click  [image]  on the toolbar.

3	In the Indexes window, select the rows containing the index you want to delete and press the DEL key. This removes only the index, not the field itself.


Define a different name to be used for the field's column name in a datasheet

You can define a different name to serve as the column heading for the field when the table or query is in Datasheet view by setting a field's Caption property. This is useful in situations where you want the column heading to be longer or more descriptive than the actual field name. For example, it can be more convenient to name a field LName for use in Visual Basic for applications code and expressions, but preferable to show "Last Name" as the field's column heading. A field's Caption property also specifies the default text for labels attached to controls in forms and reports created by dragging a field from the field list.

1	In table Design view, in the upper portion of the window, click the field for which you want to define a different column name.

2	In the lower portion of the window, click the Caption property box, and then type the text for the column name. The text can contain any combination of letters, numbers, spaces, and symbols up to 255 characters in length.

Note   If you set a field's Caption property, and later rename a field while in Datasheet view, the field's Caption text will be deleted. If this happens, you can redefine the field's Caption as described in this topic. You can avoid this by renaming the field in Design view.


Set defaults for the appearance of Datasheet view

1	In Datasheet view, click Options on the Tools menu.

2	Click the Datasheet tab.

3	Click the options you want.


Change font, font style, size, and color in Datasheet view

1	In Datasheet view, click Font on the Format menu.

2	Click the options you want.


Change the gridline style and background color in Datasheet view

1	In Datasheet view, click Cells on the Format menu.

2	Click the options you want.


Display the most current data in Datasheet or Form view

If you are using a database that's shared on a network, other users could be changing data while you are viewing the same data in a datasheet or form. Microsoft Access updates the data you see at regular intervals. You can change how often data is automatically updated. For more information, click  [image]. You can also update it at any time.

•	In Datasheet or Form view, to display the most current data immediately, click Refresh on the Records menu.

The Refresh command updates only data that already exists in your datasheet or form. It doesn't reorder records, display new records, or remove deleted records and records that no longer meet specified criteria. To perform those actions, requery the records.

•	In Datasheet or Form view, to requery the current data, press SHIFT+F9.


Change how often data is updated automatically in Datasheet or Form view

1	In Datasheet or Form view, click Options on the Tools menu.

2	Click the Advanced tab.

3	In the Refresh Interval box, type the number of seconds you want between each automatic update of data. For example, if you type 120, the data is updated every 2 minutes.

Note   This setting takes effect only if the database is shared on a network. It updates only data that already exists in your datasheet or form. It doesn't reorder records, display new records, or remove deleted records and records that no longer meet specified criteria. To perform those actions, requery the records by pressing SHIFT+F9.


Selecting fields and records in Datasheet view

The following table lists mouse techniques for selecting data or records in Datasheet view.

To select	Click
Data in a field	Where you want to start selecting and drag across the data.
An entire field	The left edge of the field in a datasheet, where the pointer changes into  [image].
Adjacent fields	The left edge of a field and drag to extend the selection.
A column	The field selector.
Adjacent columns	The field name at the top of the column and then, without releasing the mouse, drag to extend the selection.
A record	The record selector.
Multiple records	The record selector of the first record, and then drag to extend the selection.
All records	Select All Records on the Edit menu.
The following table lists keyboard techniques for selecting data or records in Datasheet view.

To select	Do this
Data in a field	Move the insertion point to the start of the text you want to select, and then hold down SHIFT and press the arrow keys to move to the end of the selection.
An entire field	Move the insertion point to the field, and press F2.
Adjacent fields	With a field selected, hold down SHIFT and press the appropriate arrow key.
The current column	Press CTRL+SPACEBAR.
The current record	Press SHIFT+SPACEBAR.
Multiple records	Press SHIFT+SPACEBAR, and then SHIFT+UP ARROW or SHIFT+DOWN ARROW.


Moving between records using navigation buttons in Datasheet or Form view

The navigation buttons are located at the bottom of the window in Datasheet  or Form view. You can use these buttons to quickly move between records.


Find a record by record number in Datasheet or Form view

1	In Datasheet or Form view, double-click the number in the record number box to select it.

2	Type the number of the record you want, and then press ENTER.


Move between fields in long records with the Go To Field box in Datasheet view

The Go To Field box makes it easier to move between fields in long records in Datasheet view.

1	In Datasheet view, click Toolbars on the View menu.

2	Select Formatting (Datasheet).

3	Click Close.

The Go To Field box is the leftmost item on the Datasheet Formatting toolbar. Use it to click the name of the field in the current record that you want to move to.


Move columns in Datasheet view

1	In Datasheet view, select the columns you want to move.

To select one column, click the field selector for that column.

To select adjacent columns, click a column’s field selector and then, without releasing the mouse button, drag to extend the selection.

2	Click and hold down the mouse button in the field selector again.

3	Drag the columns to a new position.


Resize rows in Datasheet view

1	In Datasheet view, position the pointer between two record selectors at the left side of the datasheet, as shown in the following illustration.

2	Drag the edge of the row until the row is the desired height.

Notes

•	This resizes all the rows in the datasheet at the same time.

•	You can’t undo changes to the size of rows using the Undo command on the Edit menu. To undo changes, close the datasheet, and then click No when asked if you want to save changes to the layout of the datasheet.


Resize a column in Datasheet view

1	In Datasheet view, position the pointer on the right edge of the column you want to resize, as shown in the following illustration.

2	Drag until the column is the desired width.

Note   You can’t undo changes to the width of columns using the Undo command on the Edit menu. To undo changes, close the datasheet, and then click No when asked if you want to save changes to the layout of the datasheet.


Freeze and unfreeze columns in Datasheet view

You can freeze one or more of the leftmost columns on a datasheet so that they are visible at all times no matter where you scroll.

1	In Datasheet view, select the columns you want to freeze.

To select the leftmost column, click the field selector for that column.

To select more than one of the leftmost columns, click the leftmost column’s field selector and then, without releasing the mouse button, drag to extend the selection.

2	To freeze the selected columns, click Freeze Columns on the Format menu.

To unfreeze all columns, click Unfreeze All Columns on the Format menu.


Hide columns in Datasheet view

1	In Datasheet view, select the column(s) you want to hide.

To select one column, click the field selector for that column.

To select adjacent columns, click a column’s field selector and then, without releasing the mouse button, drag to extend the selection.

2	On the Format menu, click Hide Columns.

For information on showing hidden columns, click  [image].


Show hidden columns in Datasheet view

1	In Datasheet view, click Unhide Columns on the Format menu.

2	In the Unhide Columns dialog box, select the names of the columns that you want to show.


Find a specific record by scrolling in Datasheet view or in a continuous form

If there are more records than fit in your Datasheet view or continuous form window, you can use the scroll box on the scroll bar to find a specific record.

•	Drag the scroll box up or down on the scroll bar.

Next to the scroll box, Microsoft Access displays the number of the first record at the top of the screen.


Export data to another database or file format

You can export data from a table or query to any of these formats.

Application	Version or format supported
Microsoft FoxPro	2.0, 2.5, 2.6, and 3.0
dBASE	III, III+, IV, and 5
Paradox	3.x, 4.x, and 5.0
Programs and databases that support the ODBC protocol	Including but not limited to Microsoft SQL Server
Microsoft Excel	2.0, 3.0, 4.0, 5.0, and 7.0
Lotus 1-2-3	.wks, .wk1, and .wk3 formats
Delimited text files	Windows (ANSI), DOS (PC-8), or Macintosh text format
Fixed-width text files	Windows (ANSI), DOS (PC-8), or Macintosh text format
You can also export any of your database objects to another Microsoft Access database. This is effectively the same as copying and pasting objects between databases.

You can exchange Microsoft Access data with Microsoft Word and Microsoft Excel several ways.

If you are using Microsoft Mail, or another electronic mail application that supports Messaging Application Programming Interface (MAPI), you can attach the output of a datasheet, table, query, form, report, or module to an electronic mail message in Microsoft Excel, rich-text format, or MS-DOS text formats.

To make frequent export operations more convenient, you can automate them using macros or Visual Basic for applications code.

What do you want to do?

Export a table or other database object to another Microsoft Access database

Export a table or query to a FoxPro, Paradox, or dBASE file

Export a table or query to an SQL database or other ODBC data source

Export a table or query to a Microsoft Excel or Lotus 1-2-3 spreadsheet file

Export a table or query to a delimited or fixed-width text file

Exchange Microsoft Access data with Microsoft Word

Attach a database object's output to an electronic mail message

Use macros or Visual Basic code to automate exporting data


Export a table or other database object to an existing Microsoft Access database

Note   You can export only tables to Microsoft Access version 1.x and 2.0 databases.

1	In the Database window, click the name of the object you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK.

3	Click the arrow to the right of the Save In box and select the drive or folder where the Microsoft Access database you want to export to is located.

4	Double-click the icon for the database that you want to export.

5	In the Export dialog box, enter a name for the new object (or accept the current name). If you are exporting a table, in Export Tables, select whether to export both the table's definition and data, or just the table's definition. Click OK to export the object.

Tip   You can export only one object at a time. If you want to export several objects at once, open the database you want to export to, and then import the objects instead. For more information, click  [image].


Export a table or query to a FoxPro, Paradox, or dBASE file

1	In the Database window, click the name of the table or query you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK.

3	In the Save As Type box, click the database format you want.

4	Click the arrow to the right of the Save In box and select the drive or folder to export to.

5	In the File Name box, enter the filename, and then click Export.

Note   If you export a table with table or field names that aren't allowed in the destination database, Microsoft Access adjusts the names. For example, if you export data to a dBASE table, any field names longer than 10 characters will be truncated.


Export a table or query to an SQL database table or other ODBC data source

Important   You cannot export to an SQL or other ODBC data source unless the appropriate driver has been installed first. For more information on installing ODBC drivers, click  [image].

1	In the Database window, click the name of the table or query you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK. The Save Object Name dialog box is displayed.

3	In the Save As Type box, click ODBC Databases.

4	In the Export dialog box, enter a name for the file (or use the suggested name), and then click OK.

The SQL Data Sources dialog box is displayed listing the defined data sources for any ODBC drivers installed on your computer. To define a new data source for any installed ODBC driver, click New, and then follow the instructions in the Add Data Source dialog box and the dialog boxes that follow it before continuing.

5	In the SQL Data Sources dialog box, double-click the ODBC data source that you want to export to.

6	Particular ODBC data sources have different requirements for accessing their data. For example, most require you to enter a logon ID and password. You might need to get this information from your system administrator. Enter the appropriate information in the dialog box, and then click OK.

Microsoft Access connects to the ODBC data source and creates the new table.

Notes

•	You can export data from a Microsoft Access table or query to create a new table in an SQL database or any other program that provides an ODBC driver that is installed on your computer. For more information on the availability of additional ODBC drivers, installing them, and setting up data sources, click  [image].

•	Once you export a Microsoft Access table to an SQL database, you can use an SQL pass-through query to add an index to the table. For more information, click  [image].


Export a table or query to a spreadsheet

1	In the Database window, click the name of the table or query you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK.

3	In the Save As Type box, click the spreadsheet format you want.

4	Click the arrow to the right of the Save In box and select the drive or folder to export to.

5	Double-click an existing spreadsheet, or enter a new name in the File Name box.

Caution   With two exceptions, if you export to an existing spreadsheet file, Microsoft Access deletes and replaces the data in that spreadsheet. The exceptions occur when you export to a Microsoft Excel version 5.0 or 7.0 workbook, where the data is copied to the next available worksheet.

If you selected Microsoft Excel 5-7 in step 3 and you want to preserve fonts, preserve the displayed data from Lookup fields, and preserve field widths, select the Save Formatted check box. Saving will be slower.

6	Click Export.

Microsoft Access creates the spreadsheet file containing the data from your table or query. Field names from the table or query are placed in the first row of the spreadsheet.

Note   You can save the output of a datasheet, form, or report directly to a Microsoft Excel worksheet to preserve formatting such as fonts, or a report's group levels. For more information, click  [image].


Load the output of a datasheet, form, or report into Microsoft Excel

Saving output to Microsoft Excel preserves most formatting, such as fonts and colors. Report group levels are saved as Microsoft Excel outline levels. A form is saved as a table of data.

1	In the Database window, click the name of the table, query, form, or report you want to save and load into Microsoft Excel. To save a selection of a datasheet, open the datasheet, and then select the portion of the datasheet before continuing.

2	On the Tools menu, point to OfficeLinks, and then click Analyze It With MS Excel. The output is saved as a Microsoft Excel file (.xls) file in the folder where Microsoft Access is installed. Microsoft Excel automatically starts and opens it.


Export a table or query to a delimited or fixed-width text file

1	In the Database window, click the name of the table or query you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK.

3	In the Save As Type box, click Text Files.

4	Click the arrow to the right of the Save In box and select the drive or folder to export to.

5	In the File Name box, enter the filename, and then click Export.

Microsoft Access starts the Text Export Wizard.

If you saved a specification when exporting this table or query previously and want to load it, click Advanced, click Specs, and then double-click the specification.

Note   At any point before clicking Finish, you can click the Advanced button to specify the text format to save as (Windows (ANSI), DOS OS/2 (PC-8), or Macintosh); date, time, and number formats; and which columns to export.

6	Choose whether to create a delimited or fixed-width file, and then click Next.

7	Follow the directions in the remaining dialog boxes.

Notes

•	When the wizard is finished, it automatically saves a specification of the choices you made to the default name: Filename_ExportSpec. To specify the name yourself, click Advanced, click Specs, and then click Save As. You can load this specification the next time you export data from the same table or query so you don't have to make the same choices again.

•	To include the datasheet's font and other formatting elements that aren't included in a text file, you can save all or a selection of a datasheet of a table, form, or query as a rich-text format file. For information, click  [image].


Exchange Microsoft Access data with Microsoft Word

There are four ways you can use Microsoft Access data with Microsoft Word:

•	If you are using Microsoft Word version 6.0 or later, you can use the Microsoft Word Mail Merge Wizard to create a mail merge document in Word using a link to Microsoft Access data. Once the link is established, you can open your document in Microsoft Word at any time to print a new batch of form letters or labels using the current data in Microsoft Access.

•	For any version of Microsoft Word, you can export Microsoft Access data to a mail merge data source file that can be used with the mail merge feature of Word.

•	You can save the output of a datasheet, form, or report as a rich-text format (.rtf) file. A rich-text format file preserves formatting, such as fonts and styles, and can be opened with Microsoft Word and other Windows word-processing or desktop-publishing programs.

•	You can save the output of a datasheet, form, or report as a rich-text format (.rtf) file and automatically load the file into Microsoft Word.

What do you want to do?

 	Merge Microsoft Access data using the Microsoft Word Mail Merge Wizard

Export a table or query to a Microsoft Word mail merge data source file

Save the output of a datasheet, form, or report as a rich-text format file

Save the output of a datasheet, form, or report as a rich-text format file and automatically open it with Microsoft Word


Merge data from a table or query using the Microsoft Word Mail Merge Wizard

•	In the Database window, click the name of the table or query you want to export, and then on the Tools menu, point to OfficeLinks and click Merge It.

Note   You can also begin the operation of merging data into form letters from within Word for Windows version 6.0 or 7.0. For more information, see your Word for Windows documentation.


Export to a Microsoft Word mail merge data source file

1	In the Database window, click the name of the table or query you want to export, and then on the File menu, click Save As/Export.

2	In the Save As dialog box, click To An External File Or Database, and then click OK.

3	In the Save As Type box, click Microsoft Word Merge.

4	Click the arrow to the right of the Save In box and select the drive or folder to export to.

5	In the File Name box, enter the filename, and then click Export.

Microsoft Access creates the data source containing the field names and all the data from your table.

Notes

•	If you create a Word mail merge data source, Microsoft Access uses the field names from the table or query. However, to conform to Word for Windows formatting rules, field names longer than 20 characters are truncated, and characters other than letters, numbers, and underscores are converted to underscores.

•	In a Word mail merge data source, the first record in the file contains the field names and is called the header row. All succeeding records are the data rows. The field names in the header record must match the field names in the main document. If they don't match, edit the field names either in the data source (you can open the data source in Word for Windows) or in the main document so they do match.


Load the output of a datasheet, form, or report into Microsoft Word

1	In the Database window, click the name of the table, query, form, or report you want to save and load into Microsoft Word. To save a selection of a datasheet, open the datasheet and select the portion of the datasheet before continuing.

2	On the Tools menu, point to OfficeLinks, and click Publish It With MS Word. The output is saved as a rich-text format (.rtf) file in the folder where Microsoft Access is installed. Word automatically starts and opens it.


Save an object's output as a Microsoft Excel or Rich Text Format file

You can save output to Microsoft Excel version 5.0 or 7.0 or to Rich Text Format and preserve most formatting, such as fonts and colors. When saving to Microsoft Excel, report group levels are saved as Microsoft Excel outline levels. In both cases, a form is saved as a table of data.

1	In the Database window, click the name of the object you want to save. To save a selection of a datasheet, open the datasheet and select the portion of the datasheet before continuing.

2	On the File menu, click Save As/Export.

3	In the Save As dialog box, click To An External File Or Database, and then click OK. The Save Object Name In dialog box is displayed.

4	In the Save As Type box, click Microsoft Excel 5-7 or Rich Text Format.

5	Click the arrow to the right of the Save In box and select the drive or folder to save to.

6	In the File Name box, enter a name for the file (or use the suggested name).

7	If you are saving as Microsoft Excel 5-7, select the Save Formatted check box. If you are saving as Rich Text Format, the Save Formatted check box is selected automatically.

8	Click Export.

Note   You can also use the OutputTo action in a macro to save an object in another application's file format. When you use this action, you can specify the database object you want to output, and the object doesn't have to be open or selected in the Database window.


Attach an object's output to an electronic mail message

You can attach the output of a database object to an electronic mail message as a Microsoft Excel (.xls), rich-text format (.rtf), or MS-DOS text (.txt) file.

1	In the Database window, click the name of the object you want to attach. If you want to send a selection of a datasheet, open the datasheet and select the portion of the datasheet before continuing.

2	On the File menu, click Send.

3	Click the file format you want to attach, and then click OK.

Microsoft Access opens a new mail message and attaches the output of the object in the format you selected.

Notes

•	If the Send command isn't available, your mail application might not be properly installed, or might not support Messaging Application Programming Interface (MAPI). Check your program's documentation to confirm that it supports MAPI, and if so, try reinstalling the mail application to make the Send command available.

•	You can use the SendObject action in a macro to attach an output file to an electronic mail message. When you use this action, you can specify the database object you want to attach, and the object doesn't have to be open or selected in the Database window.


About built-in and custom toolbars

Microsoft Access provides one or more built-in toolbars for each view in all your Microsoft Access databases, such as the Form Design toolbar and Formatting toolbar in form Design view, and the Relationships toolbar in the Relationships window. It also provides the following special-purpose toolbars:

•	Utility 1 and Utility 2 toolbars for constructing your own built-in toolbars available in all your Microsoft Access databases. These aren't tied to a specific view.

•	Toolbox, which contains tools that create the various types of controls within a form or report. It is displayed by default in form or report Design view.

You can modify the built-in toolbars that Microsoft Access provides, or you can create your own custom toolbar for a specific database. Custom toolbars are especially helpful on forms and reports for which you have special requirements. For example, you may have a weekly report that you preview and print one section at a time. You can create your own set of toolbar buttons that run macros to accomplish these tasks, and place them on a custom toolbar that you show only when you're working with that report. Microsoft Access also provides a variety of built-in toolbar buttons (including those with the button images from version 2.0) that you can add to a built-in or custom toolbar, including many that are equivalent to commands on the Microsoft Access menus.


Keep color and style palettes displayed while designing a form or report

So that you don't have to click a palette's toolbar button each time you want to display the palette and make a selection from it, you can drag the palette away from the button to keep it displayed while you design the form or report.

1	In form or report Design view, click one of the following buttons on the Formatting toolbar, depending on the palette you want to use.

Click this button	To display this palette	For selecting
	BackColor	Background colors for a control or section.
	ForeColor	A font color for a control.
	BorderColor	The color of a control's border.
	BorderWidth	The thickness of a control's border.
	SpecialEffect	A flat, raised, or sunken effect for a control or section.
2	Drag the palette to the position that works best for you while designing your form or report.

You can drag any of the other palettes from the toolbar and use them with the one you already positioned.


Show or hide a toolbar

The built-in toolbar appropriate to a particular view appears by default when you switch to that view. However, you can manually show or hide any toolbar from any view.

1	Use the right mouse button to click anywhere in a toolbar's background (not on a button).

2	Click the name of a toolbar on the shortcut menu to hide or show that toolbar for the current view or to hide or show any custom toolbars.

To hide or show any toolbar, whether or not it applies to the current view, click Toolbars. In the Toolbars dialog box, select the check box next to the toolbars you want to show or hide, and then click Close.

Notes

•	When you manually show a built-in toolbar, it appears in every view. When you hide a built-in toolbar from within its default view, it's hidden in every view.

•	If your database or application has only one custom toolbar, you can show the toolbar each time your database or application starts by selecting the check box next to its name in the Toolbars dialog box. If your application has different toolbars for different forms, use the ShowToolbar method in Visual Basic for applications code or the ShowToolbar action in macros to show and hide the form’s toolbar. That way, when users switch between open forms, they always see the toolbar for the active form.

•	To show or hide all built-in toolbars by default, click Startup on the Tools menu, and then select or clear the Allow Built-in Toolbars check box.


What's new with toolbars and toolbar buttons?

To help you work more quickly and accurately in Microsoft Access for Windows 95, a variety of new buttons, such as the Format Painter and Spellchecker buttons, have been added to the built-in toolbars. You can also find a variety of new buttons in the Customize Toolbars dialog box, which you can add to toolbars. (Buttons with images from Microsoft Access version 2.0 are also still available.) Additional toolbar enhancements give you greater flexibility for customizing toolbars and toolbar buttons.

Microsoft Access for Windows 95 offers the following enhancements to toolbars and toolbar buttons:

•	A Button Editor that enables you to edit an existing button image or design a new image. Besides changing or creating the image itself, you can add or change colors or move the entire image around until it's positioned where you want on the top of the button.

•	The ability to copy and paste images from one button to another on the same toolbar or different toolbars and to use bitmaps from a source outside Microsoft Access for toolbar buttons.

•	A Formatting toolbar in form and report Design view, with buttons that enable you to customize the appearance of a form or report. This toolbar includes all the formatting choices previously available through the Palette.

•	Buttons with drop-down list boxes and portable palettes.

When you click a drop-down-style button, it sometimes displays a list of choices, such as a list of the types of queries you can switch to. In the case of the Formatting toolbar, these buttons display palettes you can use to help design a form or report. You can drag the palettes away from the toolbar buttons, and then place them anywhere in the window while you're designing a form or report.

•	The ability to enable or disable shortcut menus on toolbars. By disabling shortcut menus, you can prevent others from customizing your toolbars.


 Move toolbars to another screen location

1	Click anywhere in the toolbar's background (not on a button). On a floating toolbar, you can also click its title bar.

2	Drag the toolbar to a new location. If you want, you can dock multiple toolbars at the same edge of the Microsoft Access window.

Notes

•	You can't dock a toolbar vertically if it contains a combo box (such as the Font box) or other buttons that are wider than the standard square buttons Microsoft Access provides.

•	Double-click anywhere in a toolbar's background to toggle between its docked and floating positions.


Rename a custom toolbar you created

1	With the right mouse button, click anywhere on a toolbar.

2	Click Toolbars.

3	In the Toolbars box, select the custom toolbar you want to rename.

4	Click Rename. (If you've selected a built-in toolbar, the Rename button isn't available.)

5	Type a new name for the toolbar, and then click OK.

6	Click the Close button in the Toolbars dialog box.


Add a built-in button to a toolbar

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	In the Categories box, select any category of buttons except one starting with "All." The "All" categories are for creating custom buttons that run macros or display specific forms, reports, or other database objects.

5	Select a button, and then drag it to the toolbar on which you want it to appear. The original button remains in the Buttons box.

6	Click the Close button in the Customize Toolbars dialog box.


 Add to a toolbar a button for creating a custom control

If you frequently create a specific type of custom control, you can add that control's button to a toolbar.

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	In the Categories box, select Custom Controls.

5	Select the type of control button you want to add from the Objects list, and then drag it to the toolbar. Its name remains in the Objects list for future use.

6	Click the Close button in the Customize Toolbars dialog box.


Remove a button from a toolbar

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	With the Customize Toolbars dialog box displayed, drag the button off the toolbar to any location on the screen except another toolbar.

5	Click the Close button in the Customize Toolbars dialog box.

Important   When you remove a toolbar button that came with Microsoft Access, you've removed it from that built-in toolbar for all your Microsoft Access databases; however, the button is still available in the Customize Toolbars dialog box. When you remove a button that you created, though, the button is deleted.


Move a button on a toolbar

You can move toolbar buttons to another location on the same toolbar or to a different toolbar.

1	Switch to the appropriate view and make sure the toolbars you want to work with are displayed.

You can show a toolbar, whether or not it's specific to the current view. For example, you may want to temporarily show two different toolbars in the same window at the same time.

How?

2	With the right mouse button, click anywhere on the toolbar displaying the button you want to move.

3	Click Customize.

4	With the Customize Toolbars dialog box displayed, drag the button on the toolbar to its new location on the same toolbar, or to a different toolbar.

5	Click the Close button in the Customize Toolbars dialog box.


Assign a button to a fixed location on a horizontal toolbar

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed and docked horizontally.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	With the Customize Toolbars dialog box displayed, hold down the SHIFT key while you drag the button on the toolbar to the right.

The buttons to the right of the one you're moving shift right, maintaining their order and distance relative to the button. The button you moved will retain its fixed position on the toolbar as you add or delete buttons, or rearrange them.

5	Click the Close button in the Customize Toolbars dialog box.


Add or remove space between buttons on toolbars

You can emphasize and group buttons by adding space between them and other buttons on a toolbar.

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	To add a standard space to the left of a button, drag the button on the toolbar to the right almost half the width of the button.

To remove space to the left of a button, drag the button to the left.

5	Click the Close button in the Customize Toolbars dialog box.

Tip   With the Customize Toolbars dialog box displayed, hold down the SHIFT key while you drag a button to the right on a horizontally-docked toolbar to allow additional space between buttons and to assign the button to a fixed location on the toolbar. The button you moved will retain its fixed position on the toolbar as you add or delete buttons, or as you rearrange them.


Reset a toolbar that came with Microsoft Access to show its original buttons

Anytime after you've customized a built-in toolbar, you can return its original buttons to their original order by resetting the toolbar. Resetting also hides or shows the toolbar as it was set initially.

1	With the right mouse button, click anywhere on the toolbar.

2	Click Toolbars.

3	In the Toolbars box, select the built-in toolbar you want to reset.

4	Click the Reset button. (If you've selected a custom toolbar, the Reset button becomes a Delete button because you can't reset a toolbar that you created.)

Microsoft Access asks you to confirm that you want to reset the toolbar.

5	Click Yes.

6	Click the Close button in the Toolbars dialog box.


Create a custom toolbar for a specific database

1	Open the database in which you want to use the custom toolbar.

2	With the right mouse button, click anywhere on an existing toolbar (not on a button).

3	Click Toolbars, and then click New.

4	Type a name for the toolbar, and then click OK.

Microsoft Access displays a small floating toolbar window in the Microsoft Access window.

5	In the Toolbars dialog box, click Customize.

You complete the toolbar by adding buttons to it. For more information about how to finish or modify the toolbar, click  [image].

Notes

•	If your database or application has only one custom toolbar, you can show the toolbar each time your database or application starts by clicking Toolbars on the View menu, selecting the check box next to the name of the toolbar, and then clicking OK. If your application has different toolbars for different forms, use the ShowToolbar method in Visual Basic for applications code or the ShowToolbar action in macros to show and hide the form’s toolbar. That way, when users switch between open forms, they always see the toolbar for the active form.

•	For information on creating a toolbar that's available in all your Microsoft Access databases, click  [image].


Create a toolbar for all databases

To design a toolbar that's available in all your Microsoft Access databases, add buttons to the blank built-in toolbars Utility 1 and Utility 2.

1	Use the right mouse button to click anywhere on an existing toolbar.

2	Click Toolbars.

3	In the Toolbars box, select the Utility 1 or Utility 2 check box to show the toolbar.

4	Add buttons and otherwise modify the toolbar until it looks and works the way you want.

How?


Modify toolbars or toolbar buttons

You can modify a custom toolbar that you created or any built-in toolbar that is specific to a particular view, such as the Form Design toolbar or the Table Datasheet toolbar. When you modify a built-in toolbar, it's changed in all your Microsoft Access databases.

Microsoft Access provides two blank built-in toolbars called Utility 1 and Utility 2. You can add buttons to one or both of these to design your own built-in toolbars for use in all your Microsoft Access databases.

What do you want to do?

Add, create, or remove buttons on toolbars

Move toolbar buttons

Add or remove space between toolbar buttons

Assign a button to a fixed location on a horizontal toolbar

Work with the image displayed on a toolbar button

Change the ToolTip for a custom toolbar button

Reset a toolbar that came with Microsoft Access to show its original buttons

Rename a custom toolbar you created


Add, create, or remove buttons on toolbars

What do you want to do?

Add a built-in button to a toolbar

Add a button for creating a custom control to a toolbar

Create a toolbar button that runs a macro

Create a toolbar button that displays a form, report, or other database object

Remove a button from a toolbar


Work with the image displayed on a toolbar button

What do you want to do?

Choose an existing image or enter the text to display on the face of a toolbar button

Copy a toolbar button image to another toolbar button

Design a new toolbar button image or customize an existing image

Display a bitmap created outside Microsoft Access on a toolbar button

Restore the original button image on a toolbar that came with Microsoft Access


Create a toolbar button that runs a macro

1	Create the macro you want a button to run.

How?

2	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

Note   You usually want to add your own buttons to a custom toolbar that you create for a specific database object. When you create your own macro button for a built-in toolbar, the button appears on that toolbar in all databases. However, it only works in the database where the macro is stored.

3	With the right mouse button, click anywhere on the toolbar.

4	Click Customize.

5	In the Categories box, select the All Macros check box.

In the Objects box, Microsoft Access displays the names of all the macros in the current database (including macros within any macro groups).

6	Drag the macro you want to the toolbar.

7	Click the Close button in the Customize Toolbars dialog box.

Note   For information on customizing the image, the ToolTip, and status bar text for the new button, click  [image].


Create a toolbar button that displays a form, report, or other database object

You can create a toolbar button that displays a form, report, or other database object in its default view. For example, when you click a toolbar button that you created for a query, Microsoft Access runs the query and displays the results in Datasheet view. In the case of an action query, the button runs the query and performs the required action.

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	In the Categories box, select one of the following categories depending on the type of object you want the button to open: All Tables, All Queries, All Forms, All Reports.

5	From the Objects box, drag the name of the object you want to create a button for to the toolbar.

6	Click the Close button in the Customize Toolbars dialog box.

Notes

•	If you want the button to display the object in a different view, you must create a toolbar button that runs a macro.

•	For information on customizing the image, the ToolTip, and status bar text for the new button, click  [image].


Change the ToolTip for a custom toolbar button

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	With the right mouse button, click the button on the toolbar (not the button in the Customize Toolbars dialog box) whose ToolTip you want to change.

5	Click Choose Button Image.

6	In the Description box, type the new ToolTip you want Microsoft Access to display for the button. (This text is also displayed in the status bar.)

Note   If the description area isn't available, you clicked a built-in button, not a custom button.

7	Click OK, and then click the Close button in the Customize Toolbars dialog box.


Turn ToolTips on or off

1	Use the right mouse button to click anywhere on a toolbar.

2	Click Toolbars.

3	To turn ToolTips on, select the Show ToolTips check box.

To turn ToolTips off, clear the Show ToolTips check box.

4	Click the Close button in the Toolbars dialog box.

Notes

•	You can also turn ToolTips on or off by clicking Options on the Tools menu, clicking the View tab, and then selecting or clearing the ToolTips check box.

•	The status bar displays the same text as the ToolTip even if ToolTips are turned off.


Change the size of toolbar buttons

You can change the size of all the buttons on a toolbar at once.

1	Use the right mouse button to click anywhere on a toolbar.

2	Click Toolbars.

3	To display large buttons, select the Large Buttons check box.

To display standard-size buttons, clear the Large Buttons check box.

4	Click the Close button in the Toolbars dialog box.

Notes

•	Use the large, easy-to-read button size with video resolutions higher than VGA; otherwise, some buttons on the end of the toolbar may disappear from view. If this happens, you can drag the toolbar from its docked position to a floating position that allows you to see all the buttons at once.

•	You can also change the button size by clicking Options on the Tools menu, clicking the View tab, and then selecting or clearing the Large Toolbar Buttons check box.


Turn toolbar button colors on or off

1	Use the right mouse button to click anywhere on a toolbar.

2	Click Toolbars.

3	To turn off button color, clear the Color Buttons check box.

To turn on button color, select the Color Buttons check box.

4	Click the Close button in the Toolbars dialog box.

Note   You can also turn toolbar button colors on or off by clicking Options on the Tools menu, clicking the View tab, and then selecting or clearing the Color Buttons On Toolbars check box.


Choose an existing image or enter the text to display on the face of a toolbar button

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	With the right mouse button, click the button on the toolbar (not the button in the Customize Toolbars dialog box) whose image or description you want to change.

5	Click Choose Button Image.

6	To display text on the button face, select the Text check box, and then type the text you want to appear on the button. (You can't change the text font on a button.)

To display a new picture on the button face, click the image you want to appear on the button.

Note   If you're working with a custom button, not a built-in button, you can also change the button's description as it is to be displayed in the status bar and the ToolTips caption. Type the description in the Description box. If the Description box isn't available, you're working with a built-in button.

7	Click OK, and then click the Close button in the Customize Toolbars dialog box.


Restore the original button image on a toolbar that came with Microsoft Access

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	Use the right mouse button to click the button on the toolbar whose image you want to restore.

5	Click Reset Button Image.

6	Click the Close button in the Customize Toolbars dialog box.

Note   The Reset Button Image command isn't available for toolbar buttons you create.


Copy a toolbar button image to another toolbar button

1	Switch to the appropriate view and make sure the toolbar you want to copy from is displayed.

If you want to copy the image to a toolbar that isn't specific to the current view, show the toolbar.

How?

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	Use the right mouse button to click the button on the toolbar whose image you want to copy.

5	Click Copy Button Image.

6	Use the right mouse button to click the button on the toolbar whose image you want to replace.

7	Click Paste Button Image.

8	Click the Close button in the Customize Toolbars dialog box.

Note   Copying over a button image affects only that button, not every instance of the same button in the database.


Display a bitmap created outside Microsoft Access on a toolbar button

For best results, you should use an image that's the same size or smaller than the toolbar button. If the image is larger than the toolbar button, Microsoft Access automatically reduces it to fit on the button when you paste it. Consequently, the image may become distorted.

1	Create a new bitmap or open an existing one in another program, such as Microsoft Paint.

2	Select the image, and then cut or copy it to the Clipboard.

3	Switch to the appropriate view in Microsoft Access, and make sure the toolbar you want to copy the image to is displayed.

4	With the right mouse button, click anywhere on the toolbar.

5	Click Customize.

6	Use the right mouse button to click the button on the toolbar whose image you want to replace.

7	Click Paste Button Image.

8	Click the Close button in the Customize Toolbars dialog box.

For information about editing the image, such as adjusting its position on the face of the button, click  [image].

Note   If you switch to a different button size (turn Large buttons on or off) after pasting the image on the toolbar button, you'll temporarily lose the button image because Microsoft Access only stores the image in the size that was in effect when you pasted it. To redisplay the image, return to that original button size.


Design a new toolbar button image or customize an existing image

If the image currently displayed on a toolbar button isn't what you want, you can create a whole new image or modify the current image.

1	Switch to the appropriate view and make sure the toolbar you want to work with is displayed.

2	With the right mouse button, click anywhere on the toolbar.

3	Click Customize.

4	Use the right mouse button to click the button on the toolbar whose image you want to change.

5	Do one of the following:

•	If you want to use part of the image currently displayed on the toolbar button but make modifications to it, or if you want to start from scratch and draw an image pixel-by-pixel, go to step 6.

•	If you want to choose a different built-in button image as a starting point for creating a new image for the toolbar button, click Choose Button Image. In the Choose Button Image dialog box, click the image you want to work with, and then click OK. With the Customize Toolbars dialog box still displayed, use the right mouse button to again click the button on the toolbar.

6	Click Edit Button Image.

7	Use the options and buttons in the Button Editor dialog box to clear the image and design a new one or to alter the existing image, and then click OK.

8	Click the Close button in the Customize Toolbars dialog box.


Delete a custom toolbar

1	On the View menu, click Toolbars.

2	In the Toolbars box, select the custom toolbar that you want to delete.

3	Click Delete. (If you've selected a built-in toolbar, the Delete button becomes the Reset button because you can't delete built-in toolbars.)

Microsoft Access prompts you to confirm the deletion.

4	Click Yes.

5	Click the Close button in the Toolbars dialog box.


Troubleshoot toolbar problems

What do you need help with?

My built-in toolbars have disappeared. How do I get them back?

If I've made changes to the built-in toolbars that came with Microsoft Access, how do I return them to their original state?


How do I get my toolbars back if they've disappeared?

On the Tools menu, click Startup, and then click Allow Built-in Toolbars. Close the database, and then reopen it.


Answers to common questions

Automated answers to common questions, solutions to technical problems, and tips are available at no cost — 24 hours a day, 7 days a week — by telephoning Microsoft FastTips. For more information about FastTips information services, click  [image].


Finding information in the Microsoft Knowledge Base

To find the technical information you need in the Microsoft Knowledge Base (KB), compose a text query that includes the elements in the following table.

Enter this element	By typing, for example
Topic	shortcut bar or pie chart
Application name	office or word
Application version	7.0 (for information about Word version 7.0)
Operating system	windows 95
KB keywords	kbprint (for information about printing) KB articles about the same topic are grouped by keyword. For a list of keywords, search the KB using kbkeyword. For a list of keywords for a specific Microsoft product, search the KB using kbkeyword and product name — for example, kbkeyword and excel.
Logical operators: AND, OR, NOT	print AND (landscape NOT portrait) AND laserjet AND (iiisi OR 4si) Use AND to return articles that contain the expressions on both sides of AND. Use OR to return articles that contain the expressions on one or both sides of OR. Use NOT to exclude articles that contain the expression following NOT.
Grouping operators:  “ “ (quotation marks),  ( ) (parentheses)	(explorer OR "my computer") AND "start button" Enclose phrases longer than one word in quotation marks. Enclose an expression in parentheses to change its evaluation order — for example, to evaluate an OR expression before an AND expression. (In the absence of parentheses, AND expressions are evaluated before OR expressions.)
Tip   Some Microsoft products offer KB articles in Windows Help file format. To access a list of these Microsoft products, search the KB using the keywords kbfile and help.

For more information about how to access the Microsoft Knowledge Base, click  [image].


Connect to Microsoft technical resources

If you have a question about an Office application, first look in the Getting Results books, the Answer Wizard, or the Readme file that comes with the application. If you don't find what you need, you can get information from several Microsoft technical resources, including online support forums, the Microsoft Knowledge Base (KB), Microsoft Software Library (MSL), Microsoft Download Service (MSDL), the Microsoft TechNet and Microsoft Developer Network CD-ROMs, and Microsoft Press publications.

If you have a modem, you can automatically connect to most of these resources by clicking The Microsoft Network on the Help menu in any Office application.

Where do you want to go for technical information?

The Microsoft Network (for KB, MSL, support forums, and more)

Microsoft FastTips (for popular KB articles and recorded, faxed, or mailed technical information)

Microsoft Download Service (MSDL)

The Internet (for KB, MSL, and more)

CompuServe, America Online, and GEnie (for KB, MSL, support forums, and more)

Microsoft TechNet and Microsoft Developer Network CD-ROMs (for KB, MSL, technical white papers, and more)

Microsoft Press (for technical publications)


The Microsoft Network

If you have a modem, you can quickly connect to The Microsoft Network (MSN) from any Office application.

1	On the Help menu, click The Microsoft Network.

2	Click where you want to go on The Microsoft Network, and then click Connect.


Microsoft FastTips

Microsoft FastTips gives recorded or faxed answers in English to common technical problems. You can also order Application Notes and popular articles from the Microsoft Knowledge Base (KB) by fax or mail.

Microsoft FastTips is available 24 hours a day, 7 days a week, by calling (800) 936-4100, toll-free, from a touch-tone telephone. Using the buttons on your telephone, follow the prompts to hear recorded answers to your technical questions, obtain a catalog of available information, or order items by fax.


Microsoft Download Service

To connect to the Microsoft Download Service (MSDL) bulletin board system, use your modem to call (206) 936-6735 in the United States or (905) 507-3022 in Canada, and then follow the prompts. This service is available 24 hours a day, 7 days a week.

Note   MSDL supports 1200-, 2400-, 9600-, and 14,400-baud (V.32 and V.42) data transmission with 8 data bits, 1 stop bit, and no parity. The protocols that MSDL supports are Xmodem, Xmodem-1K, Ymodem (batch), Kermit, Super Kermit (Sliding Windows), and Zmodem.


The Internet via World Wide Web, FTP, or Gopher

You can access the Microsoft Knowledge Base (KB) and Microsoft Software Library (MSL) at any of the following three Internet sites:

•	Microsoft World Wide Web site, located at www.microsoft.com

•	Microsoft Gopher site, located at gopher.microsoft.com

•	Microsoft FTP site (which supports anonymous logon), located at ftp.microsoft.com

The KB at the World Wide Web and Gopher sites provides full-text searches and automatic links to files on the MSL so you can download files directly from KB articles.


CompuServe, America Online, and GEnie

The Microsoft Knowledge Base (KB) and Microsoft Software Library (MSL) are available on the CompuServe, America Online, and GEnie information services. CompuServe also hosts Microsoft forums where you can interact with other users and Microsoft support personnel.

CompuServe

•	To access the Microsoft Knowledge Base, type go mskb at any ! prompt.

•	To access the Microsoft Software Library, type go msl at any ! prompt.

•	To access Microsoft forums, type go microsoft at any ! prompt.

America Online

•	To access the Microsoft Knowledge Base, click Keyword on the Go To menu, type microsoft in the Enter Word(s) box, and then click Go. In the Microsoft Resource Center, click Knowledge Base.

GEnie

•	To access the Microsoft Knowledge Base, type m505 at the GEnie system prompt.


Microsoft TechNet and Microsoft Developer Network

To get the Microsoft Knowledge Base (KB), Microsoft Software Library (MSL), and other technical information on CD, you can subscribe to two different services — Microsoft TechNet and the Microsoft Developer Network (MSDN).

To subscribe to Microsoft TechNet, call (800) 344-2121. To subscribe to the MSDN, call (800) 759-5474. Both numbers are toll-free in the United States and Canada.


Microsoft Press

Microsoft Press offers a wide variety of technical publications about Microsoft products and related computer technologies. These publications include development kits, resource kits, the Step by Step and Running... series of how-to books, Field Guide reference books, programming books, and more. You can get Microsoft Press books from your local bookstore or by calling (800) MSPRESS, or (800) 677-7377.


Format a form, report, section, or selected controls using predefined formats

1	Open a form or report in Design view.

2	Do one of the following:

•	If you want to format the entire form or report, click the form selector or the report selector.

•	If you want to format an individual section, click the section selector.

•	If you want to format one or more controls, select the controls.

3	Click  [image]  on the toolbar.

4	Click one of the formats in the list.

5	If you want to specify which attributes to apply (font, color, or border), click Options.

6	Click OK.

Note   You must select the entire form or report to apply a background picture.


Use the Menu Builder to create or edit a custom menu bar

1	To start the Menu Builder, do one of the following:

•	In any window, point to Add-ins on the Tools menu, and then click Menu Builder. Click New to create a new menu bar, or select an existing custom menu bar and then click Edit. If you click Edit, go to step 3.

Note   If you select a menu bar containing actions other than AddMenu actions, the Menu Builder displays a message that the macro contains actions the Menu Builder doesn't support, and it doesn't open the macro.

•	In Design view of a form or report, display the form's or report's property sheet. Click in the MenuBar property box. If this property is set to the name of a custom menu, click the Build button to the right of the property box to edit the custom menu using the Menu Builder, and then go to step 3. If the property is blank, click the Build button to create a new menu bar using the Menu Builder.

•	On the Tools menu, click Startup, and then click the Build button next to the Menu Bar box or Shortcut Menu Bar box. If either of these boxes is set to the name of a custom menu, click the Build button to the right of the box to edit the custom menu using the Menu Builder, and then go to step 3. If the box is blank or set to (Default), click the Build button to create a new menu bar using the Menu Builder.

2	To create a new menu bar, do one of the following:

•	To create a menu bar from a template, click the template you want to use for your menu bar, and then click OK.

•	To create a menu bar from scratch, click <Empty Menu Bar>, and then go to step 4.

Tip   If you haven't used the Menu Builder before, you may want to look at a menu bar template to see what a menu bar looks like in the Menu Builder. If you use a template, you may be able to save time by manipulating the existing commands to fit your needs.

3	If you're working with a template or existing custom menu bar, select the item in the lower half of the Menu Builder dialog box whose characteristics you want to change. In the upper half of the dialog box, you can edit the information that the Menu Builder displays about the item.

4	In the Caption box, type a menu name or command name as it will appear on the menu bar. If you're working with a template or custom menu bar, the name you type replaces the name you selected in the lower half of the dialog box.

If you want to assign an access key to a menu or command, precede a letter in the menu or command name with an ampersand (&); for example, &File or I&mport.

5	If you're creating a menu bar from scratch, click Next to add the item you just typed and start the next item. If you're working with a template or custom menu bar, select the next item that you want to change in the lower half of the dialog box.

The position of a menu or command determines whether it's a menu name, command name, submenu name, or submenu command name.

•	An item that is flush left in the list box is displayed on the menu bar as a menu name.

•	An item that is indented one level is displayed on the preceding menu when the user clicks that menu name. These items can be commands on the menu, separator bars, or submenu names.

•	An item indented one level followed by items that are further indented is a submenu name. Items indented below the submenu name are commands or separator bars on that submenu.

•	An item with one hyphen (-) as its caption is displayed as a separator bar. You can use a separator bar to divide menu items into logical groups.

The following table describes how to manipulate items in the Menu Builder.

To accomplish the following	Do this
Move an item in the lower half of the dialog box up or down or change its indentation level	Select the item, and then click the appropriate arrow keys.
Insert an item above a selected item	Click Insert.
Delete a selected item	Click Delete.
Assign an action to a command	Select the command in the lower half of the dialog box (remember that commands are indented), select an action in the Action box, and then enter its arguments in the Argument(s) box. If you select the RunMacro action or RunCode action, type the message you want displayed in the status bar in the Status Bar Text box. Note  Microsoft Access uses built-in status bar text for DoMenuItem commands; you don't need to enter any text in the Status Bar Text box.
Duplicate a custom menu bar	Click Duplicate, and then enter a name for the copy of the custom menu bar.  Note   This button is available only when you're editing an existing custom menu bar.
6	When you're finished defining or editing the menu bar, click OK.

Notes

•	When you use a built-in menu bar as a template for your custom menu bar, the Menu Builder displays the Add-ins submenu name, but not the add-ins themselves. The add-ins (including custom add-ins that have been installed using the Add-in Manager) are filled in automatically when the user clicks Add-ins on the Tools menu. If you use the Menu Builder to add other commands to the Add-ins submenu (something that isn't recommended), these commands are displayed before the add-ins on the Add-ins submenu.

•	If you intend to include menu commands that run macros but haven't defined the macros yet, you can define a working menu bar anyway. Begin by creating a macro that uses the MsgBox action to display a simple message such as "Here's a menu command." Then, for any menu commands that run an undefined macro, use your MsgBox macro instead. That way, you can see the menus and commands on your menu bar before writing all the macros. After you create the macros, you can use the Menu Builder to edit the menu bar and replace the MsgBox macro with the macros you want.


Work with subreports

What do you want to do?

Move the subreport control

Size the subreport control

Change the layout of the subreport


Values used to register an add-in with the USysRegInfo table

When developing your own add-in (a wizard, builder, or menu add-in), you must set several database properties and create a USysRegInfo table in the add-in database (*.mda) so that it can be installed using the Add-in Manager. For information on what database properties to define, and how to import a sample copy of the USysRegInfo table, see Chapter 16, "Creating Wizards, Builders, and Add-ins," in Building Applications with Microsoft Access for Windows 95. After you have imported a copy of the USysRegInfo table from Wztool70.mda, define the values in the records as described in the following sections.

Creating the first record

Creating the Registry key   The value in the Subkey field defines the names of the subkeys that will be created in the Windows Registry to register the add-in. This value must be the same for all records in the USysRegInfo table. The format of this entry depends on the kind of add-in you're installing. No matter what kind of add-in you're installing, for the first record, the value in the Type field must be 0 (which means "add this key"), and the ValName and Value fields must be left blank. The beginning of the Subkey entry can be either HKEY_CURRENT_ACCESS_PROFILE or HKEY_LOCAL_MACHINE. If you use HKEY_CURRENT_ACCESS_PROFILE and the installation is using a user profile (an alternate set of Registry keys that is invoked when Microsoft Access is started with the /Profile command-line option) the Add-in Manager will add the keys and values required to register the add-in in the user profile. If you use HKEY_CURRENT_ACCESS_PROFILE and a user profile is not in use, the Add-in Manager will add the keys and values required to register the add-in in the appropriate key below HKEY_LOCAL_MACHINE. If you use HKEY_LOCAL_MACHINE, the keys and values to register the add-in will always be added below HKEY_LOCAL_MACHINE.

Subkey format for control wizards, OLE custom control wizards, or builders   A control wizard is invoked from the toolbox when you click one of the control tools while designing a form or report. An OLE custom control wizard is invoked when you add an OLE custom control by clicking Custom Control on the Insert menu. A builder is invoked when you click the Build button next to a property box. To register a control wizard, OLE custom control wizard, or builder, the format for the Subkey field is:

HKEY_CURRENT_ACCESS_PROFILE\Wizards\WizardType\WizardSubType\WizardName

The first part can be either HKEY_CURRENT_ACCESS_PROFILE or HKEY_LOCAL_MACHINE, as described earlier. The second part must be Wizards. Assuming there is no user profile in use, this will cause the Add-in Manager to write the keys and values to register the wizard or builder in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Wizards. WizardType defines whether the add-in is a control wizard, or a builder (called a Property Wizard in the Registry). OLE custom control wizards are registered as control wizards. WizardSubType defines the specific type of wizard. WizardName is the name of the key where the values to register the wizard or builder will be added. Note that WizardName must follow the Microsoft Access object-naming rules. The following table describes the possible values for WizardType and WizardSubType.

WizardType	WizardSubType
Control Wizards	For control wizards, the value of WizardSubType is the name of the control in the toolbox that you want to associate your wizard with. The names of the controls are: Label, TextBox, OptionGroup, ToggleButton, OptionButton, CheckBox, ComboBox, ListBox, CommandButton, Image, UnboundObjectFrame, BoundObjectFrame, PageBreak, SubformSubreport, Line, Rectangle For OLE custom control wizards, the value of WizardSubType is the value for the Class property of the OLE custom control. To see this value, open a form or report in Design view, use the right mouse button to click the OLE custom control, click Properties, and then read the value in the Class box. For example, DBOutl.DataOutline is the value of the Class property for the Microsoft Data Outline Control 1.1 included with Microsoft Access.
Property Wizards	The name of the property that you want the builder to be associated with. This must be the name of the property with no spaces. For example, the names entered for standard Microsoft Access builders are: BackColor, BorderColor, FieldName, ForeColor, InputMask, LinkChildFields, LinkMasterFields, MenuBar, ODBCConnectStr, Picture, ShortcutMenuBar
Subkey format for object wizards   An object wizard is used to create a table, query, form, or report. An object wizard is invoked by clicking its name in the corresponding New Object dialog box. When you are registering an object wizard, the format for the Subkey field is:

HKEY_CURRENT_ACCESS_PROFILE\Wizards\WizardType\WizardName

The first part can be either HKEY_CURRENT_ACCESS_PROFILE or HKEY_LOCAL_MACHINE, as described earlier. The second part must be Wizards. Assuming there is no user profile in use, this will cause the Add-in Manager to write the keys and values to register the wizard in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Wizards. WizardType defines what kind of object wizard is being installed. WizardName is the name that displays in the corresponding New Object dialog box and is also the name of the key where the values to register the wizard will be added. The following table describes the possible values for WizardType and WizardName.

WizardType	WizardName
Form Wizards	User-defined. The name you enter will be displayed in the New Form dialog box. For example, the names entered for standard Microsoft Access form wizards are: AutoForm: Columnar; AutoForm: Datasheet; AutoForm: Tabular; Chart Wizard; Form Wizard; PivotTable Wizard
Query Wizards	User-defined. The name you enter will be displayed in the New Query dialog box. For example, the names entered for standard Microsoft Access query wizards are: Crosstab Query Wizard, Find Duplicates Query Wizard, Find Unmatched Query Wizard, Simple Query Wizard
Report Wizards	User-defined. The name you enter will be displayed in the New Report dialog box. For example, the names entered for standard Microsoft Access report wizards are: AutoReport: Columnar; AutoReport: Tabular; Chart Wizard; Label Wizard; Report Wizard
Table Wizards	User-defined. The name you enter will be displayed in the New Table dialog box. For example, the name entered for the standard Microsoft Access table wizard is: Table Wizard
Subkey format for menu add-ins   A menu add-in is invoked by clicking its name on the Add-ins submenu of the Tools menu.

HKEY_CURRENT_ACCESS_PROFILE\Menu Add-Ins\MenuAddInName

The first part can be either HKEY_CURRENT_ACCESS_PROFILE or HKEY_LOCAL_MACHINE, as described earlier. The second part must be Menu Add-Ins. Assuming there is no user profile in use, this will cause the Add-in Manager to write the keys and values to register the menu add-in in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Access\7.0\Menu Add-Ins. MenuAddInName defines the name that displays on the Add-ins submenu and is also the name of the key where the values to register the add-in will be added. To define an access key for the menu add-in so that you can use the keyboard to choose the menu add-in, type an ampersand (&) before the letter that you want to be the access key.

Creating the second and subsequent records

Adding records to create values   The first record in the USysRegInfo table creates a key or keys used to register your add-in. Each record following the first record defines a value added to the last key in the subtree. The value in the Subkey field must be the same as the entry for the first record. The value in the Type field defines the type of the value created in the Registry: 1 to create a String (REG_SZ in Windows NT) or 4 to create a DWORD (REG_DWORD in Windows NT). The value in the ValName field defines the name of the value. The value in the Value field defines the value itself. The number of records you need to add depends on the type of add-in you are registering. The following tables define the records you need to add for each type of add-in.

Records required to define values for control wizards, builders, or OLE custom control wizards

Type	ValName	Value
4	Can Edit	Defines if a wizard or builder can be used to modify an existing control or property of the same type. 1=Yes, 0=No.
1	Description	User-defined. If more than one wizard has been defined for a control, or more than one builder has been defined for a property, this string will display in the Choose Builder dialog box to allow users to select which wizard or builder to use.
1	Function	The function used to start the wizard or builder.
1	Library	Defines the path and name of the add-in database: |ACCDIR\MyAddInDb.mda The first part is always the same. The Add-in Manager will substitute the path to the folder where Microsoft Access is installed.
Records to define values for object wizards

Type	ValName	Value
1	Bitmap	Defines the path to the bitmap (.bmp) that is displayed above the description on the left side of the New Object dialog box when the wizard is selected.
4	Datasource Required	Enter this record for form and report wizards only. Defines whether the user must choose a table or query from the Choose The Table Or Query Where The Object's Data Comes From box in the New Object dialog box before running the wizard. 1=Yes, 0=No.
1	Description	User-defined. Defines the text that is displayed on the left side of the New Object dialog box when the wizard is selected.
1	Function	The function used to start the wizard or builder.
4	Index	Defines the order in which the wizard is displayed in the list in the New Object dialog box, where 0 is the first item in the list.
1	Library	Defines the path and name of the add-in database: |ACCDIR\MyAddInDb.mda The first part is always the same. The Add-in Manager will substitute the path to the folder where Microsoft Access is installed.
Records to define values for menu add-ins

Type	ValName	Value
1	Expression	The function used to start the wizard or builder formatted as an expression: =MyAddIn_Entry()
1	Library	Defines the path and name of the add-in database: |ACCDIR\MyAddInDb.mda The first part is always the same. The Add-in Manager will substitute the path to the folder where Microsoft Access is installed.


Help topic not available

The Help topic cannot be displayed, either because you chose Typical when you installed Microsoft Access, which doesn't install the complete set of Language Reference Help files, or because the file can't be found. To use the complete set of Language Reference Help files, you must rerun the Setup program to install the missing files.

To install Language Reference Help if you have Microsoft Office Pro for Windows 95

1	Run Microsoft Office Pro for Windows 95 Setup, and click Add/Remove.

2	Click Microsoft Access, and then click Change Option.

3	Click Help Topics, and then click OK.

4	Click Continue, and follow the instructions in the remaining Setup dialog boxes.

To install Language Reference Help if you only have Microsoft Access for Windows 95

1	Run Microsoft Access for Windows 95 Setup, and click Add/Remove.

2	Click Help Topics, and then click Continue.


Visual introduction to Microsoft Access

Which area of the product would you like to find out about?

What is a database?

Tables: What they are and how they work

Customizing a table

Working in table Datasheet view

Queries: What they are and how they work

Customizing a query

Working in query Datasheet view

Forms: What they are and how they work

Customizing a form

Working in Form view

Reports: What they are and how they work

Customizing a report

Macros: What they are and how they work

Modules: What they are and how they work