Results 1 to 4 of 4
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    Calculate fiscal year, something wrong in code

    I am trying to update the data for [fiscalyear] based on the [DateStart] of an event.



    Here's my current code. Fiscal year rolls over in October.

    Code:
    IF(Month([me.DateStart])>9) then
     me.FiscalYear=(Year([me.DateStart])+1))
     Else
      me.fiscalyear=(Year([me.DateStart])
    EndIf
    I've tried putting this in an 'afterupdate' event, no luck. It errors and highlights the me.FiscalYear=(Year([me.DateStart])+1)) part.

    What am I doing wrong?


    EDIT: Found code that works not using the IF command

    Code:
    Me.FiscalYear = Year(DateAdd("m", 2, DateStart))
    Still curious why the if version of the code didn't work.

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    try
    me.fiscalyear=(Year(Me.datestart)+1)
    or
    me.fiscalyear=(year(me!datestart)+1)

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    heres a function...

    Code:
    Public Function FinancialYear(dtmDate As Date)
    
    
        Dim fyr As String
        fyr = "6/30/" & Year(dtmDate)    'set month and day to the last day of fiscal year
    
    
        If dtmDate > DateValue(fyr) Then
            FinancialYear = Year(dtmDate) + 1
        Else
            FinancialYear = Year(dtmDate)
        End If
    
    
        'Debug.Print FinancialYear
    
    
    End Function

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    securitywrym: Anything surrounded by square brackets is interpreted as a field name. If it's in a query field, it will prompt for a a criteria value for the field it's in. That is the difference between your 2 code examples. You were referencing a single field [me.fieldname] which doesn't exist. In fact, you don't need the brackets at all. Me.FieldName would be enough. Only if the field name (including control names) contains spaces, certain other special characters, or starts with a number would you need them. All of those situations should be avoided.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Fiscal Year Reset code
    By manics31 in forum Programming
    Replies: 8
    Last Post: 10-02-2017, 05:04 PM
  2. Crosstab Fiscal Year on Year Query
    By DJF in forum Queries
    Replies: 1
    Last Post: 02-07-2017, 09:27 AM
  3. Replies: 1
    Last Post: 10-14-2015, 03:45 PM
  4. New fiscal year dates
    By edieb in forum Programming
    Replies: 2
    Last Post: 05-13-2014, 08:42 AM
  5. fiscal year
    By RedGoneWILD in forum Programming
    Replies: 4
    Last Post: 08-04-2010, 01:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums