Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Who's logged into my database?

Status
Not open for further replies.

chrisaroundtown

Technical User
Jan 9, 2003
122
AU
Hi,

I have a main form which has hidden fields which record the username, time logged in and time logged out to a table.

When the databsase is opened the main form launches through the start up and the username and time logged in fields are updated. If the user exits the database by using an exit button I have on the main form the Close event is activated on the form which updates the time logged out before exiting the database.

The problem is that if a user closes the database by hitting the X in the top right corner of the database, or by hitting Ctrl + Alt + Del and ending the task, the Close event on the form is not called and hence the database exits without the time logged out field being updated.

How can I have the Close event from the main form run whenever the database is exited?

Thanks
Chris
 
The OnClose Event should fire whenever and however the form closes, even by clicking the X or Ending Task with Ctl-Alt-Del.





Sam_F
"90% of the problem is asking the right question.
 
It doesn't.

If I run the following code the close event from the form does not fire:

DoCmd.Exit

In order to get the close event to fire I have to run the following code:

DoCmd.Close
DoCmd.Exit

Any idea on how I can get the Close event to fire when the X or Ctrl + Alt + Del is used to exit the application?

Thanks
Chris
 
I put this code in the OnClose event, and no matter how I close the form or the db, the msgbox pops up, indicating that the event has fired. Try it.

Private Sub Form_Close()
MsgBox "I'm closing now."
End Sub


Sam_F
"90% of the problem is asking the right question.
 
You are right, the event does fire. But it is not doing what I want it to do.

I have isolated the problem to the following line of code
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

For some reason, when I close the form only this line works and saves the record. When I use the X it doesn't save.

Any ideas on why?

The full code I am trying to run is below.

Private Sub Form_Close()
txtDBLogoutTime.Visible = True
txtDBLogoutTime.SetFocus
txtDBLogoutTime.Value = Now()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
btnNewCall.SetFocus
txtDBLogoutTime.Visible = False
End Sub

Thanks
Chris
 
Try an action query like:
DoCmd.RunSQL "INSERT INTO ... VALUES ..."

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top