Hi Nelson,
Ok, I think you need to step back a fraction to consider how this works normally.
there are basically two approaches here;
a) when the user opens the form on Insert, you assign the new record number and the record is immediately created. The form is then really in a "Change mode" not an Insert mode. If you then add child records at the same time (like say the Line items for an invoice) then the number is already set, the parent record is already created (remember some backends won't let you create child records before a parent record) and when the user clicks Save they're really just saving the "edits" to the record.
The big advantage with this approach is that it's very easy to do (indeed if you're using auto-numbering the templates do it all for you.) The big disadvantage is that if the user cancels the invoice then you can potentially get a "gap" in the numbering scheme. This is usually nothing to worry about, but in some cases can be unacceptable. (In accounting for example, you aren't really allowed "gaps"). One solution is to mark the record as "cancelled" until they click on save - so the record remains, but is effectively "null and void".
b) The second approach is somewhat more complicated. In this situation you collect the invoice and line items into one or more temporary tables. Then when the user clicks on save you have to manually move the records over to the real table. This can mean no gaps, but it's a lot more effort to do (because you need to do most of the work yourself) and also because you need to deal with a lot more complexity (ie as your form gets more complicated, with more child records, it makes more work.)
I think what you've been thinking about up to now is
"issue the number", then do a bunch of stuff, then create the record when the user clicks on Save. This is really the wrong way to do it because it's harder to manage than (a) above, but doesn't solve (a)s problems.
If the number you are fetching is _not_ an ID field for the table, just an arbitary number, then the better embed point would be the end of the ValidateRecord routine. This is called right before the record is written to disk.
cheers
Bruce