Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    ukmale65000 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    31
    Ok week 1 will be 6th april to 12th april week 2 will be 13th april to 19th april and so on. The final week 52 or 53 depending on how many days are left. The final week ending on the 5th april may have anything between 1 and seven days.
    Sorry if that makes things difficult.

  2. #17
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    That method will break within 5 years. If that is what you are after your formula will be to determine the difference in days and divide by 7. You could probably accomplish this in one line of code.

  3. #18
    ukmale65000 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    31
    5 years would be long enough

  4. #19
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I have not tested this out past leap year. It seems to be working. I did not test it extensively.

    DateDiff.zip

    This DB has one form with three text boxes and a control button. It analyzes two dates. It uses the first date as the beginning of a period. It determines which period the second date falls into. Each period is equal to seven days.

    Here is the code if anyone cares to critique it. It seems access does not offer built in symmetrical rounding so I used a function off of microsoft's KB.

    Code:
       Function SymUp(ByVal X As Double, _
                Optional ByVal Factor As Double = 1) As Double
                
       Dim Temp As Double
       
         Temp = Fix(X * Factor)
         SymUp = (Temp + IIf(X = Temp, 0, Sgn(X))) / Factor
         
       End Function
    
    'Evalute two dates and determine the period
    'the second date falls within where seven
    'days equals one period
    
    Private Sub cmdDateDiff_Click()
    
    Dim dtOne As Date
    Dim dtTwo As Date
    Dim intAnswer As Integer
    Dim sglMath As Single
    Dim intRound As Integer
    
    dtOne = Me.txtOne.Value
    dtTwo = Me.txtTwo.Value
    
    intAnswer = DateDiff("d", dtOne, dtTwo) 'Count the number of days
    intAnswer = intAnswer + 1  'Add the evaluation date back into the equation
    
    sglMath = intAnswer / 7 'Measure days in units of 7
    
    intRound = SymUp(sglMath) 'Round any fraction symmetrically
    
    Me.txtAnswer.Value = intRound
    
    End Sub

  5. #20
    ukmale65000 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Oct 2013
    Posts
    31
    Thanks for all your help i will try and incorporate this into my database, one more question and i may have to open a new thread for this but is it possible to create a report in a style where the user could have sort tabs along the top like those found when you run a query,and be able to click on any record and have it take you to the initial input form that the record was created on ?
    Im not asking you to do any work for me just asking if this is possible ?

  6. #21
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    It is possible with newer versions of Access. It will require coding in VBA. It may be easier to do in a form vs. a report. You can lock down edit capabilities in a form. Forms in DS view have shortcut menus and search options built in that may do what you need.

    As for the code pasted here... It is relatively copy/paste friendly. The top portion is a function. You will want to paste the entire function into a module. The other code you want to paste the sub into your own sub procedure. Create a sub for a control's event and THEN paste the code, minus the first and last line.

    Of course, you will have to adjust names of controls, etc for the sub. Just be sure to paste the function as an entire function.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Converting Dates into week numbers (custom)
    By Bleep-Blop in forum Programming
    Replies: 5
    Last Post: 10-04-2013, 03:29 PM
  2. Replies: 3
    Last Post: 09-19-2013, 10:18 AM
  3. 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
  4. Replies: 1
    Last Post: 11-29-2011, 08:43 AM
  5. When Week Numbers Collide!
    By Schwagr in forum Queries
    Replies: 3
    Last Post: 03-18-2006, 10:06 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