How can i automatically calculate and fill an id without using auto increment option

Being new here and having coded a long time ago I have to search a lot :slight_smile:
I am looking for an example (of code) that on completion of a record being added fills in a new value for a field including a number field that holds a unique number. I use an external db.

I also want to calculate this unique ID from a table that holds the last issued ID per table (e.g. a table with sequences).

By macro…

I kinda understood that :slight_smile:
However, how can I issue SQL commands in a macro and on what event should I trigger this macro if I use a form to add the record? I am looking for some short example.