D
Dan Williams
In this DB I've inherited, they do a time stamp when someone logs out
(when the login form closes).
Private Sub Form_Close()
Dim myDB As Database, myTable As TableDef, myQuery As QueryDef, mySet
As Recordset
Set myDB = CurrentDb
Set myQuery = myDB.QueryDefs("qryTimeLogged")
Set mySet = myQuery.OpenRecordset()
With mySet
.MoveFirst
.Edit
![outtime] = Now
.Update
.Close
End With
DoCmd.Quit
End Sub
But the Form_Close event misses instances where the user exits
violently by shutting down Access with the little "x" up in the
corner. I will try to get the users not to do that, but I would also
like it to still do the time stamp if they do it. I tried copying the
same code into the Form_Unload event:
Private Sub Form_Unload(Cancel As Integer)
THIS WORKS! The time stamp is written to the table even when they
exit using the "x". But then they get this error message:
Run-Time error '3021':
No current record.
When I step through it, it happens AFTER the last line, "End
Sub" (just before everything closes).
So far I have tried the following, which do not help:
Putting "On Error Resume Next" before the End Sub
Changing DoCmd.Quit to Application.Quit
Setting myDB, myQuery, and mySet to Nothing
(I'm not used to code that "writes into a query" instead of a table.
This query shows the single row that already contains the current
user's log-in time stamp.)
You might say this error message is good, because it punishes the user
for exiting the wrong way. But I'd rather fix it. Is there an easy
change I could make?
Access 2000
Windows 2000
Dan Williams
danwPlanet
(when the login form closes).
Private Sub Form_Close()
Dim myDB As Database, myTable As TableDef, myQuery As QueryDef, mySet
As Recordset
Set myDB = CurrentDb
Set myQuery = myDB.QueryDefs("qryTimeLogged")
Set mySet = myQuery.OpenRecordset()
With mySet
.MoveFirst
.Edit
![outtime] = Now
.Update
.Close
End With
DoCmd.Quit
End Sub
But the Form_Close event misses instances where the user exits
violently by shutting down Access with the little "x" up in the
corner. I will try to get the users not to do that, but I would also
like it to still do the time stamp if they do it. I tried copying the
same code into the Form_Unload event:
Private Sub Form_Unload(Cancel As Integer)
THIS WORKS! The time stamp is written to the table even when they
exit using the "x". But then they get this error message:
Run-Time error '3021':
No current record.
When I step through it, it happens AFTER the last line, "End
Sub" (just before everything closes).
So far I have tried the following, which do not help:
Putting "On Error Resume Next" before the End Sub
Changing DoCmd.Quit to Application.Quit
Setting myDB, myQuery, and mySet to Nothing
(I'm not used to code that "writes into a query" instead of a table.
This query shows the single row that already contains the current
user's log-in time stamp.)
You might say this error message is good, because it punishes the user
for exiting the wrong way. But I'd rather fix it. Is there an easy
change I could make?
Access 2000
Windows 2000
Dan Williams
danwPlanet