Results 1 to 7 of 7
  1. #1
    RockChick's Avatar
    RockChick is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    2

    Help adding 3 UK working days (excluding weekends and bank holidays) to a form field please?

    Hi - I have never used a forum before so please forgive any newbie errors!

    I would like some help please. I have a Complaints database which I have inherited from a previous team, but I have managed to customise it to do what I require - all except one thing. I have a field which contains the date on which the complaint was received [ReceivedbyCCG]. I want to add three working days to this and to then populate another field [AcknowledgementDue]. I am not at all experienced in Access, and most of what I have done so far has been by trial and error, and google, but having looked at various threads I think I need to add some sort of code. I have no clue how or where to do this. I have created a table of all the dates for the next 4 years (excluding the weekends and bank holidays) as partially shown in the snippet below, which adds the three days, but then I am stuck. I have added a screen shot of the fields in orange below too. The ReceivedbyCCG date is added by the user, as is the AckSent date, and I just want to make the Acknowledgement due box populate with the additional 3 working days. I can make it work for actual days with =DateAdd("w",3,[ReceivedbyCCG]) but not for working days.
    Is there anyone who could explain in simple terms what I need to do and talk me through how I should do this please?


    Any assistance would be much appreciated.
    Thank You.
    RockChick
    Attached Thumbnails Attached Thumbnails Capture1.PNG   Capture2.PNG  

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    In spite of that excellent post I can't really tell what the problem is. It looks like your expression is adding 3 weeks, not 3 days but you didn't say what result you were getting. Is this one of the sources you looked at for this issue?
    https://stackoverflow.com/questions/...g-bank-holiday
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    @Micron, 'w' is weekday, not week.

    @Rockchick, This code works in a test setup. If you need a simplified db example, I can post that.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Sub ReceivedByCCG_AfterUpdate()
        Dim i As Long
        If (ReceivedByCCG & "") = "" Then Exit Sub
        For i = 3 To 6
        Debug.Print DateAdd("d", i, ReceivedByCCG)
            If DCount("*", "tblCalendar", "CalDate =#" & DateAdd("d", i, ReceivedByCCG) & "#") > 0 Then
                Me.[AcknowledgementDue] = DateAdd("d", i, [ReceivedByCCG])
                Exit For
            End If
        Next i
    End Sub

  4. #4
    RockChick's Avatar
    RockChick is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    2
    @davegri - thank you that looks great, and thank you for using the names I had used - that makes it so much easier to follow. Could you please explain where I need to add this code in please? Do I need to add it as an EventProcedure from the Field properties and then type into the VB window that appears? Sorry, I really have very little experience of this but am very willing to be guided, and appreciate the expertise available. :-)

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I guess when it comes to IIRC, I didn't. Can't say "If memory serves..." either.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by RockChick View Post
    @davegri - thank you that looks great, and thank you for using the names I had used - that makes it so much easier to follow. Could you please explain where I need to add this code in please? Do I need to add it as an EventProcedure from the Field properties and then type into the VB window that appears? Sorry, I really have very little experience of this but am very willing to be guided, and appreciate the expertise available. :-)
    That sounds right. And you don't need to type it in, copy/paste works from the screen here.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    I am attaching a module I have used for many years for working with dates, extract and import it in your database. Then you can start using the functions in conjunction with your own bank holiday table by providing the holiday array:
    Code:
    Dim rstData    As DAO.Recordset
    Dim v          As Variant
    
    
    Set rstData = CurrentDb.OpenRecordset("Select CalDate From tblCalendar Where CalDate >= #" & Me.AckSent & "#;")
    rstData.MoveLast
    rstData.MoveFirst  
    v = rstData.GetRows(rstData.RecordCount)
    
    Me.AcknowledgementDue=dhAddWorkDaysA(Me.AckSent,v)
    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 13
    Last Post: 02-12-2020, 04:13 PM
  2. Replies: 36
    Last Post: 05-10-2018, 02:02 PM
  3. Replies: 1
    Last Post: 06-10-2014, 02:32 PM
  4. Replies: 8
    Last Post: 10-20-2012, 11:25 AM
  5. Replies: 0
    Last Post: 04-01-2011, 09:12 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