Numbering records


I want to print out from a DataPower database a list of names numbered in alphabetical order:

    1. Adams
    2. Bernard
    3. Cook

Adding a name would automatically cause them to be renumbered.

I suspect this must be possible since there is a counter in the program.

Can you advise?


It's not possible for the entries to be automatically renumbered when you add or alter a name, since the 'ID' value associated with each record is the entry order of the record, and does not change once you've entered the record. This is useful as a unique ID for each record, but no more.

However, you can write a script that gives each record a number as follows:

First add a numeric field, called (let's say) 'Number'.

Then add a script to a button on the background that says:

On ClickLeft
Renumber ( CurrentRecSet, "Number" )
// Subroutine that renumbers a recordset.
// The name of the field to renumber is passed in.
Sub Renumber ( recset as RecordSet, name as text )
Dim n as integer
Dim ok as boolean
Dim numfield as field
numfield = recset.Field(name)
n = 1
ok = recset.MoveFirst
while ok
numfield.setvalue ( n )
n = n + 1
ok = recset.MoveNext

Now you can just click on the 'Renumber' button on the layout background to renumber the records.

You can also do this with subviews in more complex layouts - just change CurrentRecSet to CurrentRecSet("Subviewname").

You can download an example file that does this by clicking here.

You can copy the script button into your own database by just dragging and dropping it across.

Top of page