Pop-up when user logs in and logs out (1 Viewer)

evictme

Registered User.
Local time
Yesterday, 19:44
Joined
May 18, 2011
Messages
122
Hello all,

I want to create a form thatll be open hidden for my user account and will be visible when a user logs-in or logs-out

For capturing user activity and log-ins I have a form already that is open hidden when they log in (see below) and will capture both when they login and log out.

I just want for a form to pop up, if I am logged in, with the user info.

Any ideas as to where would be best to start?

Code:
Private Sub Form_Load()
On Error GoTo Err_Form_Load

DoCmd.SetWarnings False
If CurrentUser() <> "Admin" And DCount("*", "tblCurrentlyLoggedIn", "empCurrentlyLoggedIn=" & Chr(34) & CurrentUser() & Chr(34)) > 0 And DCount("*", "tblCurrentlyLoggedIn", "empEnviron=" & Chr(34) & Environ("computername") & Chr(34)) > 0 Then

DoCmd.Close acForm, "Splash", acSaveNo

DoCmd.RunMacro "mcrHide"
DoCmd.OpenForm "uhoh", acNormal, , , , acWindowNormal
DoCmd.OpenForm "frmWarning", acNormal, , , , acHidden

DoCmd.SetWarnings True

Else

CurrentDb.Execute "Insert Into tblCurrentlyLoggedin (empCurrentlyLoggedIn,empEnviron) " _
                & " values ('" & CurrentUser() & "','" & Environ("computername") & "')", dbFailOnError


Set rs = CurrentDb.OpenRecordset("SELECT * FROM ButtonClicks")

rs.AddNew

rs![ButtonClick] = "Logged-In"
rs![ClickTime] = Time()
rs![ClickDate] = Date
rs![User] = CurrentUser()
rs![SearchInput] = Environ("Computername") & " " & DLast("Version", "qryVersion")

rs.Update
rs.Close

Set rs = Nothing
End If


Exit_Form_Load:
     Exit Sub
Err_Form_Load:
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM ButtonClicks")

    rs.AddNew

    rs![ButtonClick] = "Error " & Err.Number
    rs![ClickTime] = Time()
    rs![ClickDate] = Date
    rs![User] = CurrentUser()
    rs![SearchInput] = Err.Description

    rs.Update
    rs.Close

    Set rs = Nothing
Resume Exit_Form_Load

End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:44
Joined
Oct 29, 2018
Messages
13,751
Hi. Have you tried looking at some examples of this online. There are several demos of user log in/out forms available here and other places.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:44
Joined
Feb 28, 2001
Messages
18,747
Are you trying to see in your session that someone else logged in or out in their session on a separate machine? I'm not sure whether that point was clear in the question because I suspect both of my colleagues answered a slightly different question. Please clarify.
 

arnelgp

error reading drive A:
Local time
Today, 09:44
Joined
May 7, 2009
Messages
11,171
there are Many easy way to do it without much commercials:)
 

evictme

Registered User.
Local time
Yesterday, 19:44
Joined
May 18, 2011
Messages
122
Created a form that loads hidden for my user account and requeries the recordset every second, I have the recordset requery on the switchboard timer which goes every second to update the current time on the switchboard itself.

A small form that only does a few things. That after opening will launch another hidden form with a 5-second timer. I can click close or let the timer catch it.

The following is the code for that form named Form_Popup:
Code:
Option Compare Database

Private Sub Command3_Click()

Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblCurrentlyLoggedIn")

  rs.FindFirst ("popup = " & "-1")
  If Not rs.NoMatch Then
    rs.Edit
    rs.[popup] = "0"
    rs.Update
    rs.Close
  End If
Set rs = Nothing

[Forms]![popup].Visible = False

End Sub

Private Sub Form_Timer()

Me.Recordset.FindFirst "popup = " & "-1"

If CurrentUser() = "Admin" Then
Me.Recordset.FindFirst "popup = " & "-1"
If [Forms]![popup]![popup] = "-1" Then
[Forms]![popup].Visible = True
DoCmd.OpenForm "frmTimer", acNormal, , , , acHidden
End If
End If

End Sub

Im sure there are more efficient ways of doing this but for now it solves my need. Im still looking for a solution to having it requery every second. Will continue to do research but wanted to share in case other users are looking for a different solution.

Thanks all!
 

Users who are viewing this thread

Top Bottom