• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to disable login button when an employee is currently login in the system?

Ryan Barrera

New Member
I have a simple Employee Login System. Here's how it work, an employee will enter his/her Emp_ID and then it will display their name in txtName. When they hit Login button, it will then transfer their information to excel sheet. My problem is that, I can still let them login even if they are currently login to the sytem. I need the login button to be disable when they're currently login. Any answer will much appreciated.

For some reason, I can't upload the file. As an alternate way to view my project.
Here's a link:
http://stackoverflow.com/questions/...n-an-employee-is-currently-login-in-excel-vba
 
Code:
Option Explicit

Dim CM As Boolean

Private Sub cmdLogin_Click()

With Worksheets("May_1st").Range("A65536").End(xlUp)
    .Offset(1, 0) = UserForm1.txtName.Text
    .Offset(1, 1) = UserForm1.txtEmpID.Text
    .Offset(1, 2) = UserForm1.txtTime.Text
End With

'Unload Me 'Optional: Close Userform1
cmdLogin.Enabled = False
txtName.Text = ""
txtEmpID.Text = ""
txtEmpID.SetFocus

End Sub

Private Sub cmdLogOut_Click()

'Worksheets("May_1st").Range("D65536").End(xlUp).Offset(1) = Format(Now, "hh:mm:ss")

'Unload Me 'Optional: Close Userform On Where Logout Button Is

Dim myLog As Worksheet
Dim myLogSheet As Range

Set myLog = Sheets("May_1st")
Set myLogSheet = myLog.Range("B:B").Find(txtEmpID.Value, , , xlWhole)

If Not myLogSheet Is Nothing Then
myLogSheet.Offset(0, 2) = Format(Now, "hh:mm:ss")

Else
txtName.Value = "XXX"

End If

Private Sub UserForm1_Initialize()

End Sub


Private Sub UserForm_Initialize()
    cmdLogin.Enabled = True
End Sub
 
Thanks for your reply, however that is not what I want..I want the login button to be disable only when an employee is currently login.
 
How would they log in if the button is not enabled ?

Nevermind, I understand your request now. Give me some time.
 
Code:
Option Explicit

Dim CM As Boolean

Private Sub cmdLogin_Click()

Dim LSearchRow As Integer
Dim LSearchValue As String
 
    'On Error GoTo Err_Execute
 
    LSearchValue = txtEmpID.Text
 
    'Start search in row 4
    LSearchRow = 2
 
    While Len(Range("A" & CStr(LSearchRow)).Value) > 0
     
        'If value in column B = LSearchValue, copy entire row to Sheet2
        If Range("B" & CStr(LSearchRow)).Value = LSearchValue Then
            Unload Me
             MsgBox "Sorry, you have already clocked in. ", vbCritical, "Clock In Error !"
            Exit Sub
        End If
     
        LSearchRow = LSearchRow + 1
     
    Wend
 
    'Position on cell A3
    Application.CutCopyMode = False
    Range("A1").Select
 
'Err_Execute:
    'MsgBox "An error occurred."

With Worksheets("May_1st").Range("A65536").End(xlUp)
    .Offset(1, 0) = UserForm1.txtName.Text
    .Offset(1, 1) = UserForm1.txtEmpID.Text
    .Offset(1, 2) = UserForm1.txtTime.Text
End With

'Unload Me 'Optional: Close Userform1
cmdLogin.Enabled = False
txtName.Text = ""
txtEmpID.Text = ""
txtEmpID.SetFocus

End Sub

Private Sub cmdLogOut_Click()

'Worksheets("May_1st").Range("D65536").End(xlUp).Offset(1) = Format(Now, "hh:mm:ss")

'Unload Me 'Optional: Close Userform On Where Logout Button Is

Dim myLog As Worksheet
Dim myLogSheet As Range

Set myLog = Sheets("May_1st")
Set myLogSheet = myLog.Range("B:B").Find(txtEmpID.Value, , , xlWhole)

If Not myLogSheet Is Nothing Then
    If myLogSheet.Offset(0, 2) <> "" Then
        Unload Me
        MsgBox "Sorry, you have already clocked out.", vbCritical, "Clock Out Error !"
        Exit Sub
    End If
    myLogSheet.Offset(0, 2) = Format(Now, "hh:mm:ss")
    Unload Me
Else
    txtName.Value = "XXX"
    Unload Me
End If
End Sub
Private Sub UserForm1_Initialize()
    cmdLogin.Enabled = True
End Sub
 

Attachments

  • Clock In Out.xlsm
    23.4 KB · Views: 9
Hi Logit. I appreciated your time taking to help me. I tested out your own version and play with it. Here's what I observed so far, I was able to input employee name and emp ID and then hit login, after that login button will disable. I have to close the form and then reopen it for the next employee to login.. I will send you a link so that you can download my own version.

here's the link:
https://www.excelforum.com/hello-in...-is-currently-login-in-attendance-system.html

More power.
 
I notice also that after clicking the Login button, it won't capture the time.

What I really wanted is that when typing the employee ID, it will check on the sheet and check to see if that employee ID is currently login. If it is currently login, Login button should be disable.
 
I uploaded this file..Thank you so much..I'll keep you posted if I got something new.
 

Attachments

  • Emp_Login.xlsm
    23.6 KB · Views: 15
Back
Top