Results 1 to 4 of 4
  1. #1
    jdanieluk is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    22

    Date Loop Until Not Ending

    Hello,
    I am having issues with this date loop and cant figure out why. I am sure I am missing something.

    I have two dates, one start and one end. I'm using DateDiff to get the amount of months between the start and end dates. The loop increments the start date every 3 months. Once iMos gets above 3 months it should stop the loop. iMos is not changing value when the loop updates the start date. iMos stays at 2.

    I have also tried Do While and the same thing happens with the value of iMos not changing.



    Code:
    Private Sub btn_Test_Click()
    Dim dStart As Date
    Dim dEnd As Date
    Dim iMos As Integer
    
    dStart = CDate(Format("01/17/2020", "mm/dd/yyyy"))
    dEnd = CDate(Format("11/01/2019", "mm/dd/yyyy"))
    iMos = DateDiff("m", dEnd, dStart)
    
    Do
        dStart = DateAdd("m", 3, dStart)
        'Debug.Print dStart
    Loop Until iMos >= 3
    
    End Sub
    MS Access 2013
    .accdb

    Thanks for all the help in advance.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    You are not changing the value of iMos within your loop, so no comparison,no stopping the loop.
    You may want to move the Do to before the
    iMos = DateDiff("m", dEnd, dStart)

  3. #3
    jdanieluk is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    22
    uuummm. LOL I see that now. Think I have been staring at this screen for too long. cut, paste, working. Thank you.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    You're welcome. Good luck with your project.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2018, 06:34 PM
  2. Ending my if statements
    By UT227 in forum Programming
    Replies: 3
    Last Post: 05-25-2018, 10:19 AM
  3. Log In Ending
    By GCLIFTON in forum Access
    Replies: 10
    Last Post: 06-02-2016, 11:12 AM
  4. Replies: 9
    Last Post: 06-19-2015, 03:37 PM
  5. Replies: 1
    Last Post: 11-15-2014, 12:23 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