472,354 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

How to create autonumber

May anyone can teach me how to assign a autonumber, I want to create a
number that is starting with year(auto change to year 2006) +
autonumber (eg. 2005-0001, 2005-0002)
Nov 13 '05 #1
5 2963
Apple wrote:
May anyone can teach me how to assign a autonumber, I want to create a
number that is starting with year(auto change to year 2006) +
autonumber (eg. 2005-0001, 2005-0002)


Have two separate fields one with DateCreated defaulting to Now() and a
second for RecordID. Even if you don't think you need the record creation
date down to the second that could change down the road and you will be set
if it does. In in the mean time it is an easy way to get the year that you
want. With two fields it is easier to calculate the next ordinal number and
it is easy to display them on your forms and reports in the format you want
with...

=Format(DateCreated, "yyyy-") & Format(RecordID, "0000")

To assign the RecordID as each record is created use the following in the
form's BeforeUpdate event.

If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "TabelName" "Year(DateCreated) =
Year(Date())"), 0) + 1
End If

The above finds the highest existing RecordID value in the table created in
the same year as the current year and then adds 1 to it. The Nz() covers
the very first record of each new year and the If-Then block is necessary
because BeforeUpdate can fire more than once for a given record. This IS
the event you want to use though because it is the only one where the record
is saved immediately after assigning the new value.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
"Rick Brandt" <ri*********@hotmail.com> wrote in message news:<35*************@individual.net>...
Apple wrote:
May anyone can teach me how to assign a autonumber, I want to create a
number that is starting with year(auto change to year 2006) +
autonumber (eg. 2005-0001, 2005-0002)


Have two separate fields one with DateCreated defaulting to Now() and a
second for RecordID. Even if you don't think you need the record creation
date down to the second that could change down the road and you will be set
if it does. In in the mean time it is an easy way to get the year that you
want. With two fields it is easier to calculate the next ordinal number and
it is easy to display them on your forms and reports in the format you want
with...

=Format(DateCreated, "yyyy-") & Format(RecordID, "0000")

To assign the RecordID as each record is created use the following in the
form's BeforeUpdate event.

If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "TabelName" "Year(DateCreated) =
Year(Date())"), 0) + 1
End If

The above finds the highest existing RecordID value in the table created in
the same year as the current year and then adds 1 to it. The Nz() covers
the very first record of each new year and the If-Then block is necessary
because BeforeUpdate can fire more than once for a given record. This IS
the event you want to use though because it is the only one where the record
is saved immediately after assigning the new value.


Thank you Brandt. I have tried your suggestion, when I input in FORM -
PROPERTY - FORMAT the followings : "=Format(DateCreated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at"ec\re"at"ed",yyyy-)&f"\rm"at(R"eco\rd\ID",0000)"

Please tell me what's wrong with this?
Nov 13 '05 #3
"Apple" <tt*********@yahoo.com.hk> wrote in message
news:55**************************@posting.google.c om...
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:<35*************@individual.net>...
Apple wrote:
> May anyone can teach me how to assign a autonumber, I want to create a
> number that is starting with year(auto change to year 2006) +
> autonumber (eg. 2005-0001, 2005-0002)


Have two separate fields one with DateCreated defaulting to Now() and a
second for RecordID. Even if you don't think you need the record creation
date down to the second that could change down the road and you will be
set
if it does. In in the mean time it is an easy way to get the year that
you
want. With two fields it is easier to calculate the next ordinal number
and
it is easy to display them on your forms and reports in the format you
want
with...

=Format(DateCreated, "yyyy-") & Format(RecordID, "0000")

To assign the RecordID as each record is created use the following in the
form's BeforeUpdate event.

If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "TabelName" "Year(DateCreated) =
Year(Date())"), 0) + 1
End If

The above finds the highest existing RecordID value in the table created
in
the same year as the current year and then adds 1 to it. The Nz() covers
the very first record of each new year and the If-Then block is necessary
because BeforeUpdate can fire more than once for a given record. This IS
the event you want to use though because it is the only one where the
record
is saved immediately after assigning the new value.


Thank you Brandt. I have tried your suggestion, when I input in FORM -
PROPERTY - FORMAT the followings : "=Format(DateCreated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at"ec\re"at"ed",yyyy-)&f"\rm"at(R"eco\rd\ID",0000)"

Please tell me what's wrong with this?


Rick wasn't suggesting you put that in the Format property. You put the
formula he gave into the text box's ControlSource property.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

Nov 13 '05 #4
Apple,
What I do is keep a one row table with a column for each seperate sequence
number I need. If I only need one then it's only a one row, one column
table. I store the last sequence number used in that table then run an
update statement to iterate that number each time I need the next number.
This way more than one copy of the application can be runing and get the
next sequence number as needed.

"Apple" <tt*********@yahoo.com.hk> wrote in message
news:55**************************@posting.google.c om...
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:<35*************@individual.net>...
Apple wrote:
> May anyone can teach me how to assign a autonumber, I want to create a
> number that is starting with year(auto change to year 2006) +
> autonumber (eg. 2005-0001, 2005-0002)


Have two separate fields one with DateCreated defaulting to Now() and a
second for RecordID. Even if you don't think you need the record creation
date down to the second that could change down the road and you will be
set
if it does. In in the mean time it is an easy way to get the year that
you
want. With two fields it is easier to calculate the next ordinal number
and
it is easy to display them on your forms and reports in the format you
want
with...

=Format(DateCreated, "yyyy-") & Format(RecordID, "0000")

To assign the RecordID as each record is created use the following in the
form's BeforeUpdate event.

If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "TabelName" "Year(DateCreated) =
Year(Date())"), 0) + 1
End If

The above finds the highest existing RecordID value in the table created
in
the same year as the current year and then adds 1 to it. The Nz() covers
the very first record of each new year and the If-Then block is necessary
because BeforeUpdate can fire more than once for a given record. This IS
the event you want to use though because it is the only one where the
record
is saved immediately after assigning the new value.


Thank you Brandt. I have tried your suggestion, when I input in FORM -
PROPERTY - FORMAT the followings : "=Format(DateCreated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at"ec\re"at"ed",yyyy-)&f"\rm"at(R"eco\rd\ID",0000)"

Please tell me what's wrong with this?

Nov 13 '05 #5
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message news:<2N********************@rogers.com>...
"Apple" <tt*********@yahoo.com.hk> wrote in message
news:55**************************@posting.google.c om...
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:<35*************@individual.net>...
Apple wrote:
> May anyone can teach me how to assign a autonumber, I want to create a
> number that is starting with year(auto change to year 2006) +
> autonumber (eg. 2005-0001, 2005-0002)

Have two separate fields one with DateCreated defaulting to Now() and a
second for RecordID. Even if you don't think you need the record creation
date down to the second that could change down the road and you will be
set
if it does. In in the mean time it is an easy way to get the year that
you
want. With two fields it is easier to calculate the next ordinal number
and
it is easy to display them on your forms and reports in the format you
want
with...

=Format(DateCreated, "yyyy-") & Format(RecordID, "0000")

To assign the RecordID as each record is created use the following in the
form's BeforeUpdate event.

If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "TabelName" "Year(DateCreated) =
Year(Date())"), 0) + 1
End If

The above finds the highest existing RecordID value in the table created
in
the same year as the current year and then adds 1 to it. The Nz() covers
the very first record of each new year and the If-Then block is necessary
because BeforeUpdate can fire more than once for a given record. This IS
the event you want to use though because it is the only one where the
record
is saved immediately after assigning the new value.


Thank you Brandt. I have tried your suggestion, when I input in FORM -
PROPERTY - FORMAT the followings : "=Format(DateCreated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at"ec\re"at"ed",yyyy-)&f"\rm"at(R"eco\rd\ID",0000)"

Please tell me what's wrong with this?


Rick wasn't suggesting you put that in the Format property. You put the
formula he gave into the text box's ControlSource property.

Thank you Doug, I had tried to put the formula into FORM-TEXT
BOX-CONTROL SOURCE PROPERTY or FORM-UNBOUNDED TEST BOX-CONTROL SOURCE
PROPERTY, but it show error(#xxxx?); when I tried to put into a query
as an expression, when open up the query or form, it will ask to enter
an parameter (1) date; (2) number, if I entre (1) 2005/01/01; (2)
0001, it will show 2005-0001 in all record that I have input data
before.

The following is in my form's BeforeUpdate event :

Private Sub RecordID_BeforeUpdate(Cancel As Integer)
If IsNull(Me.RecordID) = True Then
Me.RecordID = Nz(DMax("RecordID", "FORM
NAME""Year(DateCreated)=Year(Date())"), 0) + 1
End If
End Sub
Please comment!!
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: poohnie08 | last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot hour, slot1, slot2, slot3, slot4 and others). The "()" will keep repeating from day 1 until end of month. eg in excel spreadsheet,...
3
by: Gekko . via AccessMonster.com | last post by:
I want to create a query that the first field should be an autonumber. For example I want the name and last name from the Emp table, but I want that the first field is an autonumber that identifies...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
2
by: Apple | last post by:
May anyone can teach me to assign a autonumber, I want to create a number that is starting with year (auto change to year 2006) + autonumber (eg. 2005-1001, 2005-1002 and so on)
2
by: Apple | last post by:
Is there anyone can help me to solve this problem? Thank!
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
9
by: minjie | last post by:
I need to upgrade a MS Access database (Version 2002) with a script only, i.e., via SQL statement, not via Access GUI, and I'm having trouble defining an AutoNumber field. I got an exception error...
1
by: junis | last post by:
Dear Experts.. i need create table with identiry field .. if i use GUI ..i just click and choose autonumber as type ... but i try with SQL Stement : "Create Table Test (id autonumber, Desc...
1
by: sanju4kk | last post by:
I am attempting to create a module that I can call to create a new field in my temp table that will be an autonumber, and then assigned that new field as the primary key. I have been search high and...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.