Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla asked on

Code Correction

What's Wrong with my Code? This code has been running in DataAccess but when i transfer in MSSQL7 it doesn't Work. Why?
Private Sub Savelog()
    Call LogIn
 
    
      If login_am = False And logout_am = False And login_pm = False And logout_pm = False Then
        With LogInRS
            .AddNew
                !EM_ID = txtEmployeeID.Text
                !DATE_LOG = lblDate.Caption
                !IN_AM = lblTime.Caption
                !OUT_AM = "00:00:00"
                !IN_PM = "00:00:00"
                !OUT_PM = "00:00:00"
                !TOTAL_AM = "00:00:00"
                !TOTAL_PM = "00:00:00"
                !GRAND_TOTAL = "00:00:00"
            .Update
        End With
         
        MsgBox "Employees ID: " & txtEmployeeID.Text & " has been successfully LOG IN!", vbInformation
    
    ElseIf login_am = True And logout_am = False And login_pm = False And logout_pm = False Then
        
        LogInRS.Find "LOG_ID='" + lblLogID.Caption + "'", 0, 1
        With LogInRS
                !OUT_AM = lblTime.Caption
                !TOTAL_AM = Result
                !GRAND_TOTAL = Result
            .Update
        End With
        
        MsgBox "Employees ID: " & Trim(txtEmployeeID.Text) & " has been successfully LOG OUT!", vbInformation
        
    ElseIf login_am = True And logout_am = True And login_pm = False And logout_pm = False Then
        
        LogInRS.Find "LOG_ID='" + lblLogID.Caption + "'", 0, 1
        With LogInRS
                !IN_PM = lblTime.Caption
            .Update
        End With
        
        MsgBox "Employees ID: " & Trim(txtEmployeeID.Text) & " has been successfully LOG IN!", vbInformation
    
    ElseIf login_am = True And logout_am = True And login_pm = True And logout_pm = False Then
        
        LogInRS.Find "LOG_ID='" + lblLogID.Caption + "'", 0, 1
        With LogInRS
                !OUT_PM = lblTime.Caption
                !TOTAL_PM = Result
                !GRAND_TOTAL = Result
            .Update
        End With
        
        With LogInRS
                tt1 = !TOTAL_AM
                tt2 = !TOTAL_PM
        End With
        
        COMPUTE_TOTAL = True
        Call computetime
        With LogInRS
                !GRAND_TOTAL = Result
            .Update
        End With
        
        MsgBox "Employees ID: " & Trim(txtEmployeeID.Text) & " has been successfully LOG OUT!", vbInformation
         
    ElseIf login_am = True And logout_am = True And login_pm = True And logout_pm = True Then
    
         MsgBox "Employees ID: " & Trim(txtEmployeeID.Text) & " has already logged completely  for the day!", vbInformation
    
    End If
    
    COMPUTE_TOTAL = False
    Call UnloadOject
End Sub
 
 
'''This is Correct
Public Sub LogIn()
    Set LogInRS = New ADODB.Recordset
    With LogInRS
        .ActiveConnection = conn
        .CursorType = adOpenStatic
        .LockType = adLockOptimistic
        .Open "SELECT * FROM TIMELOG"
    End With
End Sub

Open in new window

Visual Basic Classic

Avatar of undefined
Last Comment
Whing Dela Cruz

8/22/2022 - Mon
ASKER
Whing Dela Cruz

Private Sub checklog()
    Dim sql, RECTIME As String
    On Error GoTo Errorhandler
    sql = ""
    RECTIME = ""
    Result = ""
    Call LogIn
   
    LogInRS.Close
        sql = "SELECT * FROM TIMELOG WHERE EM_ID='" & txtEmployeeID.Text & "'and DATE_LOG like'" & lblDate.Caption & "'"
    LogInRS.Open sql, conn, adOpenDynamic, adLockOptimistic
    If Not LogInRS("IN_AM").Value = "" Then
        login_am = True
       
        With LogInRS
            t1 = !IN_AM
            lblLogID.Caption = !LOG_ID
        End With
        Call computetime
       
        If Not LogInRS("OUT_AM").Value = "00:00:00" Then
            logout_am = True
            With LogInRS
                lblLogID.Caption = !LOG_ID
            End With
           
            If Not LogInRS("IN_PM").Value = "00:00:00" Then
                login_pm = True
                With LogInRS
                    lblLogID.Caption = !LOG_ID
                    t1 = !IN_PM
                End With
                Call computetime
               
                If Not LogInRS("OUT_PM").Value = "00:00:00" Then
                    logout_pm = True
                    With LogInRS
                        lblLogID.Caption = !LOG_ID
                    End With
                Else
                    logout_pm = False
                End If
            Else
                login_pm = False
            End If
        Else
            logout_am = False
        End If
    Else
        login_am = False
    End If
    Call Savelog
    Exit Sub
Errorhandler:
        If Err.Number = 3021 Then
            login_am = False
            Call Savelog
        Else
            Resume Next
        End If
End Sub




ASKER CERTIFIED SOLUTION
Robberbaron (robr)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Whing Dela Cruz

Thanks and More Power!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23