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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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 | |
|
|