Results 1 to 2 of 2

Thread: Find last login date

  1. #1
    Lively Member
    Join Date
    Mar 07
    Posts
    83

    Question Find last login date

    Hi

    Working in msaccess:
    I have a table that keeps a log of all usernames who access the application, with date and time.

    I would like to find and display the last login date (not the current login of course) of that user.

    Currently, i am getting the first login info of my user.. check code in attachment.

    Thanks
    Attached Files Attached Files

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: Find last login date

    Instead of opening an entire table & using Find, just get the data you want using an SQL statement.

    For example, this section of your code:
    vb Code:
    1. 'Find the last login date of the username
    2. Set RecSet2 = New ADODB.Recordset
    3. RecSet2.CursorLocation = adUseClient
    4. RecSet2.Open "tblAccess", sConn, adOpenStatic, adLockOptimistic, adCmdTable
    5.  
    6. RecSet2.Find "Username = '" & ThePerson & "'", , adSearchBackward
    7. Me.lblLastLogin.Caption = Me.lblLastLogin.Caption & RecSet2.Fields("TheDate") & "at" & RecSet2.Fields("TheTime")
    Should be replaced by this:
    vb Code:
    1. 'Find the last login date of the username
    2. Set RecSet2 = New ADODB.Recordset
    3. Dim strSQL as String 'not really needed, but makes the code easier to read & debug
    4. strSQL = "SELECT * FROM tblAccess WHERE Username = '" & ThePerson & "'"
    5. RecSet2.Open strSQL, sConn, adOpenForwardOnly, adLockReadOnly, adCmdText
    6.  
    7. Me.lblLastLogin.Caption = Me.lblLastLogin.Caption & RecSet2.Fields("TheDate") & "at" & RecSet2.Fields("TheTime")
    8.  
    9. 'Unless you want to corrupt your database, you need to close
    10. 'recordsets & connections when you finish with them:
    11. RecSet2.Close
    12. Set RecSet2 = Nothing
    This still isn't quite right, but is much closer to what you need - all we need to do is minor changes to the SQL statement.

    To be able to do that, we need more info.. how can you determine what the last login date was? Is it the highest value in TheDate? or TheDate & TheTime? (if the latter, why are they two separate fields?)

Posting Permissions

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