Results 1 to 8 of 8
  1. #1
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7

    VBA Date Problem

    I am having great difficulty trying to resolve this. WCCNF1 should turn to yes for previous dates in 2015 not 2016. I cant get it to work using -1. If Year = 2015 it should turn to Yes. Can anyone help me?
    If (Year(Nz([WCCClmDt1])) = Year(Date)()) Then


    WCCNF1 = "Yes"
    ElseIf (Year(Nz([WCCMRDt1])) = Year(Date)()) And _
    (Year(Nz([wccmrdtwgt])) = Year(Date)()) And _
    (Year(Nz([wccmrdthgt])) = Year(Date)()) Then
    WCCNF1 = "Yes"
    Else
    WCCNF1 = "No"
    End If

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Try using -1 and 0 instead of Yes and No.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    As mentioned elsewhere, your parentheses are goofed up:

    If Year(Nz([WCCClmDt1],0)) = Year(Date()) Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7
    Interestingly I got it to work using the code below. The problem was the same flag was programmed on another exit at the bottom of the form which I didnt realize. Why is it accepting the format of Year(Date) - 1) when this is not supposed to?

    If (Year(Nz([WCCClmDt1])) = Year(Date) - 1) Then
    WCCNF1 = "Yes"
    ElseIf (Year(Nz([WCCMRDt1])) = Year(Date) - 1) And _
    (Year(Nz([wccmrdtwgt])) = Year(Date) - 1) And _
    (Year(Nz([wccmrdthgt])) = Year(Date) - 1) Then
    WCCNF1 = "Yes"
    Else

  5. #5
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7
    It would take it in that formart

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Again, your parentheses were goofed up originally.

    Also:

    cross posters
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    JMichael is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    7
    OK. Dully noted was unaware of that. Thanks for your response. My method did end up working.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 09-02-2015, 11:39 AM
  2. Start Date and End Date problem
    By abulfouz in forum Programming
    Replies: 5
    Last Post: 10-05-2014, 05:39 PM
  3. Date Problem
    By Christopher.Rohde in forum Programming
    Replies: 3
    Last Post: 03-07-2013, 08:38 AM
  4. Date problem
    By mohiahmed in forum Queries
    Replies: 8
    Last Post: 01-21-2012, 11:28 AM
  5. Problem With Date
    By jlg759 in forum Programming
    Replies: 6
    Last Post: 07-02-2010, 12:40 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