Thanks guys, Using the max(invoiceno) method has worked for me quite well for desktop applications. However, I'm developing client/server (MS SQL Server) and my fear is that users will be colliding when they retrieve the same invoiceno and try to save.
I'm thinking of a second solution where I have a table specifically for generating the numbers using a stored procedure. The stored procedure will insert a new row in the table and return the generated number. I will call this stored procedure when the user saves the invoice. I'll work it out and then I'll let u know if it works. Phil --- In [email protected], "Glenn B. Lawler" <[EMAIL PROTECTED]> wrote: > > InvoiceNo in Invoices is an autonumber. In my application, > > i want the number to be availed only after the user clicks Save button. > > As such i have used batch updates (ADO). The form seems to work fine > > when the user is adding the invoice items, but when one clicks Save, > > the invoice items disappear. The save button has two lines of code to > > save the changes: > > This problem is one of the reasons I avoid using autoincrement columns. > The items disappear because, by using an autoincrement column, you are > having the DBMS assign a key without your application knowing what the > assigned key is. > > Instead, I use the transaction capability of the DBMS to first find the > InvoiceNo (SELECT MAX(InvoiceNo) FROM Invoices), then use that InvoiceNo > for the INSERT INTO Invoices, then insert the lines. If you include all > these statement within a single transaction, either all or none will > execute. You can then return the InvoiceNo used so the application can > access the saved rows. > > Glenn Lawler ------------------------ Yahoo! Groups Sponsor --------------------~--> Fair play? Video games influencing politics. Click and talk back! http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/i7folB/TM --------------------------------------------------------------------~-> ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: [EMAIL PROTECTED] Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/delphi-en/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

