กระทู้เก่าบอร์ด อ.สุภาพ ไชยา
        
           505   1		  
          
					  
		    URL.หัวข้อ / 
		    URL
        
        คำถามนี้น่าจะมีคำตอบ      
		
    
      เมื่อวันที่ 9 มี.ค. 44 ที่ผ่านมา ผมได้อ่านเจอคำถามหนึ่งที่
http://pantip.inet.co.th/tech/software/topic/SP641530.html
คำถาม คือ
เก็บข้อมูลการหยุดงานของพนักงานไว้ใน Table โดยเก็บไว้ 3 Field คือ empid = รหัสพนักงาน empdat = วันที่ emphol = รหัสการหยุดงาน ก็เก็บข้อมูลมาเรื่อยๆ แต่ตอนนี้อยากทราบว่ามีพนักงานคนไหนบ้างที่ขาดงาน(ใช้รหัส AB ใน Field emphol ) เป็นเวลาติดต่อกัน 3 วัน เช่น หยุดวันที่ 1 - 2 - 3 ก็ให้แสดงออกมา แต่ถ้า หยุดวันที่ 1 - 5 - 12 หยุด 3 วันเหมือนกันแต่ไม่ต้องการ ใครทำได้บ้างคะ ช่วยบอกทีค่ะ
จากคุณ : ปู [9 มี.ค. 2544 - 14:29:29]
ผมได้ลองจำลองข้อมูลดู และลองเขียนโค้ดดังนี้
Sub CheckLeave()
Dim dbs As Database, rst As Recordset
Dim I As Integer, J As Integer, dteDate As Date, intCount As Integer
Dim BDate As Date, EDate As Date
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLeave")
dteDate = rst("empdate")
intCount = 0
Do Until rst.EOF
For I = 1 To rst.RecordCount
If rst("empid") = "002" Then
If rst("empol") = "AB" Then
'dteDate = rst("empdate")
If rst("empdate") - dteDate = 1 Then
If intCount = 0 Then
BDate = rst("empdate") - 1
End If
intCount = intCount + 1
If intCount = 2 Then
EDate = rst("empdate")
End If
End If
'Debug.Print rst("empdate") - dteDate
'Debug.Print rst("empdate"); rst("empol")
'Debug.Print "----"
dteDate = rst("empdate")
If intCount = 2 Then
Debug.Print intCount & " From " & BDate & " To " & EDate
intCount = 0
dteDate = EDate + 1
End If
Else
intCount = 0
End If
            
End If
rst.MoveNext
Next I
Loop
'Debug.Print intCount; BDate; EDate
End Sub
สิ่งที่จะต้องทำต่อไปคือ ให้วนหารหัสพนักงานคนต่อไปครับ
    
    
  http://pantip.inet.co.th/tech/software/topic/SP641530.html
คำถาม คือ
เก็บข้อมูลการหยุดงานของพนักงานไว้ใน Table โดยเก็บไว้ 3 Field คือ empid = รหัสพนักงาน empdat = วันที่ emphol = รหัสการหยุดงาน ก็เก็บข้อมูลมาเรื่อยๆ แต่ตอนนี้อยากทราบว่ามีพนักงานคนไหนบ้างที่ขาดงาน(ใช้รหัส AB ใน Field emphol ) เป็นเวลาติดต่อกัน 3 วัน เช่น หยุดวันที่ 1 - 2 - 3 ก็ให้แสดงออกมา แต่ถ้า หยุดวันที่ 1 - 5 - 12 หยุด 3 วันเหมือนกันแต่ไม่ต้องการ ใครทำได้บ้างคะ ช่วยบอกทีค่ะ
จากคุณ : ปู [9 มี.ค. 2544 - 14:29:29]
ผมได้ลองจำลองข้อมูลดู และลองเขียนโค้ดดังนี้
Sub CheckLeave()
Dim dbs As Database, rst As Recordset
Dim I As Integer, J As Integer, dteDate As Date, intCount As Integer
Dim BDate As Date, EDate As Date
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLeave")
dteDate = rst("empdate")
intCount = 0
Do Until rst.EOF
For I = 1 To rst.RecordCount
If rst("empid") = "002" Then
If rst("empol") = "AB" Then
'dteDate = rst("empdate")
If rst("empdate") - dteDate = 1 Then
If intCount = 0 Then
BDate = rst("empdate") - 1
End If
intCount = intCount + 1
If intCount = 2 Then
EDate = rst("empdate")
End If
End If
'Debug.Print rst("empdate") - dteDate
'Debug.Print rst("empdate"); rst("empol")
'Debug.Print "----"
dteDate = rst("empdate")
If intCount = 2 Then
Debug.Print intCount & " From " & BDate & " To " & EDate
intCount = 0
dteDate = EDate + 1
End If
Else
intCount = 0
End If
End If
rst.MoveNext
Next I
Loop
'Debug.Print intCount; BDate; EDate
End Sub
สิ่งที่จะต้องทำต่อไปคือ ให้วนหารหัสพนักงานคนต่อไปครับ
				1 Reply in this Topic. Dispaly 1  pages and you are on page number 1 
				
        
    1 @R00049    
        
    
      และเมื่อเช้าผมได้ตอบคำถามไว้ที่
http://www.helptalk.net/forums/access/messages/109041.html
ด้วย เป็นคำถามที่น่าสนใจ ผมใช้ชื่อ Tim K.    
    
  
      Time: 0.0811s
    
      
		