TABLE: Table_Test
OBJECTIVE: to consolidate employee according to their time in, time out, and roster type.
RESULT:
EXPLANATION:
PROBLEM: Once Record has too many, it takes sometime to load
OBJECTIVE: to consolidate employee according to their time in, time out, and roster type.
RESULT:
EXPLANATION:
- If Employee was not on leave nor late nor early out. The Rostered Type to be retrieved is always Start and End.
- If Employee was Late. The Rostered Type to be retrieved for TapIn is Leave: Late and for TapOut is Leave: End and Remarks will be Late.
- If Employee was Late and Early Out. The Rostered Type to be retrieved for TapIn is Leave: Late and TapOut is Leave: End and Remarks will be Late/EO.
- If Employee was on Leave. The Rostered to be retrieved for TapIn is Leave: PLV and for TapOut is Leave: End and Remarks will be PLV.
Code:
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rs1 As ADODB.Recordset
Dim TapIn, TapOut, ToEnd, Remarks As String
Dim Arr() As String
Dim dbName
dbName = "C:\Test\Db Test.accdb"
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & dbName & ";Jet OLEDB:Database Password="
Set db = New ADODB.Connection
If Not db Is Nothing Then
If (db.State And adStateOpen) = adStateOpen Then
Else
db.Open (sConnString)
db.CommandTimeout = 0
End If
End If
MYSQL = "SELECT DISTINCT EmpID, RosteredDate FROM Table_Test"
Set rs = New ADODB.Recordset
rs.Open MYSQL, db, adOpenKeyset, adLockOptimistic
If rs.EOF Then
Else
Do Until rs.EOF = True
MYSQL = "SELECT * FROM Table_Test WHERE EmpID = '" & rs.Fields("EmpID") & "' AND RosteredDate = '" & rs.Fields("RosteredDate") & "'"
Set rs = New ADODB.Recordset
rs1.Open MYSQL, db, adOpenKeyset, adLockOptimistic
TapIn = ""
TapOut = ""
Remarks = ""
ToEnd = ""
If rs1.EOF Then
Else
Do Until rs1.EOF = True
If Not InStr(1, rs1.Fields("RosteredType"), "End", vbTextCompare) > 0 Then
If InStr(1, rs1.Fields("RosteredType"), "Leave:", vbTextCompare) > 0 Then
Arr = Split(rs1.Fields("RosteredType"), ":")
If Remarks = "" Then
Remarks = Trim(Arr(1))
Else
Remarks = Remarks & "/" & Trim(Arr(1))
End If
End If
If InStr(1, rs1.Fields("RosteredType"), "Start", vbTextCompare) > 0 Or InStr(1, rs1.Fields("RosteredType"), "Leave:", vbTextCompare) > 0 Then
TapIn = rs1.Fields("RosteredTime")
End If
Else
If InStr(1, rs1.Fields("RosteredType"), "End", vbTextCompare) > 0 Then
TapOut = rs1.Fields("RosteredTime")
End If
End If
rs1.MoveNext
Loop
End If
rs1.Close
Set rs1 = Nothing
rs.MoveNext
Loop
End If
rs.MoveNext
Set rs = Nothing
db.Close
Set db = Nothing
PROBLEM: Once Record has too many, it takes sometime to load