Lantica Software Support Center
Lantica Software Home Page


Automatically Assign The Next Record Number

For some records, such as Invoices, you want to automatically assign the next record number when the record is saved. This method uses a Global Value.

1. Open your Form in Designer.

2. Open the Programming Editor by selecting Program Layout from the Commands Control Panel. Select your Form from the Element dropdown. Select On Form Exit from the Event dropdown.

Note: The On Form Exit event is used so that the next number is not used until the record is actually saved. If you want different behavior, you can move the code to whichever event you want.

3. Type the program in the Program Editor window.

// Only assign the number if 
// this is a new record which
// has been changed.

var vNextNum as Int

        vNextNum = @ToNumber(@GlobalValue("NextNumber")) + 1
        Key = vNextNum
        GlobalValue("NextNumber", @Str(vNextNum))

5. Test your program by selecting Test Program from the Test menu. Fix any syntax errors that are reported.

6. When you are finished, select Close Program Editor from the File menu. Your programming changes will be saved when you save your Form.

Don't forget to save and reconcile your changes!

When you save a new record, the next number will be automatically assigned.