Hi experts, I have a type mismatch error in getting time difference from database. Below are my codes.
Private Sub cmdSearch_Click()
Dim sTrID As String
Dim Total As Integer
Dim xhours As String
Dim Intime As String
Dim Outtime As String
sTrID = txtSearch.Text
Set rs = New ADODB.Recordset
rs.Open "Select Count(DateIn) as Total from Time_In where Employees_IdNo = '" & sTrID & "'", cn, adOpenKeyset, adLockPessimistic
If Not rs.EOF Then
lblTotal_Days.Caption = rs!Total
Ado.RecordSource = "Select Employees_IdNo, DateIn, TimeIn, TimeOut from Time_In where Employees_IdNo = '" & sTrID & "'"
Ado.Refresh
rs!TimeIn = Intime
rs!Timeout = Outtime
xhours = Timediff(Intime, Outtime)
lblTotal_Hours.Caption = xhours
rs.Close
Set rs = Nothing
Else
MsgBox "No records found! ", vbExclamation, "DailyRecords"
End If
End Sub
Public Function Timediff(ByVal time1 As String, ByVal time2 As String) As String
Dim MinsDiff, TheHours As String
MinsDiff = DateDiff("n", time1, time2)
MinsDiff = IIf(MinsDiff < 0, MinsDiff + 1440, MinsDiff)
TheHours = Format(Int(MinsDiff / 60), "00")
MinsDiff = Format(MinsDiff Mod 60, "00")
Timediff = TheHours & ":" & MinsDiff
End Function