Monday

1

Solutions

15

Contributors

We're obsessed with building an excellent product, and our goal is to create a tool that people will love to use—one that’s fast, beautiful, responsive, and makes your life easier. The only thing we love more than our product is our customers. The incredible teams that use our product are the most important thing to us, and we're here to provide support to them 24/7.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi Experts,
I had asked a question about First Monday & Third Monday of the week couple week ago and Expert Gustav Brock gave me the Public Function which works but when I tried to place to another form, it does not work as it suppose.  I know I did something wrong, but did not what I miss.  below is my code on a datefield:
Private Sub PDFIRSTCRTDATE_Exit(Cancel As Integer)
Dim DateInMonth As Date
DateInMonth = Date

    If Me.HoldCalA = "Cal 24" Or Me.HoldCalA = "Cal 42" Or Me.HoldCalA = "Cal 54" Then
       If Me.PDFIRSTCRTDATE = DateWeekdayInMonth(DateInMonth, 1, vbMonday) Or Me.PDFIRSTCRTDATE = DateWeekdayInMonth(DateInMonth, 3, vbMonday) Then
       Else
          MsgBox "You have schedule on the wrong Monday for the " & Me.HoldCalA & "."
       End If
    End If
  End Sub



Here is the Public Function from Gustav Brock:
' Calculates the date of the occurrence of Weekday in the month of DateInMonth.
'
' If Occurrence is 0 or negative, the first occurrence of Weekday in the month is assumed.
' If Occurrence is 5 or larger, the last occurrence of Weekday in the month is assumed.
'
' If Weekday is invalid or not specified, the weekday of DateInMonth is used.
'
' 2016-06-09. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function DateWeekdayInMonth( _
    ByVal DateInMonth As Date, _
    Optional ByVal Occurrence As Integer, _
    Optional ByVal Weekday As VbDayOfWeek = -1) _
    As Date
   
    Const DaysInWeek    As Integer = 7
   
    …
0

Monday

1

Solutions

15

Contributors

We're obsessed with building an excellent product, and our goal is to create a tool that people will love to use—one that’s fast, beautiful, responsive, and makes your life easier. The only thing we love more than our product is our customers. The incredible teams that use our product are the most important thing to us, and we're here to provide support to them 24/7.

Top Experts In
Monday
<
Overall
>