Results 1 to 7 of 7
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    coding 2 week periods

    Hey guys,

    For the last, um, forever, my company has been paying bonuses on a monthly basis. I have a program that, upon open, determines the date range to run a report. That report is then sent out to the respective branch managers, and the program closes itself. If the day is the first of the month, it runs the report for the entire last month. Otherwise it picks the to and from dates to be the first day of the month and yesterday, respectively. Here is the code that accomplishes that:

    Code:
    'Sets the to and from dates
    If DatePart("d", Date) = 1 Then
        datefrom = DateSerial(DatePart("yyyy", Date), DatePart("m", Date) - 1, 1)
        dateto = DateSerial(DatePart("yyyy", Date), DatePart("m", Date), 0)
    
    
        Else
        datefrom = DateSerial(DatePart("yyyy", Date), DatePart("m", Date), 1)
        dateto = DateSerial(DatePart("yyyy", Date), DatePart("m", Date), DatePart("d", Date) - 1)
    
    
    End If
    
    
    Forms![Montage Sales_gers]!fromdate = datefrom
    Forms![Montage Sales_gers]!todate = dateto
    Starting yesterday, the powers that be have decided to pay the bonuses out on a biweekly schedule. The periods will be a Monday thru the next Sunday, i.e. 1/5/15 - 1/18/15.

    I cannot figure out how to do this. Any thoughts?



    If you can even put me on the right track that would be perfect.

    Thanks guys!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Sounds like grounds for justifiable homicide - shoot the powers!

    So basically the odd number weeks can become the identifier for bi-weekly period. I did a quick experiment in query:

    SELECT DateField, DatePart("ww",[DateField]) AS Wk, [Wk]-IIf([Wk] Mod 2=0,1,0) AS BiWk FROM Table1;
    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.

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Ah definitely on to something with the week number.

    Messing around with the first day of the week, and first week of the year. You are right in having the odd numbers be the final week of the period. Doing this all in VBA, hopefully.

    Going to keep on playing around with this... I have until the 15th to get it done

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I did not use VBA, just calc in query.
    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.

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    I saw. I actually prefer to do this kind of stuff in VBA, usually. You're calc up there definitely pointed me in the right direction! Thanks for that!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Don't forget - will also need the year for selecting/aggregating records.
    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.

  7. #7
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    June7,

    This is what I have come up with for the dates. There will be DateFrom and DateTo. DateTo will always be yesterday. DateFrom is using the following code:
    Code:
    Public Function DateFrom(Today As Date) As Date
    
    
    'if Today is the first day of the pay period, then pull the entire last period
    If DatePart("ww", Today, vbMonday, vbFirstFullWeek) Mod 2 = 1 And _
        DatePart("w", Today, vbMonday, vbFirstFullWeek) = 1 Then
        DateFrom = Today - 14
    
    
    Else
    
    
    ' determine if current day is in 1st or 2nd week of pay period
    ' 1st weeks are odd, 2nd are even
    Dim DayMod As Integer
    If DatePart("ww", Today, vbMonday, vbFirstFullWeek) Mod 2 = 0 Then
        DayMod = 7
        Else
        DayMod = 0
    End If
    
    
    'determine how many days back you need to go to get to monday
    'of the first week in the pay period
    DayMod = DayMod + (DatePart("w", Today, vbMonday, vbFirstFullWeek) - 1)
    
    
    DateFrom = DateAdd("d", -1 * DayMod, Today)
    
    
    End If
    
    
    End Function
    Do you see any issues? Anything that could be done better or more efficiently? Testing the immediate window worked great.

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

Similar Threads

  1. Summarize data by pay periods
    By breakingme10 in forum Access
    Replies: 42
    Last Post: 01-13-2014, 08:28 AM
  2. Replies: 3
    Last Post: 09-19-2013, 10:18 AM
  3. Date range for pay periods
    By nhoover in forum Reports
    Replies: 5
    Last Post: 04-03-2013, 02:21 PM
  4. Start a report on week 40 of a week count
    By aspitalnick in forum Reports
    Replies: 8
    Last Post: 11-28-2012, 04:53 PM
  5. Change Financial Quater Periods
    By scorched9 in forum Access
    Replies: 0
    Last Post: 01-26-2010, 08: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