473,885 Members | 2,444 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 3062
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
3366
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
51276
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
3135
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
2866
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
1995
by: Apple | last post by:
Is there anyone can help me to solve this problem? Thank!
4
7754
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
60109
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
1677
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
2797
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
9956
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
9799
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
11172
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...
1
10871
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
10427
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...
0
9592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.