autonumber problem

Ok, I've suppose I have the following table:

IdCustomer || Name || Address || etc, etc, etc
autonumber    alpha    alpha

I call datamodule.clientdataset.append;
The user enters all data and then
I call datamodule.clientdataset.applyupdates(-1);

This works just fine. But what happens if I want some label of mine to show the IdCustomer the user is just entering now. I mean, while the user enters all data I want a label to show the autonumber. However, this is not as easy as it may seem, because the autonumber, apparenttly is generated when I call datamodule.clientdataset.applyupdates(-1);

Is there any way to calculate autonumber fields before the user enters data in the new record?

Who is Participating?
Autoinc in Paradox is not good at all. You are better off keeping a table with int values seperate, then having a global procedure to get value, then inc value in table. This is basically a mimic of a SQL generator.
for paradox,
there is a (tricky) way to lookup the next generated number without to get it
(you need fileaccess to the table)
(not recommended for multiuser-access)
Or may I suggest you to Force a Post when the user starts editing. Your Index will be updated and you won't have to de anything tricky to get the number...
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

pin_plunderAuthor Commented:
I'm sorry to say this but I thought I was the one who was wrong or missed something, but now I clearly see that the guys who made paradox are not very clever, are they?

thanks all for your help. although there wasn't much to say.
> the guys who made paradox are not very clever, are they?

this i would not say, just look at paradox history

its an old desktop-database comes up ~1990 and
was the first multiuser desktop-database on market

You could:
 - read the previous record's AutoInc field into variable
   and just add 1 and display it (don't post it)

 - or like comptebidon81 hinted, when the user starts
   editing, do an Append followed by a Post (fill in any
   required fields with junk first) and then Edit the
   record (clearing any junk before displaying)

rondi- The problem there is the multi-user aspect, and the fact that the autoinc value is not assigned until the post. Say I enter the app first and start to insert, with 100 being the next logical value from the previous record of 99. Then you enter the system after me, and do the same action, being 101. If you post your record first, you will end up 100 with me being 101. With more users and more data entry, the problem multiplies.

Removeing autoinc fields in favor of an integer field that you manually assign solves the issue as already said, by simulating a generator. It involves more code, but allows you to assign and increment the count on any event you like instead of being tied to the post event. You also have the benefit of manually ajusting the generator if needed.
pin_plunderAuthor Commented:
thanks, thanks, thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.