473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

reset number on new year

Kd
I have the following set up to give me aresponse number R05-001
I would like it to reset to R06-001 at new year

ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" &
Format([PONum],"000")
This is an expression in a query
any help is apprecieated
Ken

Dec 30 '05 #1
22 5569

"Kd" <ke******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have the following set up to give me aresponse number R05-001
I would like it to reset to R06-001 at new year

ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" &
Format([PONum],"000")
This is an expression in a query
any help is apprecieated
Ken


Ken,

That should do the job as is. "Date()" will return the current date, so it
should switch automatically at new year.

It seems a bit odd to Format for a 4 digit year then take only the right 2
digits, but it should work.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Dec 30 '05 #2
Kd
intead of Right(Format(Date(),"yyyy"),2)
should i go with datepart(yy)

Dec 30 '05 #3
Kd wrote:
I have the following set up to give me aresponse number R05-001
I would like it to reset to R06-001 at new year

ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" &
Format([PONum],"000")
This is an expression in a query
any help is apprecieated
Ken


How is PONum generated? What you have now will automtically change with the
year on the prefix, but the numbers will not go back over to start at one again
if you are using an AutoNumber for the PONum.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Dec 30 '05 #4
"Kd" <ke******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
intead of Right(Format(Date(),"yyyy"),2)
should i go with datepart(yy)

Instead of

Right(Format(Date(),"yyyy"),2)

you could use:

Format(Date(),"yy")

The first one says to assemble the year for the current date in 4 digits
then throw away all but the last 2 digits. The second one says simply
assemble the last two digits of the year for the current date. There is
nothing wrong with the first form, it just does more work than is needed.

Cheers,
--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Dec 30 '05 #5
Kd
PONum is set up longint. on table
and
=DMax("[PONum]","[PO Table]")+1
on form
should i change this?

Dec 30 '05 #6
What is in the PO Table? Is it a single record with the current PO number,
or does it contain a record of each PO you've created?

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
"Kd" <ke******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
PONum is set up longint. on table
and
=DMax("[PONum]","[PO Table]")+1
on form
should i change this?


Dec 30 '05 #7
Kd wrote:
PONum is set up longint. on table
and
=DMax("[PONum]","[PO Table]")+1
on form
should i change this?


First I see another problem. If you are generating this formatted number in a
query using...

ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" & Format([PONum],"000")

....then ALL of your records will change to R06 for the prefix in the new year
not just new ones because you are always using the current system date. You
need to be using the date that the record was created. Do you have such a
field?

If your table included a field named CreateDate then your query expression would
be...

ResponseNo: "R" & Format(CreateDate(),"yy") & "-" & Format([PONum],"000")

....(eliminating the unnecessary Right() function)

Then your DMax assignment changes to...

=Nz(DMax("[PONum]","[PO Table]", "CreateDate >= DateSerial(Year(Date()), 1,
1)"), 0)+1

Now instead of finding the highest number in the table and adding one to it, the
expression finds the highest number from only those records created in the
current year. The Nz() wrapper is required for the very first entry of any
given year since DMax() will return Null in that circumstance.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Dec 30 '05 #8
Kd
thanks
and i would assign the dmax satement to the
response number textbox on form correct
thanks again
Ken

Dec 30 '05 #9
On Fri, 30 Dec 2005 15:09:14 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote:
Kd wrote:
PONum is set up longint. on table
and
=DMax("[PONum]","[PO Table]")+1
on form
should i change this?


First I see another problem. If you are generating this formatted number in a
query using...

ResponseNo: "R" & Right(Format(Date(),"yyyy"),2) & "-" & Format([PONum],"000")

...then ALL of your records will change to R06 for the prefix in the new year
not just new ones because you are always using the current system date. You
need to be using the date that the record was created. Do you have such a
field?

If your table included a field named CreateDate then your query expression would
be...

ResponseNo: "R" & Format(CreateDate(),"yy") & "-" & Format([PONum],"000")

...(eliminating the unnecessary Right() function)

Then your DMax assignment changes to...

=Nz(DMax("[PONum]","[PO Table]", "CreateDate >= DateSerial(Year(Date()), 1,
1)"), 0)+1

Now instead of finding the highest number in the table and adding one to it, the
expression finds the highest number from only those records created in the
current year. The Nz() wrapper is required for the very first entry of any
given year since DMax() will return Null in that circumstance.


If I may tack on...

I've had similar cases where clients want to number their files or
responses or whatever, in the format yy/nnn. When I ask why, the
reason is always so they know how many are in that year. Of course, a
simple query can always give that answer. So I always try to change
clients to accepting a simple sequential numbering system.

Where I can't convince them, I would do something like Rick has
suggested but put this in the Default value of the control, thereby
generating the number when the record is created and maintaining it
in subsequent edits by locking the field.

P
Dec 31 '05 #10
Peter Sutton wrote:
If I may tack on...

I've had similar cases where clients want to number their files or
responses or whatever, in the format yy/nnn. When I ask why, the
reason is always so they know how many are in that year. Of course, a
simple query can always give that answer. So I always try to change
clients to accepting a simple sequential numbering system.

Where I can't convince them, I would do something like Rick has
suggested but put this in the Default value of the control, thereby
generating the number when the record is created and maintaining it
in subsequent edits by locking the field.


Actually using the DefaultValue property for this is a poor choice in a
multi-user system as it allows mutliple users to grab the same value if they
both start records before either one saves. Also it won't work at all in a
continuous form.

Assigning the value in the BeforeUpdate event is the best place to prevent
collisions.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Dec 31 '05 #11
On Sat, 31 Dec 2005 05:40:52 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote:
Peter Sutton wrote:
If I may tack on...

I've had similar cases where clients want to number their files or
responses or whatever, in the format yy/nnn. When I ask why, the
reason is always so they know how many are in that year. Of course, a
simple query can always give that answer. So I always try to change
clients to accepting a simple sequential numbering system.

Where I can't convince them, I would do something like Rick has
suggested but put this in the Default value of the control, thereby
generating the number when the record is created and maintaining it
in subsequent edits by locking the field.


Actually using the DefaultValue property for this is a poor choice in a
multi-user system as it allows mutliple users to grab the same value if they
both start records before either one saves. Also it won't work at all in a
continuous form.

Assigning the value in the BeforeUpdate event is the best place to prevent
collisions.


True what you say about collisions.

In the few cases, I've had like this, users want to see the allocated
number at the start of the process and with not a lot of users adding
records infrequently, I put a check in the BeforeUpdate event to check
and fix any collisions.

Horses for courses I guess.

P
Jan 1 '06 #12
Kd
Rick
Thanks for all your help first of all
I changed this as you sugested and even changed my table field from
OrderDate to
CreateDate
When I put
ResponseNo: "R" & Format(CreateDate(),"yy") & "-" &
Format([PONum],"000")
I get undefined function'CreateDate' in expression
What am I doing wrong
Ken

Jan 2 '06 #13
Kd wrote:
Rick
Thanks for all your help first of all
I changed this as you sugested and even changed my table field from
OrderDate to
CreateDate
When I put
ResponseNo: "R" & Format(CreateDate(),"yy") & "-" &
Format([PONum],"000")
I get undefined function'CreateDate' in expression
What am I doing wrong
Ken


CreateDate (being the name of a field and not a function) should not have ()
after it.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 2 '06 #14
Kd
Thanks
That worked
now all I have to do is get PONum to reset to 001
deleted all records from last year except 5 and
new PONum forr 2006 came out R06-006

Jan 2 '06 #15
Kd
think I have tried
Then your DMax assignment changes to...
=Nz(DMax("[PONum]","[PO Table]", "CreateDate >=
DateSerial(Year(Date()), 1,
1)"), 0)+1
everywhere i can think of on before update events
still cant get number to set to R06-001

Jan 2 '06 #16
Kd wrote:
think I have tried
Then your DMax assignment changes to...
=Nz(DMax("[PONum]","[PO Table]", "CreateDate >=
DateSerial(Year(Date()), 1,
1)"), 0)+1
everywhere i can think of on before update events
still cant get number to set to R06-001


Did you try the BeforeUpdate event of the form?

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 2 '06 #17
Kd
yes i did

Jan 2 '06 #18
Kd wrote:
yes i did


And what do you get? The expression is using Nz() so when there are no records
yet created in the year 2006 the DMax() will return Null and then the Nz()
pretty much HAS to return zero to which we add 1. There is not much that can go
wrong with that.

Just to clarify...the DMax() statement will only produce the incrementing PONum.
It will not give you a result that looks like "R06-001". You use a default
value of Now() or Date() for the CreateDate, and you assign the value of PONum
in the BeforeUpdate event of the form using the DMax() expression. It is only
AFTER the record has been created that you can use your Format() expression to
give you the "R06-001" output.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 2 '06 #19
Kd
Well I am gonna learn a lot of paitence working with this stuff
cleaned out table have 3 fields
PoNum - lng int
Create Date - short Date default Date()
Customer -Text

Query
PoNum
Create Date
Customer
ResponseNo: "R" & Format(CreateDate(),"yy") & "-" &
Format([PONum],"000")
Form
PONum default value=DMax("[PONum]","[PO Table]")+1
CreateDate default value date()
Customer
ResponseNo
BeforeUpDate on form
=Nz(DMax("[PONum]","[PO Table]", "CreateDate >=
DateSerial(Year(Date()), 1,
1)"), 0)+1

I am sure I have something in wrong place
Any help is so appreceated
Ken

Jan 3 '06 #20
Kd wrote:
Well I am gonna learn a lot of paitence working with this stuff
cleaned out table have 3 fields
PoNum - lng int
Create Date - short Date default Date()
Customer -Text

Query
PoNum
Create Date
Customer
ResponseNo: "R" & Format(CreateDate(),"yy") & "-" &
Format([PONum],"000")
Form
PONum default value=DMax("[PONum]","[PO Table]")+1
CreateDate default value date()
Customer
ResponseNo
BeforeUpDate on form
=Nz(DMax("[PONum]","[PO Table]", "CreateDate >=
DateSerial(Year(Date()), 1,
1)"), 0)+1

I am sure I have something in wrong place
Any help is so appreceated
Ken


Get rid of the default value on PONum. That is what the BeforeUpdate event is
for and besides the default value you are using won't start over each year the
way the BeforeUpdate code will.

The DMax expression doesn't go into the BeforeUpdate property box. What you
enter there is "[Event Procedure]" (without the quotes) and then you press the
builder button [...] to the right of the box which will take you to the VBA code
window for your form. THAT is where the DMax statement goes. You should find
your cursor pre-positioned between two lines of VBA code that marks the start
and end of the BeforeUpdate sub-routine. Your DMax() statement goes between
those two lines.

Lastly your DMax statement is incorrect because the value it retrieves needs to
be assigned to the PONum field. You should have (in the VBA code window)...

If IsNull(Me!PONum) Then
Me!PONum = Nz(DMax("[PONum]","[PO Table]", "CreateDate >=
DateSerial(Year(Date()), 1, 1)"), 0)+1
End If

The reason for the IsNull Test is that the BeforeUpdate event can fire multiple
times for a given record. You only want to assign the the PONum value the very
first time the record is saved (at which point PONum will still be null). There
are other form events that only fire once per record, but they are either
unreliable or allow more chances for two users to grab the same value if you
ever have more than one person entering records.

So to recap...

When you start to create a new record PONum will be Null, CreateDate will
default to the current date, and ResponseNo will be Null (because PONum is still
Null). As soon as you save the record the BeforeUpdate will calculate the
proper PONum value and assign it to the PONum field just before the save occurs.
Afterwards both PONumn and ResponseNo shoud be populated with the correct value.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Jan 3 '06 #21
Kd
Thank you very much
that was simple
I have one more question
last year when we started this
I used just a formatted number to be the R05-001
PoNumber
This was my primary key on the table
With this new approach what would you suggest for a Pk for this table?
Thanks again
Ken

Jan 3 '06 #22
Kd wrote:
Thank you very much
that was simple
I have one more question
last year when we started this
I used just a formatted number to be the R05-001
PoNumber
This was my primary key on the table
With this new approach what would you suggest for a Pk for this
table? Thanks again
Ken


I would use a composite key consisting of both CreateDate and PONum.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 3 '06 #23

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

Similar topics

0
by: Earl Anderson | last post by:
KB Article Q140908 provided the following function to create an Auto Incrementing Counter: Function Next_Custom_Counter () On Error GoTo Next_Custom_Counter_Err Dim MyDB As Database Dim...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
6
by: Kd | last post by:
I have the OrderNo set as the following Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") & "-"Format(,"000")+1 This works great until I get to a new month and need the numbers to reset like...
2
by: junkaccount | last post by:
Hello, I currently have a field named QuoteNumber in a table named Quotes. The field is set as autonumber and is used to assign sequential numbers as users enter information in the table through...
11
by: cansnowboard | last post by:
I built a file management database which generates a file number based on the year. i.e. 2006-PRRS-13 The criteria was that each file should be unique. So I took the primary key, added one to...
3
by: cassey14 | last post by:
Hi Guys... Im doing a system and it really make my head ache..i hope somebody help me.. I need to have an id like this "ABCD-07-000001"... I dont know how will I work on that thing.. ABCD...
2
by: DeanO | last post by:
I am trying to set my autonumber field to reset automatically at the beginning of each new year. This is a three digit field and is used with the date for a report number field. The number is...
1
by: medic3212 | last post by:
Greatings, I am a vbs newbie, about two months of class. I am working on a dispatching program which uses an incrementing call number. The call number is made up of two separate parts, the...
2
by: joegood | last post by:
Hello All First of all I am an access newbie and I am looking for a bit of help on this. I have looked at other similar articles but I a failing in my implementation. I have an number...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.