Features of the Orders Application

The sample Orders application enables Northwind Traders sales representatives to enter new orders and print invoices.  To find out about application-building techniques used in the Orders application, choose from the following topics:

Controlling how the application starts with an AutoExec macro.

Customizing the user interface with menu bars, toolbars, shortcut keys, and custom error messages.

Tying objects together with forms that open and close other forms and reports.

Customizing controls on a form by assigning values to the controls and their properties and by adding rows to a combo box.

Controlling the tab order on a form.

Most of these techniques are explained in the examples in Part 1, "Connecting the Dots," of Microsoft Access Building Applications.

Tips for Using the Orders Application

When you start the Orders application, the Database window is hidden, the Orders form opens for data entry, and the Show Me help window is opened.

To show the Database window, press the F11 key (or choose Unhide from the Window menu).

To work with existing orders on the Orders form, press the Show All Records button in the toolbar (or choose Show All Records from the Records menu).

To close Show Me, choose Close from the Show Me window's File menu.  You can display Show Me again by pressing the Show Me button on the Orders form toolbar or by pressing F1 in any form or report.


Control How the Application Starts

To control how an application starts, create a macro named AutoExec, and add the actions you want to occur when the user starts the application.  In the Orders application, the AutoExec macro:

Checks and refreshes attachments to external tables using the AreTablesAttached function in the Reattach NWIND module.

Hides the Database window using a DoMenuItem action that runs the Hide command on the Window menu in the Database window.

Tip   To show the Database window, press the F11 key (or choose Unhide from the Windows menu.)

Opens the Orders form for data entry using an OpenForm action.

For information on	See	Section or example
Creating an AutoExec macro	Building Applications, Chapter 2	"Starting Your Application Using the AutoExec Macro"
Attaching to tables in a separate database	Building Applications, Chapter 1	"Separating Your Application's Tables from Its Other Objects"
Using Access Basic to check and refresh attachments	Solutions sample application	In the upper part of the Solutions form, double-click Use multiple databases; in the lower part of the form, double-click Attach tables at startup


Customize the User Interface

You can customize an application's user interface by creating and attaching custom menu bars to forms and reports, attaching custom toolbars, assigning actions to shortcut keys, and replacing the Microsoft Access error messages with your own.  In the Orders application:

The Orders form has a custom menu bar and toolbar.  The MenuBar property of the form is set to Orders Menu Bar, the name of the menu bar macro that defines the custom menu bar.  Event procedures for the form's Activate and Deactivate events use the ShowToolbar action to show and hide the toolbar.

The key combination Ctrl+R runs a macro that prints the current record on a form.  A macro named AutoKeys defines the key combination.

If a user tries to save an order without specifying the customer, salesperson, or Order ID, the Orders form displays custom error messages.  An event procedure for the Error event of the form defines the error messages.

For information on	See	Section or example
Creating and attaching a custom menu bar	Building Applications, Chapter 2	"Creating a Menu Bar"
Creating a custom toolbar	User's Guide, Appendix B	"Creating Custom Toolbars"
Attaching a custom toolbar to a form	Building Applications, Chapter 2	"Using Custom Toolbars in Your Application"
Assigning shortcut keys	Building Applications, Chapter 2	"Making Key Assignments"
Displaying custom error messages	Building Applications, Chapter 10


Tie Objects Together

You can tie objects together in an application by opening or closing a form or a report in response to an event on a form.  In the Orders application:

The Details command button (with the caption, See Product Details) on the Orders form opens the Products Pop-Up form, a pop-up form that displays details about the product in the current record of the subform.  The event procedure for the button's Click event uses an OpenForm action to open the form and refers to the Product ID control on the subform to display the correct record.

The Print Invoice button on the toolbar of the Orders form opens the Print Invoice Dialog form.  The button is attached to a macro that uses an OpenForm action to open the Print Invoice dialog box.  The OpenForm action refers to the Order ID control on the Orders form so that the invoice for the current order on the Orders form is automatically selected in the dialog box.

The Print Invoice dialog box includes Preview and Print command buttons the user can use to preview or print the invoice for the selected order.  The event procedures for the buttons' Click events use OpenReport actions to open the report, refer to the Order ID control in the dialog box, and preview or print the correct invoice.

The event procedure for the Close event of the Orders form uses the Close action to close the Products Pop-Up form if it's open.  The event procedure for the Close event of the Invoice report uses the Close action to close the Print Invoice dialog box.

For information on	See	Section or example
Referring to controls and properties	Building Applications, Chapter 1 Building Applications, Chapter 4	"Referring to Objects and Their Values" "Example: Customizing a Command Button that Opens a Form"; "Example: Disabling a Command Button at Run Time"
Using pop-up forms to display information	Building Applications, Chapter 4	"Using Pop-Up Forms and Dialog Boxes"
Using dialog boxes to collect information from the user	Building Applications, Chapter 4	"Using a Custom Dialog Box to Collect Information"


Customize Controls

You can use a variety of approaches to customize how controls on your form work.  In the Orders application:

The Details command button (with the caption, See Product Details) is enabled when there's a product in the current record of the subform and disabled when there isn't.  The event procedure for the subform's Current event sets the Enabled property of the command button based on whether there's a value in the Product ID control on the subform.

The DefaultValue property of the Billing Date control is set to the value returned by the FirstOfNextMonth function in the Utilities module.  This function uses the value in the Order Date control to calculate the date of the the first day of the month following the order date.

Values are filled in other controls using AutoLookup or assignment statements.  AutoLookup fills in the controls that show the customer's billing address and contact information.  Assignment statements in the event procedure for the AfterUpdate event of the Bill To combo box (the first control on the form) fill in the controls that show the customer's shipping address.

The user can add a new customer while adding the customer's first order, and the new customer is automatically added to the Bill To combo box list.  The event procedure for the combo box's NotInList event enables the user to add the customer.  The event procedure for the form's AfterUpdate event requeries the combo box so that the new customer is added to the list.

For information on	See	Section or example
Enabling and disabling controls	Building Applications, Chapter 4	"Example: Disabling a Command Button at Run Time"
Writing a function to perform a calculation	Building Applications, Chapter 3	"Creating Your First Function"
Filling controls with values	Building Applications, Chapter 4	"Example: Assigning Values to Controls on the Orders Form" "Example: Using AutoLookup to Fill In Customer Information on the Orders Form"
Adding a row to a combo box list	Building Applications, Chapter 4	"Adding a Row to a Combo Box List"


Control Tab Order

To control the tab order on a form, you use the TabStop and TabIndex properties of controls on the form.  You can also use a transparent command button that sets the focus to a particular control when the user tabs to it.   In the Orders sample application:

The Details command button (with the caption, See Product Details) shouldn't be in the form's tab order, so the command button' s TabStop property is set to No.  This removes it from the tab order.  The user can still choose the command button by pressing its access key or by clicking it.

Users shouldn' t be able to inadvertently tab out of the current record by pressing Tab in the Freight control (the last control in the tab order) or Shift+Tab in the Bill To combo box (the first control in the tab order).  Transparent command buttons at the beginning and end of the form's tab order set the focus back to these controls.

Note   The transparent command buttons are behind the controls they set the focus to.  To work with one of the buttons in Design view, select the control it sets the focus to, and then choose Send To Back from the Format menu.  Then you can select the command button.

Users don't usually need to fill in the customer billing information so these controls are not in the regular tab order.  However, when users add a new customer or edit customer information, they should be able to tab through these controls to the Ship Name control.  Transparent command buttons before and after the customer information controls set the focus appropriately when the user clicks in these controls and then tabs through them.

For information on	See	Section or example
Preventing users from automatically moving to another record	Solutions sample application	In the upper part of the Solutions form, double-click Sample Forms; in the lower part of the form, double-click Edit Products


Use Transparent Command Buttons to Set Focus

On a form that contains a large, complicated record, you might want to prevent users from inadvertently tabbing out of the current record before it's complete. On the Orders form, you can't leave the current record by pressing Tab from the Freight control (the last control on the form that gets the focus) or Shift+Tab from the Bill To combo box (the first control on the form). In addition, the tab order normally skips the customer information controls, but if users click in these controls, they can tab through them to the Ship Name control.

Overview

Create four transparent command buttons, and place them in the tab order of the form like this: one in front of the Bill To combo box, one after the Freight control, one in front of Customer ID (the first customer information control), and one after Fax (the last customer information control). Use an event procedure for the OnEnter property of each command button that uses the SetFocus method to move the focus to the appropriate control. To prevent users from clicking the command buttons, place each one behind the control it sets the focus to.

Step by Step

1	Create two command buttons, one named Go To Freight and the other named Go To Bill To.  Set their Transparent properties to Yes.  Put the Go To Freight command button after the Freight control in the tab order.  Put the Go To Bill To command button at the beginning of the tab order, before Bill To.

2	Write an event procedure for the Enter event of each command button. The event procedure sets the focus back to the control that the user just tabbed out of.  This is the event procedure for the Go To Freight command button:

Sub Go_To_Freight_Enter ()

[Freight].SetFocus

End Sub

3	Place the customer billing information controls at the end of the tab order, after the Go To Freight control.  Because the Go_To_Freight_Enter event procedure sets the focus back to the Freight control, the customer information controls don' t get the focus unless the user clicks in them or your code sets the focus to them.

4	Create a command button named Go To Ship Name, and place it in the tab order after the Fax control (the last customer information control).  Set its Transparent property to Yes, and write an event procedure for its Enter event that uses the SetFocus method to set the focus to the Ship Name control.

5	Create a command button named Go To Customer ID, and place it in the tab order before the Customer ID control (the first customer information control).  Set its Transparent property to Yes, and write an event procedure for its Enter event that uses the SetFocus method to set the focus back to the Customer ID control.  When the user presses Shift+Tab in the Customer ID control, the focus stays on that control.

6	Place each transparent command button behind the control it sets the focus to.  To do that, position the command button directly on top of the other control, and then choose Send to Back from the Format menu.

This prevents users from inadvertently clicking the button, which is especially important if the control the button sets the focus to is sometimes disabled (your code can't set the focus to a disabled control). To work with the button in Design view, select the control it sets the focus to, and choose Send to Back from the Format menu.  Then you can select the command button.  After you finish working with the button, be sure to select it and choose Send To Back from the Format menu so that it's behind the other control again.


  Show All Records button

A button on the toolbar you click to display all records in the underlying table or query.  Clicking this button removes any filter that was previously applied.