Results 1 to 3 of 3
  1. #1
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104

    VBA for calculating last month

    Hi all,



    New to the forum, but not to MS Access...
    Am trying to hit a command button, which will then return two dates, one date first of the month, second date, last of the month, regardless of what month. However, if today is 22 Sep 2014, and I click the button that says [LAST MONTH], I'd like to populate the two dates with 1-Aug-2014 and 31-Aug-2014. Is this feasible?

    thanks in anticipation
    DubCap01

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    IF you know current date, add 1 month, then subract 1 day

    Code:
    vDate = month(date()) & "/1/" & year(date())
    
       'next month range
    vLastDayOMo = DateAdd("d", -1, DateAdd("m", 1, vDate))
    
       'LAST month range
    vDate = DateAdd("m", -1, vDate))
    vLastDayOMo = DateAdd("d", -1, DateAdd("m", 1, vDate))

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is how you can calculate those dates:

    StartOfLastMonth: DateSerial(Year(Date), Month(Date) - 1, 1)
    EndOfLastMonth: DateSerial(Year(Date), Month(Date), 1) - 1

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

Similar Threads

  1. Replies: 43
    Last Post: 08-06-2014, 08:21 PM
  2. Replies: 5
    Last Post: 06-17-2014, 12:11 AM
  3. Replies: 6
    Last Post: 05-05-2014, 10:51 PM
  4. Replies: 4
    Last Post: 05-26-2013, 03:28 PM
  5. Replies: 14
    Last Post: 06-20-2012, 08:54 AM

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