Results 1 to 2 of 2
  1. #1
    lonesoac0 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Aug 2014
    Posts
    36

    Year variable in data macro

    Hello all, I have an after insert macro that I am working on. My code looks for the month and based on the month value, it sets a value for a variable. The only trouble is, is that the value set for my variable is static and not dynamic. Here is my code:


    ### Code Example ###


    Else if [user_info_table].[Current Date] Like "8/*/*" Then // This works great. It will find any august month with any date and year.
    SetLocalVar
    Name date_difference_variable
    Expression DateDiff('y',[user_info_table].[Current Date],#8/31/2014#) // This is the static value that i was talking about. I want the year to change dynamically based off of the current year.

    Else if [user_info_table].[Current Date] Like "9/*/*" Then // This works great. It will find any september month with any date and year.
    SetLocalVar
    Name date_difference_variable
    Expression DateDiff('y',[user_info_table].[Current Date], 9/30/[only_the_year]) // I tried to setup a variable that does what I want but I could not get it quite right.
    ### Code Example ###

    The function that i tried to use to create [only_the_year] with:
    =DatePart("yyyy",Now())

    What am I doing wrong?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I generally don't use macros and have never used Data Macro.

    Maybe (note the 'yyyy' - not 'y'):

    Expression DateDiff('yyyy', [user_info_table].[Current Date], "9/30/" & Year(Date()))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-21-2014, 02:15 PM
  2. Running macro once per year
    By wlkr.jk in forum Macros
    Replies: 4
    Last Post: 06-12-2014, 01:08 PM
  3. Dsum data between to dates for this year and last year
    By sdel_nevo in forum Programming
    Replies: 1
    Last Post: 06-13-2013, 06:48 AM
  4. Replies: 8
    Last Post: 12-05-2012, 07:24 PM
  5. variable returning 1990 for the year
    By TinaCa in forum Programming
    Replies: 3
    Last Post: 08-31-2011, 09:51 AM

Tags for this Thread

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