Question

I am making a DTR, and on the Form_Load of this DTR, I want it to check for the current day date. When it reaches the 13th, 14th, 15th, 26th, 27th, 28th, 29th, or 30th day of the month, what I would want it to do is for it to pop-up a msgbox reminding the owner of its employee's salary. However, when I run my code, even if it does not match the day I want it to msgbox, it still message box. Example, if the current day is the 3rd of the month, it still pops up a msgbox. Here is my code. I did not use timer.

    Dim strDate As Integer
    If strDate = Format(Now, "d") = 13 Or 14 Or 15 Or 27 Or 28 Or 29 Or 30 Then
           'DatePart("d", Now)
             If MsgBox("Alert Edwin Jay Sandoval or Maria Consuelo regarding your salary!", vbCritical + vbOKOnly, "Salary") = vbOK Then
          MsgBox "Alert Edwin Jay Sandoval or Maria Consuelo regarding your salary!", vbCritical + vbOKOnly, "Salary"
    End If
End If

No correct solution

OTHER TIPS

You shouldn't use the Format function to get date components. Format is used to return a formatted string of the specified date. VB is doing you a favor by casting the string to an integer for your comparison. Use VB's Day(), Month(), or Year() functions to extract date components instead.

Dim intDay As Integer
intDay = Day(Date)

Select Case intDay
    Case 13 To 15, 26 To 30
        ' Match
    Case Else
        ' No Match
End Select

You're currently comparing the day just to 13, and the other terms are in your OR statement.

You'll need to do something like:

If (Format(Now, "d") = 13) Or (Format(Now, "d") = 14) _
Or (Format(Now, "d") = 15) Or (Format(Now, "d") = 27) _
Or (Format(Now, "d") = 28) Or (Format(Now, "d") = 29) _
Or (Format(Now, "d") = 30) Then
...

You should probably pull the day number out to a variable first though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top