Noting exit time

  • Thread starter Thread starter Ed Finley
  • Start date Start date
E

Ed Finley

I am trying to record the time people open and close my front end
application. I have this in the form open event: OnTime=Now(). When I put
"OffTime=Now() in the form unload event, sometimes it works, other times it
crashes. I get: runtime error '2448'; You can't assign a value to this
object. I'm sure there's an easy fix and any help will be appreciated.
Ed
 
Ed,

All I can suggest is that possibly the form's Unload event is too late
in the process. Maybe you should try setting the OffTime value as
part of whatever procedure you use to close the form in the first
place. To be honest, I am surprised that setting the OnTime on the
form's Open event works... I would have expected this to be too early,
and would myself tend to prefer Load or Activate or Current.

- Steve Schapel, Microsoft Access MVP
 
Steve,
I will change the OnTime to the forms on Load event, that seems like better
programming. What is the sequence of events when a form closes? I should
probably try the first event there. I have an exit button on the form which
writes the off time. I'm trying to capture this time even if someone exits
Access without that button and the form open. What happens when someone
exits Access with its close button with a form open? Does it still go
through it's unload events?
Ed
 
Ed,

When a form closes, this is the order of the events:
Unload => Deactivate => Close
If the application is closed by closing Access, all these events still
occur for any form open at the time. As I said before, I would avoid
making data edits on the Unload event of a form closing as part of the
database closing. Some database developers, including myself, make it
difficult to close the application except via the button provided for
the purpose :-) Here is an sketch example of how you can do this...
In the declarations section of the form module:
Dim AllowClose as Boolean
On the Load event of the form:
AllowClose = False
On the Click event of the exit button:
AllowClose = True
DoCmd.Close etc
On the form's Unload event:
If Not AllowClose Then
MsgBox "Sorry, click the button!"
Cancel =True
End If

- Steve Schapel, Microsoft Access MVP
 
Thanks again, I'm getting close but still not there. This button is to quit
the whole application, not just close the form. When it's pressed I'm
storing the time, setting AllowClose to true, then Do.Cmd.Quit. Somehow
when I get to the unload event the AllowClose has already been dumped and is
showing up False. I can't get rid of the message box.
Ed
 
Ed,

Try it like this...
AllowClose = True
DoCmd.Close acForm, Me.Name
DoCmd.Quit

Post back again if that doesn't fix it.

- Steve Schapel, Microsoft Access MVP
 
Steve,
Thanks 1,000,000. That did it.
Ed
Steve Schapel said:
Ed,

Try it like this...
AllowClose = True
DoCmd.Close acForm, Me.Name
DoCmd.Quit

Post back again if that doesn't fix it.

- Steve Schapel, Microsoft Access MVP
 
Back
Top