A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"No current record" after Quit in Form_Unload



 
 
Thread Tools Display Modes
  #1  
Old April 9th, 2009, 03:27 PM posted to microsoft.public.access.forms
Dan Williams
external usenet poster
 
Posts: 11
Default "No current record" after Quit in Form_Unload

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
  #2  
Old April 9th, 2009, 04:42 PM posted to microsoft.public.access.forms
bismuth83
external usenet poster
 
Posts: 35
Default "No current record" after Quit in Form_Unload

Hi Dan,

I found another post with the same error, this solution involves using
the Form_Error() event. Hopefully it points you in the right
direction:
http://groups.google.com/group/micro...1e04b?lnk=raot
  #3  
Old April 9th, 2009, 04:50 PM posted to microsoft.public.access.forms
Dorian
external usenet poster
 
Posts: 542
Default "No current record" after Quit in Form_Unload

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".


"Dan Williams" wrote:

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

  #4  
Old April 10th, 2009, 10:32 PM posted to microsoft.public.access.forms
Dan Williams
external usenet poster
 
Posts: 11
Default "No current record" after Quit in Form_Unload

Thanks, y'all!

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

Thanks again!
Dan



On Apr 9, 11:50*am, Dorian wrote:
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".



"Dan Williams" wrote:
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 -


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.