473,386 Members | 1,766 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,386 software developers and data experts.

How do I generate a record number based on fiscal year?

Hello,
I would like to create a record number that is based upon the fiscal year and automatically advances... Something like: 2015001, 2015002, 2015003, 2015004; 2016001, 2016002, etc.
I already have a [FiscalYr] field (calculated data type) in my table [Projects] based upon the following expression: IIf(Month([EntryDate])>=10,Year([EntryDate])+1,Year([EntryDate])). The [EntryDate] field is a Date/Time field with a default value of Date(). This is working as I would like it to.
Is there I way I can take that [FiscalYr] number and put it on the front of a 3-digit number that starts with 001 and increments by 1 based upon the previous record, with the number re-setting to 001 at the start of each new fiscal year? Our fiscal year starts on October 1 and ends on September 30.
I want the number to be generated whether the information is entered in the table [Projects] or the form [Projects Form]. I don't want it to only generate if info is entered in the form. I saw some posts online suggesting the best way to do something like this would be to use a Before Change macro, but most of the examples I can find base a significant part of their macro code on a date, and I’ve already gotten the date issue sorted out (I think).
I would be fine with a macro that both created the Fiscal Year from the [EntryDate] and created the number at the same time, if that is easier than working with my existing [FiscalYr] field. I am only a casual Access user, so if I’m speaking gibberish I am so sorry – I think I know just enough to be dangerous.
Many thanks,
Andrea
Dec 7 '15 #1
9 1827
zmbd
5,501 Expert Mod 4TB
anmarse:
Please do a search here on bytes.com
This question is a perennial favorite. ;-)
(yes, pun intended :) )

Here's two threads to get you started:
Key words:
Serial numbers, sequence numbers, year

To get you started here two: http://bytes.com/topic/access/answer...increments-one
NeoPa's suggestion in Post#6 is a very good one to use.

Here's another thread that should point you in the right direction:
http://bytes.com/topic/access/answer...-serial-number

Here's just using the terms: "MS Access" "serial numbers":
https://bytes.com/searchresults.php?...ers&gsc.page=1
Dec 8 '15 #2
Update 12/9/2015:

I have given up on the macro idea.

Using the tips on Scottgem's blog (https://scottgem.wordpress.com/2009/...ial-numbering/), I have been able to get a sequential numbering system up and running, but I am still struggling mightily with getting the number to re-set to 1 at the start of a new fiscal year. I am not sure if the problem is how I'm generating my fiscal year value, or something else entirely.

Here's what I've got:

Table Name: Projects

Within Projects, I have the following fields related to this issue:

ProjectNo: number - long integer

Sequence: number - long integer

EntryFiscalYr: calculated - long integer; expression reads as follows:
Expand|Select|Wrap|Line Numbers
  1. IIf(Month([EntryDate])>=10
  2.     ,Year([EntryDate])+1
  3.     ,Year([EntryDate]))

EntryDate: date/time; default value: Date()

Form Name: Projects Form

Within my Projects Form, I have the following controls:

Sequence: text box,
control source is Sequence field in Projects table,
set to not visible

CreateProjNo: button,
event on click:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CreateProjNo_Click() 
  2.    Me.Sequence = Nz(DMax("[Sequence]", _
  3.       "Projects"), 0) + 1 
  4.    DoCmd.RunCommand acCmdSaveRecord 
  5. End Sub
ProjectNo: text box,
data control source:
=[EntryFiscalYr] & Format([Sequence],"000")
This is displaying as I would like it to: 2016001, 2016002, etc.

I have tried various iterations of the codes on Scottgem's blog to bring the EntryFiscalYr field into the DMax statement to look and see if the Sequence number should continue incrementing for the current fiscal year or start over for the new fiscal year, but none of my attempts are working.

I have tried:

Expand|Select|Wrap|Line Numbers
  1. Me.Sequence = _
  2.   Nz(DMax(“[Sequence]”, ”Projects”, _
  3.     ”[EntryFiscalYr]) = “ & _
  4.     (Me.[EntryFiscalYr])),0)+1
Expand|Select|Wrap|Line Numbers
  1. Me.Sequence = Nz(DMax(“[Sequence]”, _
  2.     ”Projects”, ” [EntryFiscalYr] = ‘“ & _
  3.     Me.[EntryFiscalYr] & “’”),0)+1
I have also tried with Me.[txtEntryFiscalYr] instead of Me.[EntryFiscalYr]. None of these attempts have worked.

I am guessing my issues might be due to how the EntryFiscalYr is generating for each record but I am clueless as to how to address this. I have tried with the date generated by EntryDate and that does a great job with the calendar year, but it is important to get this based on fiscal year and have it re-set at the start of each new fiscal year.

Also, the ProjectNo that is generated in the Projects Form is not updating to the ProjectNo field in the Projects table, but it is my understanding that this the point. Is this correct?

Any assistance in getting this to work correctly with the fiscal year would be greatly appreciated.

Thanks!
Dec 9 '15 #3
jforbes
1,107 Expert 1GB
I would approach this very similarly, but I would put the code to get the Next Key into a Function, kind of like this:
Expand|Select|Wrap|Line Numbers
  1. Public Function getNextKey() As String
  2.  
  3.     Dim sLastKey As String
  4.     Dim iCurrentYear As Integer
  5.     Dim iNextSequence As Integer
  6.  
  7.     iCurrentYear = Year(Now)
  8.     If Month(Now) >= 10 Then iCurrentYear = iCurrentYear + 1
  9.     sLastKey = Nz(DMax("Sequence", "Projects", "Sequence LIKE '" & iCurrentYear & "*'"), "")
  10.     If Len(sLastKey) = 0 Then
  11.         iNextSequence = 1
  12.     Else
  13.         iNextSequence = Val(Right(sLastKey, 3)) + 1
  14.     End If
  15.     getNextKey = iCurrentYear & Right("00000" & iNextSequence, 3)
  16.  
  17. End Function
Then set the Default property of your Sequence field to:
Expand|Select|Wrap|Line Numbers
  1. =getNextKey()
Then whenever you end up on a New Record, the Sequence will default to the Next Key.
Dec 9 '15 #4
NeoPa
32,556 Expert Mod 16PB
To help with this question, and because this type of question comes up fairly regularly, I've just written an Insight article for it (Item Numbering Within a Group).

I hope it helps.
Dec 10 '15 #5
The fiscal year is still the part that is hanging me up. Thank you.

** Moved from article thread **
Could you give an example of how instead of Date() you could use a fiscal year? Where and how should the fiscal year be generated? For example, Microsoft has provided the code I've pasted below (found at: https://support.microsoft.com/en-us/kb/210249). How would someone go about combining this with what you have provided? This seems to be the hangup in a number of similar threads. Getting this to work with today's date is relatively easy. Getting it to work with a fiscal year seems to be the difficult part. Thanks!

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Const FMonthStart = 10   ' Numeric value representing the first month
  3.                         ' of the fiscal year.
  4. Const FDayStart = 1    ' Numeric value representing the first day of
  5.                         ' the fiscal year.
  6. Const FYearOffset = -1  ' 0 means the fiscal year starts in the
  7.                         ' current calendar year.
  8.                         ' -1 means the fiscal year starts in the
  9.                         ' previous calendar year.
  10.  
  11. Type the following procedure:
  12.  
  13. Function GetFiscalYear(ByVal x As Variant)
  14.    If x < DateSerial(Year(x), FMonthStart, FDayStart) Then
  15.       GetFiscalYear = Year(x) - FYearOffset - 1
  16.    Else
  17.       GetFiscalYear = Year(x) - FYearOffset
  18.    End If
  19. End Function
Dec 10 '15 #6
NeoPa
32,556 Expert Mod 16PB
Hi Andrea.

I've updated the article for you. The change was fairly minimal but it did require changing the formatting due to working with a simple numeric value rather than a date value.

Do you find that the code you have there from Microsoft (Typical of their standard examples I'm sorry to say.) works for you and produces the correct results? If it does then it really should be that simple.
Dec 10 '15 #7
Okay, I opened my table Projects in Design View and created a Module. I put the fiscal year code from Microsoft in Module 1 and tested in the Immediate window with the following code:

Expand|Select|Wrap|Line Numbers
  1. ?GetFiscalYear(#m/d/yyyy#)
It returned the correct fiscal year values with every date I tried.

Now my understanding is that I create a new table (I'll name mine FYNumber) with the following:
Field Name: ID
Data Type: Short Text (10)
Description: 'Laid out as "{Year}-nnn" where nnn is a sequential number within the year
Is description the appropriate place to put that line about the format?

After I do that, where do I put the code from your article? Should that be associated with my form? What event would it go with? And is there any way to control this so that it is generated by a button or has some other way to handle multiple users and avoid a traffic jam?

Thanks and I look forward to your response!
Dec 10 '15 #8
Thank you to everyone who contributed on this question. I sincerely appreciate the time you took to help me!

I was working on a couple different solutions in tandem and finally settled on a different one than suggested here, but I am bookmarking this in case I need to reference this in the future.

Thanks again!
Dec 10 '15 #9
NeoPa
32,556 Expert Mod 16PB
AnMarse:
After I do that, where do I put the code from your article? Should that be associated with my form? What event would it go with? And is there any way to control this so that it is generated by a button or has some other way to handle multiple users and avoid a traffic jam?
In case you still want an answer to this one, I would say that you put the code I have in the linked article into a general-purpose module somewhere in you project. It could be near to the one you got from Microsoft if you like. Just like that one, you'd call it from anywhere that you needed to determine what the next ID should be. There are a hundred and one different places it could be used depending on what you want to do with it. That scope is so broad it couldn't reasonably be covered here. That said, you'd want to call it from within a form that allowed you to add records to the table certainly.

I hope that helps.

-Ade.
Dec 11 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
1
by: MissiMaths | last post by:
This isn't really an access question as I can write the code myself(I hope) but need to know how the start of the financial year is worked out. If someone knows the rules or an algorithm, I would...
16
by: usenet | last post by:
I want to be able to use the record numbers of a sub-form, are they available anyhow in VB (Access 2003)? I want to use the sub-form record number as *part* of the primary key for the table...
2
by: JohnC | last post by:
This fantastic expression was posted by Duane Hookom. I have no idea how it works but it displays the fiscal year and quarter for FY starting on October 1. =Format$(DateAdd("q",1,),"\Qq...
1
by: rkohon | last post by:
Hello all, I am new to JavaScript and need some ideas, suggestions, or code snippets. I have a form which requires the end user to put in a date for required items. I need javascript function to...
4
by: Twobridge | last post by:
Hi I am trying to perform a search that will return records based on a fiscal year search of the bill_Date. The user gives the year then I want to search based on the fiscal year (July 1 - June...
4
by: ltazz | last post by:
How can i make it so that Access will Recognize the fiscal year 07 start at 1 oct 2006, and end 30 Sep 2007? i know its possible, however cant figure it out. Thanks for the help in advance you...
2
by: Nick McConnell | last post by:
I'm trying to query a table and pull all data for the current fiscal year. I'd like the query to work whenever it's pulled be it tomorrow or 3 years from now. I found an IF clause on this website...
6
by: anguyen | last post by:
Hello everyone, I want to generate a unique ID number for a test number field in the format NTN-YY-XXX where YY is the two digit of the year, and XXX is the sequential number. This number reset to...
4
by: kashish sinha | last post by:
have four forms namely file status , load file, reconciliation, and reports. Reconciliation form has 2list boxes.. namely fiscal year and fiscal month. In that we have to choose for eg say i chose...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.