Results 1 to 3 of 3
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    who's logged in

    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Is modUserLog the general module that contains the functions LogOff and LogOn? I have never called a public function by prefixing with the module name but I suppose that doesn't hurt.

    I don't see anything that 'launches' monitor form or any form for that matter, such as:
    DoCmd.OpenForm "monitor form"

    That code you say is supposed to launch the form, won't. It is just code behind the form. The Current event will run after the form opens and loads.

    Maybe need to set this form to open as default when the db opens. This is a property of the database.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Thanks. I launched the form after login and it's working great!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. restricting access until logged in
    By gbmarlysis in forum Security
    Replies: 1
    Last Post: 02-17-2012, 06:43 PM
  2. Whos Logged in????????
    By george.vniekerk in forum Security
    Replies: 2
    Last Post: 08-26-2011, 12:24 PM
  3. logged user name on main form
    By foxtet in forum Forms
    Replies: 1
    Last Post: 07-30-2011, 03:00 PM
  4. Getusername of currently logged in user
    By nkuebelbeck in forum Access
    Replies: 8
    Last Post: 06-29-2011, 04:06 PM
  5. Currently logged in user into text box
    By ne16428 in forum Security
    Replies: 5
    Last Post: 06-10-2009, 11:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums