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) 5 3027
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
"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?
"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!)
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?
"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!! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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)
|
by: Apple |
last post by:
Is there anyone can help me to solve this problem? Thank!
|
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,...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |