Field Rules

Description

An Alpha Anywhere User Guide to the Desktop.

Name
Description
Add Fields to List Dialog Box

Procedure for adding fields to a list dialog box.

Alpha Anywhere Basics

Alpha Anywhere is a feature-filled database and application development tool for Windows that lets you track, report, and manage information. Alpha Anywhere is compatible with the versions of these operating systems that display 8 bit character sets. Alpha Anywhere is easy to learn because it is menu-driven. The menus are self-explanatory; novice and expert alike can quickly make use of Alpha Anywhere's many features.

Automatic Backup and Revision Control of Layouts and Field Rules

Every time you make an edit to any Form, Label, Letter, Report, Browse or Field Rule, Alpha Anywhere automatically make a backup of the object you editing. You can roll back to any previous version of your layout, or Field Rule definition that you want. This means that it is now virtually impossible to lose work because of a file corruption. And it lets you experiment with your layouts more freely because if you make a design change you don't like, its easy to revert back to a pervious version. To restore a prior version of a Layout, right click on the Layout and select the 'Restore Prior Version' command.

Automatically Populating Linking Field Values when Doing Data Entry

The following scenario describes a situation in which you want to automatically populate "linking" fields in a grid component menus. Assume that you have an application with the following characteristics:

Calculated Fields

Alpha Anywhere supports two similar capabilities:

Calculated Values

Alpha Anywhere calculates a calculated value when it is based on one or more fields in a table and you change or enter a record. You may define a calculated field for a:

Changing the Case of Words

Transformation Rules automatically change entries to uppercase or lowercase, and define shortcut abbreviations for entering commonly used words and phrases.

Coded Fields

Alpha Anywhere supports Coded Fields, a field that displays one value but internally stores another value. For example, a product_id field might store "X123" internally, but display "Alpha Five V5" on Forms, Reports, etc. To define a coded field, you perform the following steps:

Controlling a Field's Width

Default Behavior, Using "Nowrap", and Using a TextBox.

Copy Previous Field

The Copy Previous Field action copies the value for the corresponding field in the previous record. For repetitive data entry, this action is handy when there are duplicate fields. For example, entering records for multiple people at the same company, might involve the same address repeatedly. This action lets the user easily copy the information.

Creating a Field Rule Event

Events are pre-named Alpha Anywhere actions that are associated with certain Alpha Anywhere components. For example, clicking on a button on a form initiates an event called OnPush. When you click on a field, form or browse, a series of events happen. This series includes the OnArrive event for the field you clicked on, and the OnDepart event for the field you left. Alpha Five lets you attach Xbasic code that executes when specific events like these occur.

Creating a Posting Field Rule

During data entry, you can post values in the current field to matching records in a second table, thus adding to, subtracting from, or replacing the value in a second table.

Creating a Simple List

If you want to provide a pre-defined list of choices for a field, use a Simple List lookup. For example, in the AlphaSports Invoices set, the Pay_Method field is defined as a Simple List lookup with the choices: "Credit", "Cash", and "Check". You can select any of these values instead of typing them in.

Creating and Using a Summary Field

The Summary Genie assists you in creating calculated fields that summarize various aspects of a field over a group of records or over the whole table. The Summary Genie will summarize over the child records for a given parent record if you select a field or expression based on a child record. It will summarize over the whole table if you select a field or expression based on a parent record. The following functions are supported:

Creating and Using an Email Smart Field

Email0 is an Alpha Anywhere Email Smart Field. It provides a convenient method of inputting, editing, and using an email address. Email0 combines a Type-In control and a button. Clicking the 'moving letter' button displays the Send Email dialog box and copies the contents of Email0 the To field of the new email message in the Alpha Anywhere internal email client.

Creating and Using Calculated Values

Use calculated values to automatically calculated a number, character string, or any other variable type when you enter or change data. The developer may manually enter the expression that calculates a value or use the Expression Builder. The operator cannot enter or change data in a calculated value.

Data Field Control Properties

Properties are available for all form controls that are bound to a table field, variable, or a calculated value. Examples include:

Default Values

Use Default mode field rule to fill a field in a new record with a default value.

Defaulting a Date Field to Today's Date

Frequently, you will want to assign today's date as a default value to a field. There are two ways to do this using field rules.

Define a View Query

This procedure is part of the procedure for building a grid component. A view is similar to an Alpha Anywhere set or SQL join. It combines selected fields from two or more tables that are linked in one-to-one or one-to-many relationships.

Dial Phone Number in Field

The Dial Phone Number in Field action dials a phone number from a field in an open form or browse window using Alpha Anywhere's phone dialer.

Display Help Topic

The Display Help Topic action opens a help file (Windows .HLP or .CHM formats or an Alpha Anywhere help file) to display a topic to the user.

Exporting Fields from a Table

Exporting plain text with a Xbasic script and exporting plain text with an action script.

Expression Builder

Whenever you want to enter an expression, clicking the 'xy' icon you displays the Expression Builder. The Expression Builder provides access to all the inputs required to build any type of expression. This includes...

F1 Context Sensitive Help

You can define context sensitive Help for any object on a form or for the form itself. If the user gives focus to a field for which custom Help has been defined, and then presses F1, the custom Help for that object is displayed. However, if no custom Help has been defined at the object level, then the custom Help defined at the form level will be shown. Also, if no object on the form has focus, pressing F1 will bring up the form's Help.

Field Rule Field Events

When defining field rules for a table, there are two types of field rule events to which a script can be attached: Field events and Record events.

Field Rule Record Events

When defining field rules for a table, there are two types of field rule events to which a script can be attached: Field events and Record events.

Field Rules

Field rules govern how data can be entered into a database, and help to ensure that data entry is accurate, consistent, and complete. Using Field Rules, you describe the data that will be entered. Field rules apply to tables, not to sets.

Field Rules Table Lookups

The value of using field rules to populate a list is that the rules are associated with the data, and consequently, the rules automatically influence the way a form or browse displays the data. The following screen shot shows the Table Lookup form with type-in controls which display lists based on the Vendor and Product tables. These controls provide two operating modes:

Field Rules: Field Types

Topics include: Extended Field Types, User-Entered Fields, Calculated Fields, Auto-Increment Fields, Examples of Auto-increment Fields, Default Descriptive Name, Field Description, Deleting a Calculated Field

Filtering Records to Exclude a Single Field Value

This demonstration of Action Scripting adds a button to the Edit_Customer_Info form. This script will restrict all the records that the form displays to those where "MA" is not the value in the Bill_State_Region field.

Find Tables that Contain a Field Name

This utility displays the Table Finder dialog. Use this dialog to find tables that contain named fields.

Form Level Field Rules

Alpha Anywhere has always allowed you to define Field Rules for the fields in a table. Now, you can also define Field Rules at the Form Layout level. When you define Field Rules at the Form level, you can define rules for both fields and variables. Contrast this with Field Rules defined at the Table level - this only allows Field Rules for fields, not variables.

Auto-Increment Fields

If there are NO records in the table, the initial value in the field (the so called 'seed' value) can be set by specifying a " default value " field rule and setting the " set value at start of data entry ". If there are existing records in the table, then when the user starts to enter a new record, Alpha Anywhere shows a "likely" value for the auto-increment field. This "likely" value is the previous high value in the field plus one. The user if free to change this "likely" value as long as he enters a number that is higher than any existing value. If the user breaks the sequence and enters a higher value than the likely value, then the sequence for all subsequent records starts with the value entered by the user. The user can never change the value in a previously saved record.

Improvements V9

Improvements that were made during Alpha Five V9 by category.

List Box Table Lookup

The List Box tab of the Table Lookups form contains two list boxes.

Mask Style

A mask is a specified pattern to which data must conform to be accepted, making data entry faster and more accurate. Use masks to validate and format data as it is entered into character fields. Masks are especially helpful when entering various types of codes or identification numbers such as telephone numbers, social security numbers, and invoice numbers into character fields. For example, if you track sales slips that always begin with a letter followed by three numbers, you might use the mask a### to ensure all entries start with a lowercase letter followed by three numbers.

Microsoft Word Integration

While Alpha Anywhere offers a powerful letter writer for creating mail merge Letters, in some instances, you might prefer to generate mail merge Letters using Microsoft Word.

Modifying a Form Field on the onchange Event

One of the most common requirements that developers have is to examine a field value and then, if certain requirements are met, change its value before it gets written. Many such operations are possible with field rules, but sometimes an Xbasic script is more flexible.

Multi Field Quick Filter Dialog Box

Check the boxes to the left of the fields you want to use in the filter.

Override Field Definitions Dialog

The Override Field Definitions dialog allows you to redefine the field characteristics of a table that is going to be created by importing a table from a SQL back-end database. You may open the Override Field Definitions dialog from the Specify Table Name dialog.

Overview of Field Rules

Alpha Anywhere offers great flexibility for controlling data entry in your database. You can create Field Rules to govern how you enter data in a table or set, and help ensure that data entry is accurate, consistent, and complete. You use Field Rules to control the information that you can enter in a field.

Parent-Child Dialog Example

Adding fields from a child table (such as InvoiceItems as children of InvoiceHeader) introduces some complications in the database insertion logic. Our Genies handle these in a graphical way, but you can write the code yourself if you wish. First, you'll want to save the parent record, and get the record ID (primary key) if it was automatically generated. Then, you'll want to save each child record along with the record ID of the parent record as a foreign key.

Placing a Calculated Value on a Form

This example shows how to place a calculated value on a form. The example is based on the invoice_items table of the AlphaSports sample database.

Placing a Data Field on a Form

There are three ways to place data fields onto a form.

Placing Bitmap and JPEG Image Fields

Alpha Anywhere lets you add images to your database in two ways.

Placing Image File Reference Fields

Alpha Anywhere lets you add images to your database in two ways.

Placing Smart Fields on a Form

You create a Smart Field by editing the properties of an existing field on a form. In other words, you "transform" a type-in field to a Smart Field.

Query Builder

The Query Builder allows you to quickly create filter and order expressions and apply them to a table or set. To use the Query Builder :

Quickly Sorting and Filtering Records

You can order records by their field values using single and multiple sorting techniques. When you issue a sort command, Alpha Anywhere uses an index, if one exists, or a query, to order the records. The Alpha Anywhere Status Bar, at the bottom of the screen, shows you which one is being used.

Re-Evaluating Field Rules

If you define or change certain rules after you have already entered records in the table, you can select Rules > Re-evaluate Rules to re-apply these rules to each record. Field rule re-evaluation works with Calculated Fields rules, the Case Conversion rules, and all the Validation rules. When you re-evaluate Field Rules, you can also specify that invalid records be marked. This feature works with the following rules:

Recalculating Calculated Fields (Field Rules)

To recalculate fields defined field rules:

Required Fields

Use the Required rule to make sure a field contains a value before exiting. You can set the Required rule so that a field must always be filled, or filled if a condition evaluates to TRUE.

Resize Fields to Fit Data

To resize field lengths in a table to fit its data:

Retrieving Distinct Field Values

A common application requirement is to produce a list of unique field values contained in a table or set of records. The SQL language uses the DISTINCT keyword to produce these lists.

Returning a Different Field Than You Display

Frequently in a database application you will want to display one field value while storing a different field value. For example, you might want to display "Alaska" but store "AK". You might want to display a user's full name, but store his or her employee number. The following two examples show how to use this technique with a drop down list of choices

Right-Click Menus

Alpha Alpha Anywhere gives you granular control over the right-click menus in your forms and browses. You can define custom right-click menus for the form itself, and for each embedded browse and field on the Form. While using the Control Panel (or any of Alpha Anywhere's layout editors), you can right-click on objects to set properties or perform actions. When you right-click, a right-click (or contextual menu) appears for you to make a selection from a list. For example, if you right-click on a table in the Control Panel, the right-click menu lets you restructure the table, define field rules, rename the table, or perform other actions.

Select Fields Dialog - Generic

The List View Genie and ADO Import Genie use the Specify Fields dialog to create SQL SELECT statements.

Select Text in a Field

The Select Text in a Field action highlights text in a form or browse window.

Skipping Over Fields

A Skip expression can conditionally make a field read-only. If the expression evaluates to TRUE (.T.), the field is skipped; otherwise, it is not. For example, if you have a table that contains both billing address fields and shipping address fields for customers, you can use a Skip expression to skip the shipping address fields if the first line of the shipping address field reads "Same." You might want to make a field conditional based on who is logged on.

Sorting and Selecting Overview

A key function of a database management system is the ability to select specific records and put them in a particular order. Ordering records puts them in a specified sequence, like ordering last names alphabetically. Ordering is also referred to as sorting. Alpha Anywhere provides a variety of tools for finding, selecting, and ordering records. You can perform powerful and complex searches to group your data into lists that match your specific criteria.

Specify Filter Dialog

The List View Genie uses the Specify Filter dialog to create filter expressions.

Specify Order Dialog

The List View Genie and ADO Import Genie use the Specify Order dialog to create SQL SELECT statements.

Specify Table Name Dialog

Steps for specifying a table name dialog.

Tracking Changes to Table Fields

This topic describes a general technique for tracking when fields in different tables are modified. The technique uses:

Types of Field Rules

The following list includes a brief description of each field rule in its own respective category.

Update Example

Updates are the most common and easiest operations that users will perform. Here is an example that uses the AlphaSports sample database.

Using a Coded Lookup Field

A coded lookup field stores one field while displaying another. The Invoice form shows an example of the value of coded lookup fields in its embedded browse. The left-most column of the browse displays the description field from the invoice_items table. This effect is achieved through Field Rules. This is how it was done in the AlphaSports sample database:

Using Field Rules to Generate A Table Lookup

The Product List tab contains an embedded browse named Browse1 that displays data from the Product table. When the user clicks on the Vendor ID column (the Vendor field of the Product table), a popup displays a lookup list of records from the Vendor table. Selecting and entry in this list and clicking the OK button returns the vendor_id from the Vendor table and saves it in the Vendor field of the Product table. The popup list is generated by the field rules associated with the Vendor field of the Product table.

Using Field Statistics

The Field Statistics window displays several different statistics, such as total, average, minimum and maximum, for a field. To view Field Statistics :

Using Object Properties for Table Lookups

The value of using object properties to populate a list is that the developer can use a variety of other control types. The Object Properties tab of the Table Lookups form demonstrates five different ways to do table lookups. Each of the following examples has extra fields (for your information only) that display the stored values of the Quote_Vendor_No and Quote_Product_No fields. The Table Lookups sample database can be downloaded.

Using the Fields Panel

The Fields panel provides an easy way to place data fields, system fields, calculated fields, and variables on a layout. The Fields panel will list all the available data fields for your layout.

Validation Rules

Validation Rules help assure that data entry is reasonable and accurate.

When Calculated Fields are Calculated

Merely adding a field to a table and giving it a field rule calculation expression does not fill the field with values. A field rule does not calculate until one of three events occurs.

Xbasic View Record

The Xbasic View Record action displays a window displaying the chosen fields of a specified record.