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:
'Find the last login date of the username
Set RecSet2 = New ADODB.Recordset
RecSet2.CursorLocation = adUseClient
RecSet2.Open "tblAccess", sConn, adOpenStatic, adLockOptimistic, adCmdTable
RecSet2.Find "Username = '" & ThePerson & "'", , adSearchBackward
Me.lblLastLogin.Caption = Me.lblLastLogin.Caption & RecSet2.Fields("TheDate") & "at" & RecSet2.Fields("TheTime")
Should be replaced by this:
vb Code:
'Find the last login date of the username
Set RecSet2 = New ADODB.Recordset
Dim strSQL as String 'not really needed, but makes the code easier to read & debug
strSQL = "SELECT * FROM tblAccess WHERE Username = '" & ThePerson & "'"
RecSet2.Open strSQL, sConn, adOpenForwardOnly, adLockReadOnly, adCmdText
Me.lblLastLogin.Caption = Me.lblLastLogin.Caption & RecSet2.Fields("TheDate") & "at" & RecSet2.Fields("TheTime")
'Unless you want to corrupt your database, you need to close
'recordsets & connections when you finish with them:
RecSet2.Close
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?)