Features of the Orders Sample Application

Northwind Traders sales representatives use the Orders application to enter new orders and print invoices. For information on the application-building techniques used in the Orders application, choose from the following topics:

Control how an application starts by setting Startup options.

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

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

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

Filter and sort data on a form.

For examples of most of these techniques, see Chapter 3, "Using Forms to Collect, Display, and Filter Information," in Building Applications with Microsoft Access for Windows 95.

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 opens.

To show the Database window, click  [image]  on the toolbar or press F11.

To work with existing orders on the Orders form instead of entering new data, click the Filter Orders button on the toolbar, and then click  [image]  (or click Remove Filter/Sort on the Records menu).

To close the Show Me Help topic, click  [image]  in the upper-right corner of the Help window. You can display the Show Me Help topic again by clicking the Show Me button on the Orders form toolbar.

Other Features of the Orders Sample Application

In addition to illustrating techniques you can use to create database applications, the Orders sample application provides tools that can help make application development easier.

The UtilityFunctions module contains several custom Visual Basic functions that automate common tasks, such as:

Determining whether a record is locked.

Determining whether a specified form is open.

Converting the first letter of each word in a string to uppercase.

Returning the first day of the month following the specified month.

Resetting DisplayStartupForm, a custom database property that determines whether the Startup form is displayed.

The ShowEvents form is a special version of the Orders form that records the events that occur while you work with the form. The EventHistory form lists the events in the order they occur.


Control How an Application Starts

You can control how your application looks and behaves when it starts by setting Startup options or by using event procedures.

Setting Startup Options

To set Startup options, click Startup on the Tools menu and then enter option settings in the Startup dialog box. The Orders application uses Startup options to:

Open a startup form.

Display the custom title in the application's title bar.

Hide the Database window.

Tip   To show the Database window, click  [image]  on the toolbar or press F11.

Using Event Procedures for Startup Operations

You can perform additional operations at startup, including changing the settings of Startup options, by using event procedures. The Orders application uses event procedures to:

Check and refresh links to external tables. The Startup form's Form_Load event procedure calls the CheckLinks and RelinkTables functions in the RefreshTableLinks module to check and refresh links to tables in the Northwind sample database.

Give users the option to not display the Startup form again. When a user clicks the OK command button on the form, the button's OK_Click event procedure checks whether the check box is selected. If it is, the event procedure changes a custom database property so that the application displays the Orders form rather than the Startup form at startup.

Note   If you turn off the Startup form, you won't be able to display it in Form view. You can view it again by running the ShowStartup Sub procedure in the UtilityFunctions module.

For more information on the following subjects, see Building Applications with Microsoft Access for Windows 95.

Subject	Chapter	Section
Setting Startup options	Chapter 1, "Creating an Application"	"Setting Startup Options"
Using event procedures	Chapter 2, "Introducing Visual Basic"	"Creating Your First Event Procedure"


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 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 OrdersMenuBar, 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 method 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, the Orders form displays a custom error message. An event procedure for the form's Error event defines the error message.

For more information on the following subjects, see Building Applications with Microsoft Access for Windows 95.

Subject	Chapter	Section
Creating and attaching a custom menu bar	Chapter 1, "Creating an Application"	"Creating a Menu Bar"
Creating and attaching a custom toolbar	Chapter 1	"Using Custom Toolbars in Your Application"
Assigning shortcut keys	Chapter 1	"Making Key Assignments"
Displaying custom error messages	Chapter 8, "Handling Run-Time Errors"	"Using Error Events"


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 ProductsPopup form, which displays details about the product in the current record of the subform. The event procedure for the button's Click event uses the OpenForm method to open the form and refers to the ProductID control on the subform to display the correct record.

The Print Invoice button on the toolbar of the Orders form opens the PrintInvoiceDialog 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 OrderID 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 PrintInvoiceDialog form includes Preview and Print buttons the user can use to preview or print the invoice for the selected order. The event procedures for the buttons' Click events use the OpenReport method to open the report, refer to the OrderID 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 method to close the ProductsPopup form if it's open. The event procedure for the Close event of the Invoice report uses the Close method to close the PrintInvoiceDialog form.

For more information on the following subjects, see Building Applications with Microsoft Access for Windows 95.

Subject	Chapter	Section
Referring to controls and properties	Chapter 1, "Creating an Application"	"Referring to Objects and Their Values"
	Chapter 3, "Using Forms to Collect, Display, and Filter Information"	"Example: Customizing a Command Button that Opens a Form"; "Example: Disabling a Command Button at Run Time"
Using pop-up forms to display information	Chapter 3	"Using Pop-up Forms and Dialog Boxes"
Using dialog boxes to collect information from the user	Chapter 3	"Using a Custom Dialog Box to Collect Information"


Customize Controls

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

The Details command button (with the caption See Product Details) on the Orders form 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 OrdersSubform form's Current event sets the Enabled property of the command button based on whether there's a value in the ProductID control on the subform.

The ControlSource property of the BillingDate control on the Orders form is set to the value returned by the FirstOfNextMonth function in the UtilityFunctions module. This function uses the value in the OrderDate control to calculate the date of the first day of the month following the order date.

AutoLookup or assignment statements fill other controls with values. 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 BillTo combo box (the first control on the form) fill in the controls that show the customer's shipping address.

When entering the first order for a new customer, the user can choose to automatically add the customer to the list in the BillTo combo box. 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, adding the new customer to the list.

When a user selects a product in the OrdersSubform form, the product's UnitPrice field is automatically filled in. The event procedure for the ProductID control's AfterUpdate event uses the DLookup function to assign the value of the UnitPrice field in the Products table to the UnitPrice field in the subform.

For more information on the following subjects, see Building Applications with Microsoft Access for Windows 95.

Subject	Chapter	Section
Enabling and disabling controls	Chapter 3, "Using Forms to Collect, Display, and Filter Information"	"Example: Disabling a Command Button at Run Time"
Writing a function to perform a calculation	Chapter 2, "Introducing Visual Basic"	"Creating Your First Function"
Filling controls with values	Chapter 3	"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	Chapter 3	"Adding a Row to a Combo Box List"


Filter and Sort Data

You can make it easy for users to filter and sort data in an application and to keep related forms synchronized by using the Filter By Form window, the Filter and ApplyFilter events, and the Filter property. In the Orders application:

The Filter Orders button on the toolbar of the Orders form switches the form to its Filter By Form window, where users can enter or select criteria to specify the records they want to see.

The event procedure for the form's Filter event disables fields on the form that aren't appropriate for filtering.

The event procedure for the form's ApplyFilter event resets the disabled fields when the filter is applied.

The event procedures for the Current event of the OrdersSubform form and the AfterUpdate event of the ProductID combo box keep the OrdersSubform form and the ProductsPopup form synchronized by setting the Filter property of the ProductsPopup form.

For more information on the following subjects, see Building Applications with Microsoft Access for Windows 95.

Subject	Chapter	Section
Filtering and sorting data on a form	Chapter 3, "Using Forms to Collect, Display, and Filter Information"	"Filtering and Sorting Data in Forms and Reports"