add ElseIf to exception the missing days (1 Viewer)

alwazeer

Registered User.
Local time
Yesterday, 17:29
Joined
Nov 9, 2011
Messages
36
Hi There
Hope You Are Good
in code below i need to add ElseIf to exception the missing days:

Code:
Function HolDateType(EmpNumF As Integer, d1 As Date) As String
'On Error Resume Next

    If OutOfDate = True Then Exit Function

    Dim rst As DAO.Recordset, SQL As String
    Dim d2 As Date

    d2 = d1
  
    
    If (Weekday(d1) = 6) Then
        HolDateType = WeekEnd
    ElseIf (Weekday(d1) = 7) Then HolDateType = WeekEnd
    '''[SIZE=4][COLOR=Red] I need ElseIf her [/COLOR][/SIZE]
    End If
    
    
    SQL = "SELECT * FROM MonthRep WHERE InputDate<=# " & Format(d2, "yyyy/mm/dd") & " #  AND Id=" & EmpNumF
    Set rst = CurrentDb.OpenRecordset(SQL)
    If rst.RecordCount > 0 Then
        
        For i = 1 To 31
            rst.FindFirst "InputDate=#" & Format(d2, "yyyy/mm/dd") & "#"
            If Not rst.NoMatch Then
                HolDateType = rst!InputText
            End If
       
       Next i
    
    End If
 

Ranman256

Well-known member
Local time
Yesterday, 20:29
Joined
Apr 9, 2015
Messages
4,337
Use SELECT CASE. (Not elseIf)
Code:
Select case Weekday(d1)
  Case 1
      'Event here
  Case 2
      'Event
   Case 3
End select
 

Minty

AWF VIP
Local time
Today, 01:29
Joined
Jul 26, 2013
Messages
10,371
Why not use
Code:
HolDateType = your default non weekend value
If (Weekday(d1) >= 6) Then HolDateType = WeekEnd
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:29
Joined
Aug 30, 2003
Messages
36,127
By the way, you don't need your ElseIf, you could do:

If (Weekday(d1) = 6) OR (Weekday(d1) = 7) Then
 

alwazeer

Registered User.
Local time
Yesterday, 17:29
Joined
Nov 9, 2011
Messages
36
Thanks for your replay
your nots are good but what i need is:
in the table InputDate the dates for example:
04/09/2016
05/09/2016
8/09/2016
=======
what i need is 6/09/2016 and 07/09/2016 empty

i use :
on the code
Code:
Const WeekEnd = "0", WorkDay = "+", holdy = ""
Code:
Select Case Weekday(d1)
   Case 6, 7
      HolDateType = WeekEnd
  
  ' her i need case to make messing dates (that in Holidays Table) empty

      HolDateType = holdy
End Select

hope that I explained what I needed
 

Cronk

Registered User.
Local time
Today, 10:29
Joined
Jul 4, 2013
Messages
2,772
Use
Select Case Weekday
case 6,7
...
case else
'--anything other than 6 or 7
end select

or

if weekday = 6 or weekday = 7 then
...
else ...
endif

or

Holidaytype = iif( weekday = 6 or weekday = 7 ,Weekend, Workday)

This of course is defining the weekend as Friday and Saturday.
 

Users who are viewing this thread

Top Bottom