+ Reply to Thread
Results 1 to 3 of 3

userform with login and logout button

Hybrid View

  1. #1
    Registered User
    Join Date
    01-27-2017
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    90

    userform with login and logout button

    Hi ,
    below is the screen shot of the user form which i am trying to capture login and logout timings.

    i found below code from the net but it not working as expected , i have done enough R&D and last posing in this forum.

    i need the code to capture login and logout details in excel after login using username and password.
    this workbook code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    UserForm1.CommandButton2.Visible = True
    UserForm1.CommandButton1.Visible = False
    UserForm1.TextBox1.Visible = False
    UserForm1.TextBox2.Visible = False
    UserForm1.Label1.Visible = False
    UserForm1.Label2.Visible = False
    UserForm1.Show
    End Sub
    
    Private Sub Workbook_Open()
    MsgBox "Please login. After finishing your work please click on the logout button."
    UserForm1.Show
    End Sub
    userform1 code:
    Function IsWorkBookOpen(FileName As String)
    
    Dim FF As Integer, ErrNum As Integer
    
    On Error Resume Next ' We turn off error checking
    FF = FreeFile()  'The inbuilt function gets a free file number.
    Open FileName For Input Lock Read As #FF 'we try to open the file and lock it
    Close FF  'Close the file
    ErrNum = Error  'capture the error number
    On Error GoTo 0  'Turn on error checking
    'Find which error happened
    Select Case ErrNum
    ' No error
    ' File is not open
    Case 0: IsWorkBookOpen = False
    ' Error for “Permission Denied.”
    ' File already opened by another user
    Case 70: IsWorkBookOpen = True
    ' Some other error occurred. Capture the error number for further action
    Case Else: Error ErrNum
    End Select
    End Function
    
    Private Sub CommandButton1_Click()
    Dim username As String
    Dim password As String
    
    username = TextBox1.Text
    password = TextBox2.Text
    
    'checklogincredentials
    'If TextBox1.Text = “abc” And TextBox2.Text = “abc789” Then
    'MsgBox “You are logged in!”
    Dim info
    info = IsWorkBookOpen("D:\TMS_Project\username-password.xlsx")
    ' we open the workbook if it is closed
    If info = False Then
    Workbooks.Open ("D:\TMS_Project\username-password.xlsx")
    End If
    
    Dim x As Integer
    x = 2
    Do While Cells(x, 1).Value <> ""
    If Cells(x, 1).Value = username And Cells(x, 2).Value = password Then
    MsgBox "Welcome!"
    Sheet1.Range("A1").Value = Date & " " & Time
    Selection.NumberFormat = "m/d/yyyy h:mm AM/PM"
    
    UserForm1.Hide
    ActiveWorkbook.Close True
    End
    Else
    x = x + 1
    End If
    
    Loop
    MsgBox "Please check your username or password!"
    ActiveWorkbook.Close True
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox1.SetFocus
    
    'Else
    'MsgBox “Wrong username or password!”
    'TextBox1.Text = “”
    'TextBox2.Text = “”
    'TextBox1.SetFocus
    'End If
    End Sub
    
    Private Sub CommandButton2_Click()
    
    Sheet1.Range("B1").Value = Date & " " & Time
    Selection.NumberFormat = "m/d/yyyy h:mm AM/PM"
    
    ThisWorkbook.Save
    
    Worksheets("Sheet1").Range("A1:B1").Select
    
    Selection.Cut
    
    Unload Me
    
    getlogindata
    
    ActiveWorkbook.Close True
    'Application.Quit
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    End If
    
    End Sub
    module code:
    Function IsWorkBookOpen(FileName As String)
    
    Dim FF As Integer, ErrNum As Integer
    
    On Error Resume Next ' We turn off error checking
    FF = FreeFile() ' The inbuilt function gets a free file number.
    Open FileName For Input Lock Read As #FF 'we try to open the file and lock it
    Close FF ' Close the file
    ErrNum = Error ' capture the error number
    On Error GoTo 0 ' Turn on error checking
    'Find which error happened
    Select Case ErrNum
    ' No error
    ' File is not open
    Case 0: IsWorkBookOpen = False
    ' Error for "Permission Denied."
    ' File already opened by another user
    Case 70: IsWorkBookOpen = True
    'Some other error occurred. Capture the error number for further action
    Case Else: Error ErrNum
    End Select
    End Function
    
    Sub getlogindata()
    
    Dim info
    info = IsWorkBookOpen("D:\TMS_Project\login-details.xlsx")
    ' we open the workbook if it is closed
    If info = False Then
    Workbooks.Open ("D:\TMS_Project\login-details.xlsx")
    End If
    Worksheets("Sheet1").Activate
    erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    ActiveSheet.Paste Destination:=Worksheets(“Sheet1”).Range(Cells(erow, 1), Cells(erow, 2))
    
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    Application.Quit
    
    End Sub
    and i am getting error object required at line
    Sheet1.Range("A1").Value = Date & " " & Time
    Attached Images Attached Images
    Last edited by narsing18; 07-13-2017 at 06:06 AM. Reason: picture attached

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: userform with login and logout button

    i have done enough R&D
    From what I can see the code you posted was copied verbatim from another site - no sign of any R&D at all.

    Rather than posting a bunch of code you claim is "not working as expected" perhaps you'd take the time to explain exactly what you expect?

  3. #3
    Registered User
    Join Date
    01-27-2017
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    90

    Re: userform with login and logout button

    as i already said i found this code in net.... and trying to implement it for my use.

    i can capture the login details ..but not able to capture logout details and i don't want form to be closed once the login details were entered.

    in thisworkbook i tried to change the userform visibility from true to false but it didnt worked for me.

    once again i confirm that this is not my code i found this while searching in net.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Login/logout hrs - is there a quicker way?
    By jeffa0 in forum Excel General
    Replies: 3
    Last Post: 05-10-2016, 09:25 PM
  2. Login - Logout report
    By vamshi57 in forum Excel General
    Replies: 9
    Last Post: 04-19-2016, 12:38 AM
  3. Replies: 0
    Last Post: 02-17-2014, 07:44 AM
  4. login and logout time , with total login time ,break> 1 hours
    By shrinivasmj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-12-2013, 05:37 AM
  5. Login Logout Report
    By excelnightmare in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2011, 01:45 PM
  6. Login Logout userform
    By poitachi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2010, 03:01 PM
  7. First login & last Logout
    By Vikky in forum Excel General
    Replies: 2
    Last Post: 08-19-2006, 01:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1