"No current record" after Quit in Form_Unload

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
 
D

Dorian

You could disable the X to force your users to exit gracefully. I do that in
all my applications.
Is there anything in qryTimeLogged that expects a current record?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
D

Dan Williams

Thanks, y'all!

I'm using the Form_Error() code from the link, and it works great!

Thanks again!
Dan



You could disable the X to force your users to exit gracefully. I do thatin
all my applications.
Is there anything in qryTimeLogged that expects a current record?
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".



Dan Williams said:
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- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top