473,785 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Da te(),"yyyy"),2) & "-" &
Format([PONum],"000")
This is an expression in a query
any help is apprecieated
Ken

Dec 30 '05
22 5632
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(CreateDa te(),"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
5870
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 MyTable As Recordset Dim NextCounter As Long
5
5993
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 event is fired by one of the controls contained in the User Control, these variable are reset. Here is my current code (I have a little more to add later, right now I am just concerned about the variables getting reset): Public Class DatePicker2...
6
6019
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 the following example 512-001 Anybody have any thoughts to point me in the right direction,got stuck with making updates to someone elses created database and getting frustrated.
2
2752
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 a form. This number is mainly used later as reference when a customer calls our office with questions. We use the quote number to retrieve their related information through a query. This QuoteNumber field is NOT a primary key. It is not...
11
6191
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 it and moved on. Several months down the road they came back and said did we mention the file number needs to reset to zero each year. They click a button to generate the file number.
3
2976
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 always a default character..07 is the last two digit of the year and it should be reset everytime a year change..and the last six digit should be incremented by 1 everytime they add a new record but it should be reset when the year change..please help me...
2
2843
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 currently set to auto fill and looks like this 00/00/0000-000. I want the last three digits to reset with the new year date field. Both fields are hidden and combine in the report number text box.
1
1421
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 last two digits of the year, (which I have worked out), and an integer, “CallCount” i.e. 07 0115. The two are displayed in a separate text boxes. Each time a call is added, (the “AddCall” button clicked), the CallCount is increased by one. I need to...
2
1994
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 generated automatically using this code Private Sub Form_Dirty(Cancel As Integer) Me!.Value = (DMax("ReportID", "Reports") + 1) End Sub The number format is as follows BR then year(=Format(Date(),"""BR""yy")001
0
9489
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
10356
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
10100
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
9959
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
8988
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
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
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.