All; I am using access 2010 but working with an access 2003 database. This is split with frontend mdes on users desktop and be on the server. I've been looking for a way to find out who's logged in. All the ones I found gives me only the computer name and time users log in and off.
I did find this code courtesy of datawright that seems to give me what I need but the concept is that a hidden form is suppose to launches when the users open the database. I do have a login form user name and password. When I test it; nothing happened. But then; it was not until I opened the monitoring form that it gave me the results I needed. The problem with this is; it doesn't give me the other users in the database. I am afraid that is because It's not launching when they open the database. The following is the code in a module:
Code:
Function LogOn()
Dim sUser As String
Dim sSQL As String
DoCmd.SetWarnings False
sUser = Environ("username")
sSQL = "INSERT INTO tblUserLog ( UserID )" _
& "SELECT '" & sUser & "' AS [User];"
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Function
Function LogOff()
Dim sUser As String
Dim sSQL As String
DoCmd.SetWarnings False
sUser = Environ("username")
sSQL = "UPDATE tblUserLog SET tblUserLog.LogOff = Now() " _
& "WHERE tblUserLog.UserID='" & sUser & "' AND tblUserLog.LogOff Is Null;"
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True
End Function
This is the code that is suppose to launch the monitor form:
Code:
Option Compare Database
Option Explicit
Private Sub Form_Current()
Me.Visible = False
End Sub
Private Sub Form_Load()
modUserLog.LogOn
End Sub
Private Sub Form_Unload(Cancel As Integer)
modUserLog.LogOff
End Sub
I also have a form that only I can get to in a frontend mdb. All the forms and modules were in the mdb frontend before creating the mde. So all the users have the monitor form that is suppose to launch. The table is in the be that everyone points to. Here is the code for the form:
Code:
Option Compare Database
Option Explicit
Const sSELECT = "SELECT tblUserLog.UserID, tblUserLog.LogOn, tblUserLog.LogOff " _
& "FROM tblUserLog "
Const sWHERE = "WHERE (((tblUserLog.LogOff) Is Null)) "
Const sORDER = "ORDER BY tblUserLog.LogOn DESC;"
Dim sSQL As String
Private Sub cmdAll_Click()
sSQL = sSELECT & sORDER
With Me.lstUsers
.RowSource = sSQL
.Requery
End With
Me.lblUsers.Caption = "Full Log"
End Sub
Private Sub cmdClose_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdCurrent_Click()
sSQL = sSELECT & sWHERE & sORDER
With Me.lstUsers
.RowSource = sSQL
.Requery
End With
Me.lblUsers.Caption = "Currently Logged On"
End Sub
Can anyone see why the monitor form does not launch please!
Thanks