Using an Expression to Get the Fiscal Year or Fiscal Month
NOTE: This section applies only to a Microsoft Access database (.mdb).
To get the fiscal year or fiscal month of a particular date by using anexpression, follow these steps:
Open the sample database Northwind.mdb.
Create the following new query based on the Orders table.
NOTE: In the following sample expressions, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating these sample expressions.
Run the query, and then scroll through the query datasheet. Note that the fiscal year and fiscal month appear for each record in the Orders table.
You can use the FYear and FMonth expressions in your database by modifying the Date field, the day and the month, to the appropriatevalues for your fiscal year. For example, if the fiscal year begins on 9/15of the current calendar year, you can modify the previous expressions asfollows:
Using Sample Functions to Get the Fiscal Year or Fiscal Month
NOTE: This section applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To get the fiscal year or fiscal month of a particular date by using user defined functions, follow these steps:
Create a module and type the following lines in the Declarations section:
Option ExplicitConst FMonthStart = 6 ' Numeric value representing the first month ' of the fiscal year.Const FDayStart = 16 ' Numeric value representing the first day of ' the fiscal year.Const FYearOffset = -1 ' 0 means the fiscal year starts in the ' current calendar year. ' -1 means the fiscal year starts in the ' previous calendar year.
Type the following two procedures:
Function GetFiscalYear(ByVal x As Variant) If x < DateSerial(Year(x), FMonthStart, FDayStart) Then GetFiscalYear = Year(x) - FYearOffset - 1 Else GetFiscalYear = Year(x) - FYearOffset End IfEnd Function
Function GetFiscalMonth(ByVal x As Variant) Dim m m = Month(x) - FMonthStart + 1 If Day(x) < FDayStart Then m = m - 1 If m < 1 Then m = m + 12 GetFiscalMonth = mEnd Function
To test these functions, type each of the following lines in the Immediate window, and then press ENTER after each one:
Note that this line returns the year 2000.
Note that this line returns the number 2. The 2 represents the second month in the fiscal year.
For more information about the DateSerial function, click Microsoft Access Help on the Help menu, type DateSerial, Day, Month, and Year function examples in the Office Assistant or the Answer Wizard, and then click Search to view the topic.