473,770 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3057
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(DateCre ated, "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.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "TabelName" "Year(DateCreat ed) =
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*********@ho tmail.com> wrote in message news:<35******* ******@individu al.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(DateCre ated, "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.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "TabelName" "Year(DateCreat ed) =
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(DateCr eated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at "ec\re"at"ed",y yyy-)&f"\rm"at(R"ec o\rd\ID",0000)"

Please tell me what's wrong with this?
Nov 13 '05 #3
"Apple" <tt*********@ya hoo.com.hk> wrote in message
news:55******** *************** ***@posting.goo gle.com...
"Rick Brandt" <ri*********@ho tmail.com> wrote in message
news:<35******* ******@individu al.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(DateCre ated, "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.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "TabelName" "Year(DateCreat ed) =
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(DateCr eated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at "ec\re"at"ed",y yyy-)&f"\rm"at(R"ec o\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*********@ya hoo.com.hk> wrote in message
news:55******** *************** ***@posting.goo gle.com...
"Rick Brandt" <ri*********@ho tmail.com> wrote in message
news:<35******* ******@individu al.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(DateCre ated, "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.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "TabelName" "Year(DateCreat ed) =
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(DateCr eated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at "ec\re"at"ed",y yyy-)&f"\rm"at(R"ec o\rd\ID",0000)"

Please tell me what's wrong with this?

Nov 13 '05 #5
"Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message news:<2N******* *************@r ogers.com>...
"Apple" <tt*********@ya hoo.com.hk> wrote in message
news:55******** *************** ***@posting.goo gle.com...
"Rick Brandt" <ri*********@ho tmail.com> wrote in message
news:<35******* ******@individu al.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(DateCre ated, "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.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "TabelName" "Year(DateCreat ed) =
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(DateCr eated,
"yyyy-")........, it will turn to
("=F"\m"at)d"at "ec\re"at"ed",y yyy-)&f"\rm"at(R"ec o\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_Before Update(Cancel As Integer)
If IsNull(Me.Recor dID) = True Then
Me.RecordID = Nz(DMax("Record ID", "FORM
NAME""Year(Date Created)=Year(D ate())"), 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
3361
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, ============================================================================== A1 |A2 A3 A4 A5 A6 A7 A8 |A9 A10 A11 | 01/02/04 |02/02/04 StaffName |Work Hr OT Hr Slot1...
3
51269
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 the record so the results of the query should look something like Field1 Name LastName 1 Gekko NoLast 2 Mary Jane 3 Jon Doe ***************************************** * This message was posted via...
24
3123
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 (primary key) FirstName MiddleName LastName
2
2863
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
1986
by: Apple | last post by:
Is there anyone can help me to solve this problem? Thank!
4
7748
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, but I can't update record in query or in form. I believe the problem is due to the source query. In source query, there is a filter to show the incomplete record ("is null" in delivery date)], but I need to re-use the job no. if the job is...
9
60101
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 when running the follwoing (in a C++ program using ADO): ...... cmdStr = "CREATE TABLE mytab " "( AutoNumber, " " TEXT(50), " "CONSTRAINT PRIMARY KEY ()); ";
1
1676
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 Text(50))" i get error message that syntax error in filed definition.. i try again .. i change "autonumber" with "identiry" and.. i get error message again..
1
2789
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 low for the code, it seems like an easy task but haven't solved the problem yet. Here is the current scenario: I import an text file of numbers, once imported, I need to assign a unique (autonumber) value to each number imported, starting with 1...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.