|
- 액세스 버전(2010)
황동준님을 비롯한 여러 지도해 주시는 분들께 감사드립니다.
1. <공휴일> 테이블에 <일자>를 입력하였을 때 <요일>이 바로 자동 입력되게 할 수는 없을까요?
2. <작업일수계산> 쿼리에서 <일요일수>에 현재의 "일요일"만 계산한 것을 "토요일"도 <일요일수>에 합산 계산되게 하고, <근무일수>도 토요일은 제외되도록 <modWorkDay>을 수정 부탁드립니다. - 김길동의 5, 1, 1, 3이 5, 2, 1, 2로 되도록 부탁드립니다.
감사합니다.
==============[이인형님 글에 대한 답변입니다]==============
1. 테이블에서는 안됩니다. (매크로 및 vb 사용 불가)
폼에서 이용하세요
Private Sub 일자_AfterUpdate()
If IsNull(일자) Then Exit Sub
Me.요일 = Weekday(Me.일자)
End Sub
2. 토,일요일의 개수를 구하는 아래 모듈을 추가하신 후 HowManyWorkDay 모듈을 적절히 수정 하세요.(첨부참조)
출처 : ACCESSWORLD
https://www.access-programmers.co.uk/forums/threads/count-sunday-saturday-between-two-days.222228/
Public Function SatSunCount(date1 As Date, date2 As Date) As Long
'define some variables
Dim begindate As Date
Dim enddate As Date
Dim i As Long
Dim daysdiff As Long
Dim incdate As Date
Dim weekenddaycounter As Long
'If the dates are entered in reverse order, reset them properly; also remove the time portion if included
If date2 < date1 Then
begindate = DateValue(date2)
enddate = DateValue(date1)
Else
begindate = DateValue(date1)
enddate = DateValue(date2)
End If
'set the weekend day counter to zero, assign the beginning date to the date variable that will be incremented
weekenddaycounter = 0
incdate = begindate
'find the number of days difference between the two dates
daysdiff = DateDiff("d", begindate, enddate)
'Debug.Print daysdiff
'loop based on the days difference +1 and add to the counter if the date is a saturday or sunday
For i = 1 To daysdiff + 1
If Weekday(incdate) = 1 Or Weekday(incdate) = 7 Then
weekenddaycounter = weekenddaycounter + 1
End If
incdate = DateAdd("d", 1, incdate)
Next i
'assign the days counted to the function
SatSunCount = weekenddaycounter
End Function |
|