Need help in Auto number Please..!!

G

Guest

Hello every body..
I have apb in my DB. I designed a DB in Access and all stuff is ok. But nwo
i want to give serial number to my records also. Yes i use the auto number
utility but the auto number it gives form 20 and onwards. bc i have already
19 records in my table. For such pb i delete my all records form the table
that may be when i again enter records it will start the auto number from 1
but not succeded. Can any one tell me a way that hwo can my autonumber should
start from 1.

Regards,
Khaksar,
 
D

Douglas J. Steele

Realistically, the value of the Autonumber field shouldn't matter to you. An
Autonumber exists for one purpose only: to provide a (practically
guaranteed) unique value that can be used as a primary key. It's usually
considered unusual to even show the value of the Autonumber field to the
users.

That having been said, compacting the database once you've deleted all of
the data from the table should cause the next record to be inserted into the
table to have an Autonumber with a value of 1.
 
G

Guest

R. Sir,
You are right and quite well at your side. But in my DB i have to assign a
file number to each person and that File number depends on the Serial number.
So to assign fil enumber it is very necessary to give Serial number. It shows
me the number of records entered in the DB.

So if you can please help in these regards.

Thanks.
 
D

Douglas J. Steele

The value of the highest value in the AutoNumber field will NOT give you the
number of records entered in the table.

AutoNumber fields are not guaranteed to be consecutive. If you start to add
a record and then change your mind, you are guaranteed to lose the value
that would have been assigned to that record.

If you have the requirements you're describing, you shouldn't be using an
AutoNumber field.
 
G

Guest

Then can you please helpme in these regards.....

khaksar said:
R. Sir,
You are right and quite well at your side. But in my DB i have to assign a
file number to each person and that File number depends on the Serial number.
So to assign fil enumber it is very necessary to give Serial number. It shows
me the number of records entered in the DB.

So if you can please help in these regards.

Thanks.
 
D

Douglas J. Steele

If all you care about is having the ID number equal the number of records in
the table when that record was inserted, put code in your form's
BeforeInsert event to calculate the ID:

Private Sub Form_BeforeInsert()

Me.ID = DCount("*", "NameOfTable") + 1

End Sub
 
G

Guest

Sir,
I think it does not make any sence.

Douglas J. Steele said:
If all you care about is having the ID number equal the number of records in
the table when that record was inserted, put code in your form's
BeforeInsert event to calculate the ID:

Private Sub Form_BeforeInsert()

Me.ID = DCount("*", "NameOfTable") + 1

End Sub
 
D

Douglas J. Steele

Of course it makes sense. Before you insert a new record into the table, you
determine how many records are already in the table using DCount and add one
to that number to use it as the ID for the record you're going to insert.

Since I didn't know the name of your table nor the name of your ID field, I
used NameOfTable for the table name, and assumed that the ID field is named
ID.

I did make one error, though. It should be

Private Sub Form_BeforeInsert(Cancel As Integer)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top