mobile databases, mobile forms, and mobile synchronization … where you need to work
Providing Pocket Access, Mobile Database, Windows CE Database, and Windows CE Development Solutions

Tip of the Month (February 2005)

Handling "Record not found" When Searching

A Command Button (RECORD | SEARCH) can be used to naviage to a record based on a value in a variable. If the "Exact matches only" checkbox is on and there is no corresponding record, Visual CE puts up a "Record not found" error message. Instead of the "Record not found" error, you might want to do some error handling instead.

If you have Visual CE 11.0 or later, a RECORD | SEARCH macro step that fails to find a record can be detected by the macro step itself. If you have an older version of Visual CE, here's how you can do this by putting a Lookup Control on your form and putting the Command Button (RECORD | SEARCH) in a macro...

Say you are searching the CUSTOMER for a record that has the value in CUSTOMER_ID that equals @var(1). On your CUSTOMER form, create a lookup control, that looks in the CUSTOMER table keyed on @var(1). When asked if you want to save the value found, say YES and put it into a variable (for example, @var(34)). When asked what column to retrieve, select CUSTOMER_ID. When this form runs, the lookup control will fire. If there is an CUSTOMER whose CUSTOMER_ID equals @var(1), the CUSTOMER_ID will be in @var(34). Otherwise @var(34) will be blank.

The macro you would use to test the Lookup Control is:

Button 1: SKIP. Set "number" to: if @var(34) = '' then 1 else 0
Button 2: The original Commad Button (RECORD | SEARCH)
Button 3, 4, 5...: Whatever you want done if there is no corresponding CUSTOMER.