Record user logout

DataMinerHome

Registered User.
Local time
Yesterday, 16:46
Joined
Jan 4, 2010
Messages
57
I have a form called "Hidden" which opens in hidden mode, via the db's autoexec. The autoexec also logs a "login" record to a table. Form Hidden's close event logs a "logout" record.... at least most of the time. Sometimes the logout record does not get recorded, and I don't understand why. Any guesses? Or is there a better way to do this?

Thanks for any ideas...
 
well with just a "sometimes it does not get recorded" statement, it's hard to discern anything.
 
Hmm, well, I agree. I wish I had more information to give you. What would you like to know? All I know right now is that sometimes, although it's clear that the user is no longer using the database, there was no "logout" record recorded. And I am looking for ideas as to why this would be? I mean, if the database closes, form Hidden must close, and therefore form Hidden's close event should fire. Right? So what do you suppose can keep this from happening?

Is there a better way to always run a slice of code on exiting the database? Like some sort of autoexec, but one that runs on closing instead of opening?
 
are you the "dataminer" UN with a UN based at home now? Just like "galaxiom" and "galaxiomathome"?? If you are, haven't you been around here while? Sorry, but you should know what to tell me, I would think. ;)

how about these:

  • HOW does a user close your db? (button, any other method avail?)
  • what code is behind the hidden form's CLOSE?
  • how do you record a user "log in" rec when the db is opened?

based on what you said already, my first suspicion would obviously be that you have code behind a button somewhere that says something like:

Code:
application.quit

but no code before that line that says something like:

Code:
docmd.close acform, "hiddenform"

but I guess you said that this sometimes doesn't happen. Whenever I hear someone say that, my first suspicion is that some piece of code somewhere is executing faster than the previous operation can execute. For instance, I wrote a small module just last week that looked like this:

Code:
        Case 6 'AFTER GENERATE DB
            Shell Environ("COMSPEC") & " /C " & _
                "RMDIR" & " " & _
                """" & baseDir & "1106" & """" & "/S/Q"
            sourceFolder = "6 - after_generate_db"
            MkDir (baseDir & "1106")
            Shell Environ("COMSPEC") & " /C " & _
                "XCOPY" & " " & _
                """" & baseDir & sourceFolder & """" & " " & _
                """" & baseDir & "1106" & """" & "/E", vbHide

        Case Else
            MsgBox "No valid stage number was entered.", vbCritical, "Error"

    End Select

Exit Function

eh:
    'If error 75, RMDIR did not execute fast enough and MKDIR
    'threw an error because the old 1106 dir still existed.  Run it again.
    If err.Number = 75 Then
        Resume
    Else
        MsgBox "Error: " & err.Number & vbCr & vbCr & err.Description
    End If

End Function
so there, my DOS command that was doing the RMDIR() and deleting about 600MB of files in that dir was taking too long and when my code got to the MKDIR() command, it was erroring out because the dir still existed. (there are better ways to fix this, but this was just a test of mine)

Could that be a possibility with your situation perhaps? I doubt it, but you never know!
 
Last edited:
In answer to you questions:
1. To close, user clicks a button which has embedded macro with action "quit". I do not have the closeform stuff before it. I will try adding that... but I seriously doubt that it is going to make any difference, as I think the problem stems from those seeming unavoidable "abnormal exits". What I am looking for is some way to record a logout when the database closes for ANY reason.

2. Behind form Hidden's Close is:
Loguserinfo ("LogOut")

LogUserInfo code is:
Function LogUserInfo(UserEvent As String)
Dim PCName As String
Dim DB As Database, RS As DAO.Recordset, LogTime As Date
If Len(PCName) = 0 Then PCName = "Can't identify"
LogTime = Now()
Set DB = CurrentDb
Set RS = DB.OpenRecordset("runlog", dbOpenDynaset)
With RS
.AddNew
!itemname = UserEvent
!databasename = DB.Name
!Userlogin = fOSUserName
!rundate = LogTime
!pc = fOSMachineName
.Update
End With
RS.close
DB.close
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function
Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function

3. In the autoexec of the database is
loguserinfo("login")
 

Users who are viewing this thread

Back
Top Bottom