form to view a record of each user's login dates (1 Viewer)

jun90

Registered User.
Local time
Today, 19:28
Joined
Jan 10, 2010
Messages
22
hi! please be patient with me. i am only a newbie in ms access.

may i know how can i go about keeping a record of the dates for each user who login to that form?

i have already created a table of users who can login and password. now i need to track each user's login dates. how do i do that?

i'll be very grateful for ur help! thanks and regards.
 

ntanh72

New member
Local time
Today, 04:28
Joined
Nov 16, 2009
Messages
7
2 ways:
you add a code to insert the username and time (getdate() or now()) to the log in tracking table.
you set defaut value of "login time" field in tracking table to getdate() and just create a code to insert username
 

McSwifty

Registered User.
Local time
Today, 23:28
Joined
Jan 14, 2010
Messages
67
Hi there,

Afte getting a lot of help from this forum and now having built a resonably complex app for work. I figured it is my time to give back to the community.
Here goes.

For my Ex below you need a table named tblUserLog
With the fields
UserId (text)No Duplicates - saved me having an autonumber field but you can refer the user as a number if you require.
LoginTime - Text
LogoutTime - Text

I also have other fields, ex. password and user level as i created my own login form for it, and form there use a dlookup to check the user level.

As i work a lot on tidying up and improvign the backend, I have also added a flag to show who is logged in.

Code:
Dim logintime As String
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
strSQL = "SELECT tblUserLog.UserID, tblUserLog.logintime, tbluserlog.logouttime FROM tblUserLog WHERE (((tblUserLog.UserID)= '" & UserName & "'));"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
rst.Edit
logintime = Format(Now(), "dd mmm yyyy -HH:mm")
rst!logintime = logintime
rst!logouttime = "Logged In Now"
rst.Update
rst.Close
Let me know if this helps any, please!!!


If you require the Log out code, I can be forthcoming if requested.
 

jun90

Registered User.
Local time
Today, 19:28
Joined
Jan 10, 2010
Messages
22
Hi there,

Afte getting a lot of help from this forum and now having built a resonably complex app for work. I figured it is my time to give back to the community.
Here goes.

For my Ex below you need a table named tblUserLog
With the fields
UserId (text)No Duplicates - saved me having an autonumber field but you can refer the user as a number if you require.
LoginTime - Text
LogoutTime - Text

I also have other fields, ex. password and user level as i created my own login form for it, and form there use a dlookup to check the user level.

As i work a lot on tidying up and improvign the backend, I have also added a flag to show who is logged in.

Code:
Dim logintime As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
 
Set db = CurrentDb()
strSQL = "SELECT tblUserLog.UserID, tblUserLog.logintime, tbluserlog.logouttime FROM tblUserLog WHERE (((tblUserLog.UserID)= '" & UserName & "'));"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
rst.Edit
logintime = Format(Now(), "dd mmm yyyy -HH:mm")
rst!logintime = logintime
rst!logouttime = "Logged In Now"
rst.Update
rst.Close
Let me know if this helps any, please!!!


If you require the Log out code, I can be forthcoming if requested.


hi! can u give me a sample of ur above database if possible? sorry for the trouble! n i would like to ask.. where the above codes are placed?
 

McSwifty

Registered User.
Local time
Today, 23:28
Joined
Jan 14, 2010
Messages
67
Hi Jun90,

Here is a sample of what you are more than likely after.

Hope it helps.

Remember to keep the list of users in the backend if you have a separated db.

:)



View attachment Sample_DB.mdb
 

jun90

Registered User.
Local time
Today, 19:28
Joined
Jan 10, 2010
Messages
22
thank you, McSwifty! :) ur codes really helps!

but may i know is it possible to store all the dates in which that particular user has login into the database throughout (like a period of 1 year) instead of being overwrite each time he/she log in?
 

McSwifty

Registered User.
Local time
Today, 23:28
Joined
Jan 14, 2010
Messages
67
Hi Jun,

Not really thought of that one.

You could make another table that has the name of the user in it, or an autonumber ID if you like that references to the user. and append the details each time rather than replace.

I am a little out of my league on that one, any one else got ideas using the example posted above?
 

jun90

Registered User.
Local time
Today, 19:28
Joined
Jan 10, 2010
Messages
22
actually i m creating a database where there is a form for new users register their particulars (which store inside a table).

after that, he/she can log in via another form and view his/her own individual status / preferences / settings (example, a record of all of his/her login dates, change his/her own particulars, etc). but he/her cannot view other users' status / preferences / settings.

this is the place where i m stuck. please help.. :(
 

ntanh72

New member
Local time
Today, 04:28
Joined
Nov 16, 2009
Messages
7
Hi June 90,

You can do below:
Create a table logcount with:

************
id: autonumber
userid: text
login time: date/time, default value = now()

************

Paste the below code to replace your current update login time code.

************
Dim mysql As String

mysql = "INSERT INTO logcount ( userid ) VALUES (" & Me.Username & ")"

DoCmd.RunSQL (mysql)

************

So it will insert a new record on you logcount table with userid and log in time everytime user log in successfully.
 

Users who are viewing this thread

Top Bottom