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 (March 2004)

Generating Unique Ids When Using Multiple Handhelds

Say you are working on an order entry application and you want Visual CE to generate a unique ORDER_ID for each new order. If you have multiple handhelds creating orders, you need to work out a scheme such that different handhelds don't generate the same ORDER_ID. Visual CE has some tools you can use to help do this.

If your application is only going to run on one handheld, an Autonumber control can be used to generate a unique ORDER_ID for each order. The Visual CE Autonumber control will generate a unique number relative to all the other ORDER_ID's already in use.

However, if you are creating orders on more than one handheld, it is possible that that the Autonumber control on one handheld will generate the same ORDER_ID as on another. To accommodate this, one of the properties of an Autonumber control is the "Start" number. You can have one handheld start at 1000, another start at 2000, etc. This scheme is simple to implement and, in many cases, will do the job.

However, using the "Start" property on Autonumber controls has two potential problems:

  • You need to have a slightly different form on each handheld (they would only differ by the Start number property). If you only have two or three handhelds, this is not a problem. But if you have a large number of devices, this can be cumbersome.

  • If you generate too many records on one handheld, that device would start generating ORDER_ID's that "belong" to another handheld.

To overcome these problems...

  1. In your table, create another column called UNIQUE_ID and create an Autonumber control over that column.

  2. Remove the ORDER_ID column from your table and replace it with another column (also called ORDER_ID) that is a text, not a numeric, column.

  3. On your form, create a calculated control over the new ORDER_ID column with the expression

    @devicename & UNIQUE_ID

Once you do this, all you have to do is make sure each device has a unique device name (START | SETTINGS | SYSTEM | ABOUT | DEVICE ID).