Auto increment ID value

Hello -

I am trying to figure out how to use the .Initialize procedure to set my filegloabal variable to the value of max ID+1 so, I can use a procedure to trigger on Add new record to auto increment the ID value in each new row.

Any input or advice to perform this action? Is there a PDF version of the developer documentation?

Thank you in advance for guidance.

Robb

Put ‘+’ in the Default Value field of the Field Properties for your ID field. See Field Properties

Thank you so much. That is perfect.

Robb

Robb - here is something to consider … If you use +1 there is a potential for a duplicate ID. That’s because, with a +1, Panorama simply adds 1 to the numeric field above it to create the next number. The problem is, what if, intended or not, a new record was inserted instead of added at the end. In that case, it wouldn’t get the next “unique” number, it would get the number in the ID field of the record above it, plus 1, which would be a duplicate of the ID number below it.

So if you had records with ID field content
1
2
3
4

and you aded at the end, you have
1
2
3
4
5 - new record

but if for some reason the new record was added (inserted) between the 3 and the 4 you’d have
1
2
3
4 - new record
4
5

You can avoid that problem by just using “+” and not giving an increment. It’s an amazing difference for such a small change. With ONLY, the “+”, the new record is assured a unique record number - a number that will never be repeated even if the record that has it is deleted. Note, that is NOT the case with the +1.

There is something reassuring about seeing a nice sequential, no gaps, series of ID numbers. But remember, The ID field’s main job is to be unique, not necessarily sequential. Using just the “+” guarantees that Prime Directive. Using “+1” (or any other increment, does not).

But there is a caveat - The Help Reference says that unique number (“+”) is derived from a record counter that can be seen, AND CHANGED, in the General Tab of Database Options (under the File Menu). There’s no further discussion in the Help about what happens if you reset that record number counter to an earlier and then add more records. My guess is, in the words of that great philosopher, RoboCop, “There will be … trouble”.

Check out the File menu ‘Database Options…’ Next Record ID#

Or: NSN = aggregate(“NSN”,“max”)+1, where NSNOTIFY (for new serial number) is a field.

sorry, NSN should be new serial number…

Thanks to everyone on your assistance.

Robb