Database Reference
In-Depth Information
Creating a Keystroke Filter
Keystroke triggers also let you limit what users can type into a field. You know how to use
validation to show an error message if something inappropriate is typed in a field ( Looked-
Up Value ) . But with validation, users don't get feedback until after the wrong data has been
entered. Alternatively, you can write a script and set an OnObjectKeystroke trigger that can
refuse certain data and beep to warn the user.
The script will check each key your users press and cancel all invalid keystrokes. Careful
though: Writing a keystroke trigger takes special care. First of all, you have to decide what
makes a keystroke invalid. Here are the rules for the Zip Code field:
▪ If the keystroke isn't a number (0 through 9), then don't allow it.
▪ If the field already has five digits in it, then cancel any keystroke.
With this in mind, switch to Layout mode and then select the Zip Code field. Choose
Format→Set Script Triggers and then select the OnObjectKeystroke option. Then click the
+ button to create a new script. The new script consists of two If statements. First you check
for non-number keys with a formula like this one:
Get ( TriggerKeystroke ) ≠ 0 and
Get ( TriggerKeystroke ) ≠ 1 and
Get ( TriggerKeystroke ) ≠ 2 and
Get ( TriggerKeystroke ) ≠ 3 and
Get ( TriggerKeystroke ) ≠ 4 and
Get ( TriggerKeystroke ) ≠ 5 and
Get ( TriggerKeystroke ) ≠ 6 and
Get ( TriggerKeystroke ) ≠ 7 and
Get ( TriggerKeystroke ) ≠ 8 and
Get ( TriggerKeystroke ) ≠ 9
Inside the If statement you add a script step to let users know something is happening and
then exit the script with a result of False. Your second If statement checks for excess key-
strokes. It has a simple calculation:
Length ( Customers::Zip Code ) ≥ 5
Once again, inside this If statement, you beep and exit with a False result. You can see this
script in Figure 17-18 .
Search WWH ::




Custom Search