Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto increment a number code needed

Status
Not open for further replies.

darlek

Technical User
May 9, 2001
27
GB
I have just discovered i cannot use the auto increment that is in paradox, I need to create my own incrementing number field. I have a form that is put into edit mode with an append button to place entries at the bottom of a table.
fields Partno, Weight, Operator.
Partno has to increment by one i.e 1000, 1001 etc all the traps and validity are set on weight.
so I thought i could use the can depart method in weight to trigger the number autoincrement like...
If weight.value>1 then
Partno.value= I need this to be the last number+1 or could i use maximum value +1
this number then needs to be saved as the new Partno
Please could someone help me with this bit of code'
Thank you
 
A common way to do this is to use a separate, one record control table which holds the value of the last PartNo used. Just before you post your new record to your form's table, use code to open the control table with a tcursor, and place a full lock on it. (Check the lock was obtained, and if not, delay a second and retry - abondon with an error if the lock can't be placed within, say, 10 tries). Next, read the value of PartNo from the table, increment it, place the tcursor into edit mode, write the incremented value back to the control table, exit tcursor edit mode, release the lock, close the table. This will ensure that PartNo is unique. However, if your user subsequently abandons the form, the PartNo is "lost" - i.e. there will be gaps in the sequence. This can be avoided by waiting until the form is ready to commit the record to the main table before getting a PartNo from the control table. See also Paradox help re locking tables.
 
I use frequently the following as a calculated field on my form entry:

max(sale_id) + 1

Of course this is only one field and I already have a Key field set up as auto-incrementing.
In this case sale_id, is used as the link to a seperate sales .db

Hope this helps. Steve Butterworth

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top