나눔터  
  HOME > 나눔터 > 묻고답하기 > 액세스
액세스
액세스에 대한 질문과 답변을 올려주세요. 단, 취지에 맞지 않는 글은 운영자가 삭제합니다.
 "000 님, 도와주세요", "부탁 드립니다.", "급합니다!" 등과 같이 막연한 제목을 달지 말아주세요.
[필독] 빠르고 정확한 답변을 얻는 16가지 Tip !
[필독] 저작권법 개정에 따른 이용안내
작성자:  

 황동준 (bogri2000)

추천:  1
파일:     200222_WorkDay.mdb (476KB) 조회:  1648
제목:   [RE]주말과?공휴일?제외한?작업일수?계산-지도바랍니다
     
  - 액세스 버전(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
 
[불량 게시물 신고]  
        
  

작성일 : 2020-02-22(14:18)
최종수정일 : 2020-02-22(14:18)
 


 ◎ 관련글

  제 목   작성자   날짜
주말과 공휴일 제외한 작업일수 계산-지도바랍니다 이인형 2020-02-21
[RE]주말과?공휴일?제외한?작업일수?계산-지도바랍니다 황동준 2020-02-22
[RE]주말과?공휴일?제외한?작업일수?계산-지도바랍니다 이인형 2020-02-22