Application close event? (1 Viewer)

pedie

Registered User.
Local time
Yesterday, 22:59
Joined
Aug 3, 2011
Messages
20
Is acccess application close event? like thisworkbook.close event? rather before close..
'm trying to make the event triger the code and maintain in and out from database log....


If anyone has anyidea...please help me out....

Thanks in advance:)
 

MarkK

bit cruncher
Local time
Yesterday, 22:59
Joined
Mar 17, 2004
Messages
8,186
You open a hidden form, leave it open, and when the application is going to close you handle the Unload event of that form.
And if you cancel the Unload event on that form then the application won't close, so this also allows to effectively disable the Windows close button.
Cheers,
Mark
 

pedie

Registered User.
Local time
Yesterday, 22:59
Joined
Aug 3, 2011
Messages
20
Thanks for the idea....

I tried this way form does not get hidden...
Code:
[/FONT]
[FONT=Courier New]Option Compare Database
Option Explicit
Private Sub Form_Close()
'close activity?
End Sub
Private Sub Form_Load()'start up form
 Me.Visible = False
 'DoCmd.Close
 DoCmd.OpenForm "Login Dialog"
End Sub
 

MarkK

bit cruncher
Local time
Yesterday, 22:59
Joined
Mar 17, 2004
Messages
8,186
Try ...
Code:
DoCmd.OpenForm "FormName", , , , , acHidden
 

pedie

Registered User.
Local time
Yesterday, 22:59
Joined
Aug 3, 2011
Messages
20
Hi, one more small problem...
I tried this way and tried trigerring code on unload
the code runs and does not end....and then the access file stops responding....everytime i close the database..

Please advice

Thanks again
Code:
[/FONT]
[FONT=Courier New]Private Sub Form_Unload(Cancel As Integer)[/FONT]
[FONT=Courier New]Call LogMeOut[/FONT]
[FONT=Courier New]End Sub
Code:
[/FONT]
[FONT=Courier New]Sub LogMeOut()[/FONT]
[FONT=Courier New]Dim db As DAO.Database
Dim rst As DAO.Recordset[/FONT]
[FONT=Courier New]Set db = CurrentDb
Set rst = db.OpenRecordset("BTLog", dbOpenDynaset)
'rst.MoveFirst
While Not rst.EOF
If rst!x_id = UCase(Environ("Username")) And rst!OutStatus = False Then
         rst.Edit
         rst!Logout = Now
         rst!Total = (rst!Logout - rst!Login)
         rst!OutStatus = True
         rst.Update
End If
rst.MoveNext
Wend[/FONT]
[FONT=Courier New]rst.Close
db.Close
Set rst = Nothing
Set db = Nothing[/FONT]
[FONT=Courier New]End sub[/FONT]
[FONT=Courier New]
 

MarkK

bit cruncher
Local time
Yesterday, 22:59
Joined
Mar 17, 2004
Messages
8,186
To show or hide a form after it opens you can set the form's visible property.

As far as your loop goes there, it doesn't look endless. Why doesn't it end? What's endless about it?
Are you sure something else isn't happening, like do you have the database set to compact on close. Maybe when you close it it does a compact & repair.

As a separate issue I would avoid that loop. Open a recordset using exactly the SQL you need for the record you want to update, like...
Code:
set rst = currentdb.openrecordset( _
  "SELECT Logout FROM BTLog " & _
  "WHERE x_id = '" & ucase(environ("username")) & "'")
with rst
  if not .eof then
    .edit
    .fields(0) = now()
    .update
    .close
  end if
end with
... so there's no loop.
A few other points, in a database you want to avoid any situation where your data may be in conflict with itself, or where you duplicate the same data. So, you have a field called OutStatus, but OutStatus, it looks like, is always true if LogOut > LogIn. So then you don't need a field for it. If you want to display the concept of OutStatus, write a query with this field...
Code:
OutStatus: LogOut > LogIn
This same reasoning applies with your field Total. Not required. It duplicates a result easily returned by Logout - Login.
When a user logs out you describe that event completely by recording 1) who logged out and 2) when. Everything else is a calculation you can do when you retrieve data.
Just a few thoughts, hope you find them useful,
Mark
 

pedie

Registered User.
Local time
Yesterday, 22:59
Joined
Aug 3, 2011
Messages
20
Mark, thanks again for the usefull advice!!
 

Users who are viewing this thread

Top Bottom