PC Review


Reply
Thread Tools Rate Thread

Autonumber fields in MS Access

 
 
=?Utf-8?B?UEQ=?=
Guest
Posts: n/a
 
      19th Apr 2006
Hello,

Can anyone tell me how to programatically reset the autonumber count in a
table in Access? I want to run a delete query to remove all rows, then
append rows and have the autonumber field begin counting at 1. I don't want
to make a new table with a new autonumber field, because I don't know how to
do that in a macro or a module (how to make a new table, define the fields,
create a new autonumber field). I have tried the method in the help file of
appending to the autonumber field and it doesn't work. The autonumber field
just picks up where it was before appending.

Thank you for your help.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?T2ZlciBDb2hlbg==?=
Guest
Posts: n/a
 
      19th Apr 2006
You can set the field back to counter after you delete the date

Delete statement
docmd.RunSQL "Alter table TableName ALTER COLUMN FieldName counter"
Insert Statemet

--
HTH, Good Luck
BS"D


"PD" wrote:

> Hello,
>
> Can anyone tell me how to programatically reset the autonumber count in a
> table in Access? I want to run a delete query to remove all rows, then
> append rows and have the autonumber field begin counting at 1. I don't want
> to make a new table with a new autonumber field, because I don't know how to
> do that in a macro or a module (how to make a new table, define the fields,
> create a new autonumber field). I have tried the method in the help file of
> appending to the autonumber field and it doesn't work. The autonumber field
> just picks up where it was before appending.
>
> Thank you for your help.

 
Reply With Quote
 
=?Utf-8?B?UEQ=?=
Guest
Posts: n/a
 
      20th Apr 2006
Thank you so much. I appreciate it. When I tried to run I inserted the
table and field names like this:
DoCmd.RunSQL "Alter table Table1, ALTER COLUMN test counter"

And I got the following error message:

Syntax Error in Alter Table statement.

Is it an issue with enclosing the table and field names in quotes, or was I
supposed to do something with the counter at the end?

I really appreciate your help.





"Ofer Cohen" wrote:

> You can set the field back to counter after you delete the date
>
> Delete statement
> docmd.RunSQL "Alter table TableName ALTER COLUMN FieldName counter"
> Insert Statemet
>
> --
> HTH, Good Luck
> BS"D
>
>
> "PD" wrote:
>
> > Hello,
> >
> > Can anyone tell me how to programatically reset the autonumber count in a
> > table in Access? I want to run a delete query to remove all rows, then
> > append rows and have the autonumber field begin counting at 1. I don't want
> > to make a new table with a new autonumber field, because I don't know how to
> > do that in a macro or a module (how to make a new table, define the fields,
> > create a new autonumber field). I have tried the method in the help file of
> > appending to the autonumber field and it doesn't work. The autonumber field
> > just picks up where it was before appending.
> >
> > Thank you for your help.

 
Reply With Quote
 
=?Utf-8?B?UEQ=?=
Guest
Posts: n/a
 
      20th Apr 2006
Ofer,

Thank you so much. I removed the comma that I had inserted and it works
great! Are there any references to what is available in the RUNSQL function,
or is it just a matter of knowing SQL?

Thank you so much again for your help. I really appreciate it.

"PD" wrote:

> Thank you so much. I appreciate it. When I tried to run I inserted the
> table and field names like this:
> DoCmd.RunSQL "Alter table Table1, ALTER COLUMN test counter"
>
> And I got the following error message:
>
> Syntax Error in Alter Table statement.
>
> Is it an issue with enclosing the table and field names in quotes, or was I
> supposed to do something with the counter at the end?
>
> I really appreciate your help.
>
>
>
>
>
> "Ofer Cohen" wrote:
>
> > You can set the field back to counter after you delete the date
> >
> > Delete statement
> > docmd.RunSQL "Alter table TableName ALTER COLUMN FieldName counter"
> > Insert Statemet
> >
> > --
> > HTH, Good Luck
> > BS"D
> >
> >
> > "PD" wrote:
> >
> > > Hello,
> > >
> > > Can anyone tell me how to programatically reset the autonumber count in a
> > > table in Access? I want to run a delete query to remove all rows, then
> > > append rows and have the autonumber field begin counting at 1. I don't want
> > > to make a new table with a new autonumber field, because I don't know how to
> > > do that in a macro or a module (how to make a new table, define the fields,
> > > create a new autonumber field). I have tried the method in the help file of
> > > appending to the autonumber field and it doesn't work. The autonumber field
> > > just picks up where it was before appending.
> > >
> > > Thank you for your help.

 
Reply With Quote
 
=?Utf-8?B?T2ZlciBDb2hlbg==?=
Guest
Posts: n/a
 
      20th Apr 2006
Your welcome, glad it worked
In the RunSQL (as given by it's name) we run Action SQL such as
Create, Insert , Delete , Update , Alter

--
HTH, Good Luck
BS"D


"PD" wrote:

> Ofer,
>
> Thank you so much. I removed the comma that I had inserted and it works
> great! Are there any references to what is available in the RUNSQL function,
> or is it just a matter of knowing SQL?
>
> Thank you so much again for your help. I really appreciate it.
>
> "PD" wrote:
>
> > Thank you so much. I appreciate it. When I tried to run I inserted the
> > table and field names like this:
> > DoCmd.RunSQL "Alter table Table1, ALTER COLUMN test counter"
> >
> > And I got the following error message:
> >
> > Syntax Error in Alter Table statement.
> >
> > Is it an issue with enclosing the table and field names in quotes, or was I
> > supposed to do something with the counter at the end?
> >
> > I really appreciate your help.
> >
> >
> >
> >
> >
> > "Ofer Cohen" wrote:
> >
> > > You can set the field back to counter after you delete the date
> > >
> > > Delete statement
> > > docmd.RunSQL "Alter table TableName ALTER COLUMN FieldName counter"
> > > Insert Statemet
> > >
> > > --
> > > HTH, Good Luck
> > > BS"D
> > >
> > >
> > > "PD" wrote:
> > >
> > > > Hello,
> > > >
> > > > Can anyone tell me how to programatically reset the autonumber count in a
> > > > table in Access? I want to run a delete query to remove all rows, then
> > > > append rows and have the autonumber field begin counting at 1. I don't want
> > > > to make a new table with a new autonumber field, because I don't know how to
> > > > do that in a macro or a module (how to make a new table, define the fields,
> > > > create a new autonumber field). I have tried the method in the help file of
> > > > appending to the autonumber field and it doesn't work. The autonumber field
> > > > just picks up where it was before appending.
> > > >
> > > > Thank you for your help.

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      20th Apr 2006
PD wrote:

>Can anyone tell me how to programatically reset the autonumber count in a
>table in Access? I want to run a delete query to remove all rows, then
>append rows and have the autonumber field begin counting at 1. I don't want
>to make a new table with a new autonumber field, because I don't know how to
>do that in a macro or a module (how to make a new table, define the fields,
>create a new autonumber field). I have tried the method in the help file of
>appending to the autonumber field and it doesn't work. The autonumber field
>just picks up where it was before appending.



Another way to reset an auto number after deleting records
is to Compact the database.

OTOH, you should not care what values are in an autonumber
field. If you do care about the values, you should create
them yourself instead of relying on a feature that was
intended for an entirely different purpose.

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
RobFMS
Guest
Posts: n/a
 
      20th Apr 2006
Here's everything you need to know about autonumbers...

Autonumber field in Table
http://www.mvps.org/access/general/gen0006.htm

Use Autonumbers properly
http://www.mvps.org/access/general/gen0025.htm

Have Autonumber field start from a value different from 1
http://www.mvps.org/access/tables/tbl0005.htm

Creating an AutoNumber field from code
http://www.mvps.org/access/tables/tbl0016.htm

HTH

--
Rob Mastrostefano

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com


"PD" <(E-Mail Removed)> wrote in message
news:5D03D87F-7261-4B4F-B36C-(E-Mail Removed)...
> Hello,
>
> Can anyone tell me how to programatically reset the autonumber count in a
> table in Access? I want to run a delete query to remove all rows, then
> append rows and have the autonumber field begin counting at 1. I don't
> want
> to make a new table with a new autonumber field, because I don't know how
> to
> do that in a macro or a module (how to make a new table, define the
> fields,
> create a new autonumber field). I have tried the method in the help file
> of
> appending to the autonumber field and it doesn't work. The autonumber
> field
> just picks up where it was before appending.
>
> Thank you for your help.



 
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 Fields??? Bill Microsoft Access 6 22nd Nov 2006 10:26 PM
Autonumber fields =?Utf-8?B?SmltIEpvbmVz?= Microsoft Access VBA Modules 4 25th Jul 2006 10:58 AM
Resetting AutoNumber Fields to Zero in Access 2003 =?Utf-8?B?Qnl6YW50aW5l?= Microsoft Access 1 16th Dec 2004 08:51 PM
Access 2000, autonumber fields =?Utf-8?B?WnliZXJnNzQ=?= Microsoft Access 3 17th Nov 2004 04:24 PM
autonumber fields ping Microsoft Access 4 12th Oct 2004 01:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:49 PM.