Running a piece of code on exit

Chimp8471

Registered User.
Local time
Today, 21:54
Joined
Mar 18, 2003
Messages
353
how can i get access to run a piece of code before shutting down.

I need to record the time that the user leaves the system, this works ok if they select exit via a menu button, but if they click the cross in the top corner or file--->Exit the database just ends. I am then unable to see what time they logged out.

Cheers

Andy
 
Open a hidden form as the very first thing the database does.

Put the code to record the time in that form's Unload event.
 
i just had a bet with someone in my office that Milo would be the first to offer any help........will give this a go....

Cheers

Andy
 
Hi Milo, i have had a look at what you suggested but have had no joy,

any chance you could have a look for me please

Andy
 

Attachments

Hi milo, once again thanks.

Trouble is this reaaly aint going as well as i had hoped.

i thought i would be able to just copy the following code into the unload area that you suggested and away we go........

but i keep getting an error saying it can't find the form....

Not sure i am even using the right code to be honest.

I just simply cut it from one of the exit button that when clicked do what i want them to.

the code i am using...

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click

Dim intResponse As Integer
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = currentdb()
Set rst = db.OpenRecordset("ztblUserLog", dbOpenDynaset)

Forms!fmnuMainMenu.Visible = False

intResponse = MsgBox("Warning: You are about to completely exit the database." & Chr(13) & _
"Are you sure you want to do this?", vbYesNo + vbExclamation, "Exiting Database")

Select Case intResponse
Case vbYes
rst.FindLast "SecurityID = " & User.SecurityID
rst.Edit
rst!TimeOut = Now()
rst.Update
DoCmd.Quit
Case Else
Forms!fmnuMainMenu.Visible = True
End Select

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub

please help

Andy
 
You can't do that as Access works on a first open, last closed basis.

Since you question was just to put the time in for a user leaving the system all you need to do is run an update query that changes the TimeOut field you want.


i.e.


Code:
Private Sub Form_Unload(Cancel As Integer)

    DoCmd.SetWarnings False
    DoCmd.OpenQuery "MyQuery"
    DoCmd.SetWarnings True

End Sub
 
Ok thanks for your input again,

I really have no idea on the best way to carry out what you suggested here, but just wondering if there is an easier way for me to work around this issue.

Bearing in mind that it does what it is meant to do, when the database is closed via a button on the form.

Is there no way i can disable the close (cross in the top right hand corner) and also disable the exit facility from the menu, this way forcing them to use the buttons available.

sorry to keep on

Andy
 
Yes, you can disable the X button but it requires the use of a hidden form anyway, and since you just want to record when someone is leaving the database using an update query in the unload event of a hidden form should work fine.

Here's a recent example:
 

Attachments

Users who are viewing this thread

Back
Top Bottom