Making a User Log Table (1 Viewer)

adam.grendell

Registered User.
Local time
Yesterday, 19:47
Joined
Dec 7, 2011
Messages
21
Hello all!

What I am needing to do is create a table that logs whenever some one logs in, and then when they log out. I've created a Multi-User Login form, and my splash screen has a logout button which takes you to the login screen (and if done correctly, creates a record in a table every time the user logs in and out). I've tried to wrap my mind around it but it's not working. Please help!:confused:
 
You can look at Aphrodite in the sample db forum. It has a function that logs anytime any function is used. You can use that.
 
That is what I needed, yet I'm still having some issues. The login form I use gets data from a Users Table. It has an ID # (primary key), Name, and Password. I've applied the code to add a record to the tblLogTime for User and TimeIn. The code works and adds a timestamp, but in the User column, it just inserts the ID# from the Users Table instead of the Name selected in the login form. I've torn the code apart trying to figure it out, but it's just not working. Any advice?
 
Use dlookup to pull a value from your user table.
Code:
dlookup("name of the field you want to use","your user table name name", "[your useridname]=" & me.your combobox name)
 
Okay, I've got this narrowed down just a bit more. I converted the data in my combo box (the user name) to a string and called it into my table (same thing with the time stamp). Now, when I click the logon button, a record is made in the Log Time table with a User and a Time In. The Time Out, however is another problem. When they click the Login Button, the login form creates a record and then closes. How do I make a logout record since the data from the user name combo box is erased once the form is closed. Here is an example of what I'm trying to do.



Private Sub cmdLogin_Click()

Dim strLoginDate As String
strLoginDate = Now()
Dim rst As DAO.Recordset

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("txtPassword", "tblUsers", _
"[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value


Me.cboEmployee.SetFocus
Dim strEmployee As String
strEmployee = cboEmployee.Text
'Close logon form and open splash screen
Set rst = CurrentDb.OpenRecordset("tblLogTime", , dbAppendOnly)
rst.AddNew
rst![User] = strEmployee
rst![TimeIn] = strLoginDate
rst.Update
rst.Close


DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Splash Form"


Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If


End Sub





The above code works for getting me the Name and Time In in my Log Time table. I don't know what to do next to get the Time Out stored in the same table with that person's name. I know I'm close to getting there, I just don't know what's next. Any help is greatly appreciated.
 
Usually login forms are left open so that they can be used later in the application. The username is relevant for logging things, and for determining user privleledges. You can leave the login form open, but hidden. Alternatively, you could set a global variable to that of the username in the combo box after update event.

edit- Try and wrap your code with
Code:
 and [ /code] minus the space.
 
Thanks for the info guys. I've never used global variables before. How would I use one? Does it need to be public or private? I guess what I'm asking is how to I make one and use it with VBA? I've tried to look it up, but I get misdirected a lot.
 
In a standard module in the declarations, declare it as public. I usually make one module called mdlGlobals to house all of my globals, this way at a glance I can see how I have declared them.
Code:
Public g_strYourStringVariable as string
Public g_intYourIntegerVariable as integer
Public g_booYourBooleanVariable as boolean
Now anywhere in your db, you can set this variable, and use it anywhere.
 

Users who are viewing this thread

Back
Top Bottom