Consulting

Results 1 to 16 of 16

Thread: Log In-Out Sheet

  1. #1
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location

    Log In-Out Sheet

    Good day everybody!

    I have a logIn Sheet that captures user UserName, ComputerName, DateLoggedIn, TimeLoggedIn and TimeLoggedOut. The example code was summited by Simon LLoyd (thanks Lloyd) now I need to modify it. When user logs out, a pop msg window ask if you want to save the changes, and if you click no (workbooks will be opening read-only user not supposed to modify it) user supposed to click no, well, this removes the loogedIn information on the Sheet. How can I overcome this problem, either by avoiding the pop msg window or by recoding the logIn and out information no matter what the user does.

    One more question on column "F" I want to print the time in minutes the user was logged in (incode)

    Sample WB Attached

    Hope everybody is enjoying the long holiday weekend!

    Thanks!
    Last edited by IgnBan; 03-22-2008 at 11:46 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Save the logging information in a separate text file, and make the Excel file read-only.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    XLD, thanks for replaying. I'm looking the KB for code samples how to keep a separate text file and can't find an example. Can you give me some clues how I can do this, or direct me to a web-page to research the topic.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Private Sub Workbook_Open()
    Dim FileNumber As Long
    FileNumber = FreeFile    ' Get unused file
            ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Write #FileNumber, Environ("username"), Environ("computername"), Format(Now, "dd mmm yyyy hh:mm:ss")
        Close #FileNumber
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    If I insert this code in the LogTimePost workbook:
    Private Sub Workbook_Open()
        Open LogTimePost.Path & "\usage.log" For Append As #1
        Print #1, Application.UserName, Now
        Close #1
    End Sub
    How can I modify it so it can give in the text file besides User Name ComputerName, DateLoggedIn, TimeLoggedIn, TimeLoggedOut and the difference between the time loggedIn and Out in minutes, in another words the time user was logged?

  6. #6
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    Sorry XLD, I guess I was writing my replay when you answered my post.

  7. #7
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    How can I append the logOut time to the text file and calculate the time the user was logged using both logIn and Out time?

  8. #8
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    I posted the question above and the post didnt bump up!?!?

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim FileNumber As Long
    FileNumber = FreeFile ' Get unused file
         ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Print #FileNumber, "Out:" & Environ("username"), Environ("computername"), "Format(Now, "; dd; mmm; yyyy; hh: mm: ss ")"
        Close #FileNumber
    End Sub
    
    Private Sub Workbook_Open()
        Dim FileNumber As Long
    FileNumber = FreeFile ' Get unused file
         ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Print #FileNumber, "In:" & Environ("username"), Environ("computername"), "Format(Now, "; dd; mmm; yyyy; hh: mm: ss ")"
        Close #FileNumber
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    Thanks for the help XLD...I want to be sure I following the proper procedures; This code should be place in the workbook module,.. when I do and try to compile it is giving me and error .
    Sub or Function not defined;
    ..highlighting the minute formating.
     
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim FileNumber As Long
    FileNumber = FreeFile ' Get unused file
         ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Print #FileNumber, "Out:" & Environ("username"), Environ("computername"), "Format(Now, "; dd; mmm; yyyy; hh: mm: ss ")"
        Close #FileNumber
    End Sub
    When I try to open or close the workbook , gives me the same error in both Subs.

    Attached WB

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I don't know if this helps or not Jose......changed Bob's format a little....
    Option Explicit
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Dim FileNumber As Long
    FileNumber = FreeFile ' Get unused file
         ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Print #FileNumber, "Out:" & Environ("username"), Environ("computername"), Format(Now, "dd mmm yyyy hh:mm:ss")
        Close #FileNumber
    End Sub
     
    Private Sub Workbook_Open()
        Dim FileNumber As Long
    FileNumber = FreeFile ' Get unused file
         ' number.
        Open ThisWorkbook.Path & Application.PathSeparator & "LogFile.txt" For Append As #FileNumber
        Print #FileNumber, "In:" & Environ("username"), Environ("computername"), Format(Now, "dd mmm yyyy hh:mm:ss")
        Close #FileNumber
    End Sub
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I've no idea how we got that mess, but

    "Format(Now, "; dd; mmm; yyyy; hh: mm: ss ")"
    should be

    "Format(Now, "dd-mmm-yyyy hh:mm:ss ")"
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    It must have happened when you posted it Bob......system is pretty good but not perfect.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    VBAX Contributor
    Joined
    Jan 2008
    Posts
    104
    Location
    Lucas that will doit, it fixed it, thanks so much.
    Xld Thanks for the code, this appending will do the "time logged" by showing the time in and out next to the other, visually it can tell how long the user reviewed the workbook. Thank you guys!

  15. #15
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lucas
    It must have happened when you posted it Bob......system is pretty good but not perfect.
    No, I just looked at my workbook, I introduced it into there somehow.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  16. #16
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by IgnBan
    Lucas that will doit, it fixed it, thanks so much.
    Xld Thanks for the code, this appending will do the "time logged" by showing the time in and out next to the other, visually it can tell how long the user reviewed the workbook. Thank you guys!
    Personally, Iwould think that the log file is a perfect andidate for further analysis in Excel, probably using a pivot table/pivot charts.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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