Link to home
Start Free TrialLog in
Avatar of pin_plunder
pin_plunder

asked on

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?

thanks.
paul.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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)
ASKER CERTIFIED SOLUTION
Avatar of YodaMage
YodaMage

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of comptebidon81
comptebidon81

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...
GunDamn
Avatar of pin_plunder

ASKER

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.
paul.
> 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.
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.
thanks, thanks, thanks.