Results 1 to 15 of 15
  1. #1
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142

    Holidays Restriction to Users


    Hello Everyone
    How do I send a warning message to the users inputting data for the holidays date.

    Do I have to create a table that lists the holiday dates?

    And I have to make a restriction from weekending date.
    So when the user chooses the weekending date (Usually a Friday).
    If the holiday date falls between the weekending date.
    A warning message should be displayed.
    Attached Thumbnails Attached Thumbnails Capture.PNG  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    A Holidays table probably best. I have seen a thread that discussed code to calculate any holiday but can't find it again.

    Code can do a DLookup on Holidays table for record with date between the begin and end week dates.
    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
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I tried the below code:

    Code:
     If Forms!Create_New_Entry_F!WeekEndingBox = DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_F!WeekEndingBox, 0), "Short Date") & "#") Then
         MsgBox "Please note the holiday falling on this week"
       Me.WeekEndingBox.SetFocus
       Cancel = True
       End If
    This works well. How to check if holiday is falling within the week. When weekending is a Friday.




    Quote Originally Posted by June7 View Post
    A Holidays table probably best. I have seen a thread that discussed code to calculate any holiday but can't find it again.

    Code can do a DLookup on Holidays table for record with date between the begin and end week dates.

  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,848
    For consideration:
    Some logic along this line might be appropriate:
    Code:
    If HolidayDate between WeekEndingDate - 7 and WeekEndingDate
    
    then (there's a holiday this week)
        'Do something (change color, send message,......)
    else ( no holiday this week)
        'Do regular stuff
    End if

  5. #5
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    In order to know the holiday list , I have created a holiday Table which contains the list of holidays.
    Or Do I have to mention all the 8 federal holidays? Not sure how to proceed with your option


    Quote Originally Posted by orange View Post
    For consideration:
    Some logic along this line might be appropriate:
    Code:
    If HolidayDate between WeekEndingDate - 7 and WeekEndingDate
    
    then (there's a holiday this week)
        'Do something (change color, send message,......)
    else ( no holiday this week)
        'Do regular stuff
    End if

  6. #6
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I created a start date (Monday) and the end date as the weekending date Friday.
    And used this code:

    Code:
    If Forms!Create_New_Entry_Menu_F!WeekendingCmbo >= DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_Menu_F!WeekendingCmbo, 0), "Short Date") & "#") And Forms!Create_New_Entry_Menu_F!Text32 <= DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_Menu_F!Text32, 0), "Short Date") & "#") Then
         MsgBox "Please note the holiday falling on this week"
       Me.WeekendingCmbo.SetFocus
       Cancel = True
       End If
    This one doesn't show any error. Even though I have kept the weekending date 9/14/2018 as holiday in the holiday table.



    Quote Originally Posted by June7 View Post
    A Holidays table probably best. I have seen a thread that discussed code to calculate any holiday but can't find it again.

    Code can do a DLookup on Holidays table for record with date between the begin and end week dates.

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    You're only concerned about holidays falling on a weekday? Not the weekends?

  8. #8
    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,848
    You need some code/vba to invoke some logic to determine if a holiday or holidays exist within the week displayed on your form.
    I suggest you work with the underlying tables (your calendar and your holidays).

    There is an example of identifying Holidays, weekends and work days/business days in this thread that may be helpful.

  9. #9
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much. I will look into that.

    Quote Originally Posted by orange View Post
    You need some code/vba to invoke some logic to determine if a holiday or holidays exist within the week displayed on your form.
    I suggest you work with the underlying tables (your calendar and your holidays).

    There is an example of identifying Holidays, weekends and work days/business days in this thread that may be helpful.

  10. #10
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    As of now, I am trying to send a warning message or as @orange suggested a color change to the holidays falling on the weekday.
    Quote Originally Posted by kd2017 View Post
    You're only concerned about holidays falling on a weekday? Not the weekends?

  11. #11
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    [edit - delete. that was bad. stay tuned.]

    The following query will try to find records's in a table called holidays that fall within the same week as an input date called [InputDate]

    Code:
    PARAMETERS InputDate DateTime;
    SELECT Holidays.Holiday, Holidays.HolidayDate
    FROM Holidays
    WHERE (((Holidays.HolidayDate)>=[InputDate]-Weekday([InputDate])+2) AND ((Holidays.HolidayDate)<[InputDate]-Weekday([InputDate])+7));
    Here's how you might use it in a generic function:
    Code:
    Public Function FindHolidayWeek(InputDate As Date) As Variant
    On Error GoTo ErrHandler
        Dim rs As DAO.Recordset
        Dim mon As Date
        Dim qry As String
        
        mon = InputDate - Weekday(InputDate) + 2
        
        qry = "SELECT Holidays.HolidayDate" & _
              " FROM Holidays" & _
              " WHERE Holidays.HolidayDate>=#" & mon & "# AND Holidays.HolidayDate<#" & (mon + 5) & "#;"
              
        Set rs = CurrentDb.OpenRecordset(qry)
            If Not (rs.BOF And rs.EOF) Then
                FindHolidayWeek = rs!HolidayDate
            Else
                FindHolidayWeek = Null
            End If
        rs.Close
        
    ExitHandler:
        Set rs = Nothing
        Exit Function
        
    ErrHandler:
        MsgBox "Error"
        FindHolidayWeek = Err
        Resume ExitHandler
    End Function
    And you could call it from a textbox's BeforeUpdate event like so:
    Code:
    Private Sub txtInputDate_BeforeUpdate(Cancel As Integer)
        Dim holiday As Variant
        holiday = FindHolidayWeek(Me.txtInputDate)
        
        If Not IsNull(holiday) Then
            MsgBox "The input date is in the same week as a holiday on " & holiday & "."
        End If
    End Sub

  12. #12
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Right now. I am using the below code. It works. Its just a temporary solution. But I am trying to read your thread and build that later. Thank you so much for the info.
    Code:
    If Text284 = DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_F!Text284, 0), "Short Date") & "#") Then
       Monday.BackColor = vbRed
      
       Else
      Monday.BackColor = vbWhite
       End If


    Quote Originally Posted by orange View Post
    You need some code/vba to invoke some logic to determine if a holiday or holidays exist within the week displayed on your form.
    I suggest you work with the underlying tables (your calendar and your holidays).

    There is an example of identifying Holidays, weekends and work days/business days in this thread that may be helpful.

  13. #13
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much for the update. I will try this one too.

    Quote Originally Posted by kd2017 View Post
    [edit - delete. that was bad. stay tuned.]

    The following query will try to find records's in a table called holidays that fall within the same week as an input date called [InputDate]

    Code:
    PARAMETERS InputDate DateTime;
    SELECT Holidays.Holiday, Holidays.HolidayDate
    FROM Holidays
    WHERE (((Holidays.HolidayDate)>=[InputDate]-Weekday([InputDate])+2) AND ((Holidays.HolidayDate)<[InputDate]-Weekday([InputDate])+7));
    Here's how you might use it in a generic function:
    Code:
    Public Function FindHolidayWeek(InputDate As Date) As Variant
    On Error GoTo ErrHandler
        Dim rs As DAO.Recordset
        Dim mon As Date
        Dim qry As String
        
        mon = InputDate - Weekday(InputDate) + 2
        
        qry = "SELECT Holidays.HolidayDate" & _
              " FROM Holidays" & _
              " WHERE Holidays.HolidayDate>=#" & mon & "# AND Holidays.HolidayDate<#" & (mon + 5) & "#;"
              
        Set rs = CurrentDb.OpenRecordset(qry)
            If Not (rs.BOF And rs.EOF) Then
                FindHolidayWeek = rs!HolidayDate
            Else
                FindHolidayWeek = Null
            End If
        rs.Close
        
    ExitHandler:
        Set rs = Nothing
        Exit Function
        
    ErrHandler:
        MsgBox "Error"
        FindHolidayWeek = Err
        Resume ExitHandler
    End Function
    And you could call it from a textbox's BeforeUpdate event like so:
    Code:
    Private Sub txtInputDate_BeforeUpdate(Cancel As Integer)
        Dim holiday As Variant
        holiday = FindHolidayWeek(Me.txtInputDate)
        
        If Not IsNull(holiday) Then
            MsgBox "The input date is in the same week as a holiday on " & holiday & "."
        End If
    End Sub

  14. #14
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I have one more question in this:
    The below query I am trying to give a warning message when user enters values greater than zero on a text box, based on the date value.
    Its checking the date criteria but even if I enter 0, it still throws the message.
    What is the problem here.?


    Code:
    Private Sub Monday_Change()
    If Text284.Value > 0 And Text284 = DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_F!Text284, 0), "Short Date") & "#") Then
        MsgBox "Please note this day is a holiday. Do you still want to charge on this day? "
      Me.Monday.SetFocus
       Cancel = True
       End If
    End Sub

  15. #15
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    Thank you so much for the inputs.
    I have taken the below code and its working.
    I have created a holiday table. and Dlookup the values to it.

    Orange and kd2017 thread are worth reading . Because of time constraint I am using the below code.


    Code:
    Private Sub Monday_AfterUpdate()
    Dim LResponse As Integer
     
    If Monday.Value > 0 And Text284 = DLookup("[HolidayDate]", "Holiday_T", "HolidayDate = #" & Format(Nz(Forms!Create_New_Entry_F!Text284, 0), "Short Date") & "#") Then
    LResponse = MsgBox("Please note this day is a holiday. Do you still want to charge on this day? ", vbYesNo, "CONTINUE")
    If LResponse = vbYes Then
    Me.Monday.SetFocus
    Else
    Me.Monday.Value = 0
    End If
       End If
    End Sub

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

Similar Threads

  1. ComBo Box Restriction
    By Shamli in forum Access
    Replies: 14
    Last Post: 09-11-2018, 10:03 AM
  2. InPut restriction
    By wal in forum Access
    Replies: 4
    Last Post: 09-16-2015, 09:23 AM
  3. Replies: 1
    Last Post: 03-06-2013, 02:15 PM
  4. Field Restriction
    By nils@dslextreme.com in forum Forms
    Replies: 1
    Last Post: 03-06-2012, 07:48 PM
  5. Filtering restriction on tables
    By pcasper in forum Access
    Replies: 3
    Last Post: 02-15-2012, 12:19 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