PC Review


Reply
Thread Tools Rate Thread

Change autonumber data type

 
 
=?Utf-8?B?TWlrZXk=?=
Guest
Posts: n/a
 
      13th Apr 2004
Hi

I have a table that has an ID field as an autonumber

People create new records through a form, but very frequently they end up cancelling the record (deleting it). The problem is that if they go and make a new record again it will be a number higher - with the amount of deletions etc, this has meant eg the IDs go as follows 1,2,3,4,6,7,11,28,33,34,35,55,70 et

Is there a way that when they do delete a record I can include with the code a preocedure to change the field data type from autonumber to number and then back to autonumber - I have noticed that if I do this manually it seems to reset the autonumber in effect. Will this work

I have thought about having a temporary form which is then submitted to the main table... but the idea seems a bit overwhelming to me

What do you think? Any examples on code if changing the data type will work

Mikey
 
Reply With Quote
 
 
 
 
Gerald Stanley
Guest
Posts: n/a
 
      13th Apr 2004
If it is important to your application to have a column in
strict sequence then I would advise that you do not use the
autonumber facility but instead have a query that
determines the max value of the column and adds 1 to it.

Hope This Helps
Gerald Stanley MCSD
>-----Original Message-----
>Hi,
>
>I have a table that has an ID field as an autonumber.
>
>People create new records through a form, but very

frequently they end up cancelling the record (deleting it).
The problem is that if they go and make a new record again
it will be a number higher - with the amount of deletions
etc, this has meant eg the IDs go as follows
1,2,3,4,6,7,11,28,33,34,35,55,70 etc
>
>Is there a way that when they do delete a record I can

include with the code a preocedure to change the field data
type from autonumber to number and then back to autonumber
- I have noticed that if I do this manually it seems to
reset the autonumber in effect. Will this work?
>
>I have thought about having a temporary form which is then

submitted to the main table... but the idea seems a bit
overwhelming to me.
>
>What do you think? Any examples on code if changing the

data type will work?
>
>Mikey
>.
>

 
Reply With Quote
 
Phil Hunt
Guest
Posts: n/a
 
      13th Apr 2004
If it is a multi user (Lan application) system, it is pretty tricky to use
the Max+1 trick as I found out. Due to the some delay in the network or
whatever, it is easy to get duplicate value. I suppose you have to lock the
table somehow when you do this kind of stuff.

"Gerald Stanley" <(E-Mail Removed)> wrote in message
news:1be4b01c4216a$ad56bf90$(E-Mail Removed)...
> If it is important to your application to have a column in
> strict sequence then I would advise that you do not use the
> autonumber facility but instead have a query that
> determines the max value of the column and adds 1 to it.
>
> Hope This Helps
> Gerald Stanley MCSD
> >-----Original Message-----
> >Hi,
> >
> >I have a table that has an ID field as an autonumber.
> >
> >People create new records through a form, but very

> frequently they end up cancelling the record (deleting it).
> The problem is that if they go and make a new record again
> it will be a number higher - with the amount of deletions
> etc, this has meant eg the IDs go as follows
> 1,2,3,4,6,7,11,28,33,34,35,55,70 etc
> >
> >Is there a way that when they do delete a record I can

> include with the code a preocedure to change the field data
> type from autonumber to number and then back to autonumber
> - I have noticed that if I do this manually it seems to
> reset the autonumber in effect. Will this work?
> >
> >I have thought about having a temporary form which is then

> submitted to the main table... but the idea seems a bit
> overwhelming to me.
> >
> >What do you think? Any examples on code if changing the

> data type will work?
> >
> >Mikey
> >.
> >



 
Reply With Quote
 
Gerald Stanley
Guest
Posts: n/a
 
      13th Apr 2004
True. I have always coded defensively by delaying the
retrieval of the sequence number until the last possible
moment and then trapping for the duplicate error.

Gerald Stanley MCSD
>-----Original Message-----
>If it is a multi user (Lan application) system, it is

pretty tricky to use
>the Max+1 trick as I found out. Due to the some delay in

the network or
>whatever, it is easy to get duplicate value. I suppose you

have to lock the
>table somehow when you do this kind of stuff.
>
>"Gerald Stanley" <(E-Mail Removed)> wrote in message
>news:1be4b01c4216a$ad56bf90$(E-Mail Removed)...
>> If it is important to your application to have a column in
>> strict sequence then I would advise that you do not use the
>> autonumber facility but instead have a query that
>> determines the max value of the column and adds 1 to it.
>>
>> Hope This Helps
>> Gerald Stanley MCSD
>> >-----Original Message-----
>> >Hi,
>> >
>> >I have a table that has an ID field as an autonumber.
>> >
>> >People create new records through a form, but very

>> frequently they end up cancelling the record (deleting it).
>> The problem is that if they go and make a new record again
>> it will be a number higher - with the amount of deletions
>> etc, this has meant eg the IDs go as follows
>> 1,2,3,4,6,7,11,28,33,34,35,55,70 etc
>> >
>> >Is there a way that when they do delete a record I can

>> include with the code a preocedure to change the field data
>> type from autonumber to number and then back to autonumber
>> - I have noticed that if I do this manually it seems to
>> reset the autonumber in effect. Will this work?
>> >
>> >I have thought about having a temporary form which is then

>> submitted to the main table... but the idea seems a bit
>> overwhelming to me.
>> >
>> >What do you think? Any examples on code if changing the

>> data type will work?
>> >
>> >Mikey
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      13th Apr 2004
"Phil Hunt" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> If it is a multi user (Lan application) system, it is pretty tricky to
> use


My strategy for this is to create an empty record using

"INSERT INTO MyTable (MyNumber) VALUES " & strSomeNumber

and incrementing strSomeNumber until dbFailOnError doesn't fail. Usually it
succeeds first time round, obviously. The strSomeNumber is passed back to
the requesting procedure/ form.

Hope that helps


Tim F

 
Reply With Quote
 
Phil Hunt
Guest
Posts: n/a
 
      13th Apr 2004
I coded something like that before, but wrapped within a transaction. When
it fails, i forgot to rollback and bam! the table locked up. Just be
careful, this kind of thing is kinda hard to test/debug.

"Tim Ferguson" <(E-Mail Removed)> wrote in message
news:Xns94CABF83986C4garbleme4455656@207.46.248.16...
> "Phil Hunt" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > If it is a multi user (Lan application) system, it is pretty tricky to
> > use

>
> My strategy for this is to create an empty record using
>
> "INSERT INTO MyTable (MyNumber) VALUES " & strSomeNumber
>
> and incrementing strSomeNumber until dbFailOnError doesn't fail. Usually

it
> succeeds first time round, obviously. The strSomeNumber is passed back to
> the requesting procedure/ form.
>
> Hope that helps
>
>
> Tim F
>



 
Reply With Quote
 
TC
Guest
Posts: n/a
 
      14th Apr 2004
Unfortunately, none of those schemes will guarantee what the OP wants - ie.
no gaps in the numbers - unless the assignment of the next available #, and
the final saving of all new, updated & deleted records pertaining to that
new #, are performed as an atomic transaction - and that ain't possible in
various cases with Access; eg. when using bound forms.

Thus:
- user A hits Save
- code gets next available #123
- user B hits Save
- code gets #124
- A's save fails (for some reason);
- B's save works.

#123 is now MIA!

Cheers,
TC


"Tim Ferguson" <(E-Mail Removed)> wrote in message
news:Xns94CABF83986C4garbleme4455656@207.46.248.16...
> "Phil Hunt" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > If it is a multi user (Lan application) system, it is pretty tricky to
> > use

>
> My strategy for this is to create an empty record using
>
> "INSERT INTO MyTable (MyNumber) VALUES " & strSomeNumber
>
> and incrementing strSomeNumber until dbFailOnError doesn't fail. Usually

it
> succeeds first time round, obviously. The strSomeNumber is passed back to
> the requesting procedure/ form.
>
> Hope that helps
>
>
> Tim F
>



 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      14th Apr 2004
"=?Utf-8?B?TWlrZXk=?=" <(E-Mail Removed)> wrote in
news:9F7478B6-116D-459D-86FA-(E-Mail Removed):

> Is it actually possible to do what I was saying though - i.e. change
> the data type of the field to number


Yes

> and then back to autonumber?


No


Tim F



 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      14th Apr 2004
"Phil Hunt" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> I coded something like that before, but wrapped within a transaction.


Why?


Tim F

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      14th Apr 2004
"TC" <(E-Mail Removed)> wrote in news:407cc2a3$(E-Mail Removed):

> Unfortunately, none of those schemes will guarantee what the OP wants
> - ie. no gaps in the numbers -


Fair cop -- in all the excitement about multiple users I forgot the OP!

B Wishes


Tim F

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoNumber data type =?Utf-8?B?RGVs?= Microsoft Access VBA Modules 5 28th Sep 2006 06:59 PM
Data Type mismatch with autonumber Aranyx Microsoft Access Form Coding 6 21st Dec 2005 10:38 PM
Data type: Autonumber =?Utf-8?B?Ynh5bGU=?= Microsoft Access 4 13th Oct 2005 02:26 PM
Number to AutoNumber Data Type in a table containing data Adrian Microsoft Access 11 16th May 2005 06:16 PM
How to change a number or text data type to autonumber and keep the table data? Julian Ganoudis Microsoft Access Forms 2 12th Jan 2004 08:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 AM.