How to Retreive and save Loginname from the Database Login?

G

Guest

hi,
I HAVE DEVELOPED AN ACCESS2000 BASED DATABASE, FOR INVENTORY CONTROL.

IT HAS LOGIN SECURITY WICH PROMTS USER FOR LOGIN NAME AND PASSWORD.

NOW THE PROBLEM IS TO RECORD THE LOGIN, AS WHO LOGGED IN TO THE DATABASE? AT
WHAT TIME ?ETC,IN A TABLE, SO THAT IT CAN BE RETRIVED LATER.

CAN ANYBODY SUGGGEST SOME IDEA?
THANKYOU
 
J

Jeff Conrad

Vijay,

Please do not post in capital letters, it is a little hard to read and it seems like you are
shouting.
Thanks.

Here is past post of mine which should help:

1. Create a new table called tblUserLog with the following fields:
LogID - Autonumber (Primary Key)
ProgramUser - Text
TimeIn - Date/Time
TimeOut - Date/Time

Save the new table.

2. I have a switchboard-type form that is the first form open via
Tools | Startup and is always open. You could do something similar
by creating a small hidden form that is always open behind the scenes.

3. In the Declarations area of the Switchboard form code module I have this:
Private dteLogInT As Date

(That could just as easily be put in a standard module as well and declared as Public)

4. In the Form's Load event I have this code:
(A reference to the DAO object library must be set)

'*************Code Start***************
Private Sub Form_Load()
On Error GoTo ErrorPoint

' Record this Login to tblUserLog
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblUserlog")
With rst
.AddNew
!ProgramUser = CurrentUser()
!TimeIn = Now()
dteLogInT = !TimeIn
.Update
End With

ExitPoint:
' Cleanup Code
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub

ErrorPoint:
' Unexpected Error
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub
'*************Code End*****************

5. In the Form's Unload event I have this code:

'*************Code Start***************
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrorPoint

' Record the time out in tblUserLog
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQLUser As String

Set dbs = CurrentDb()

strSQLUser = "Select * From tblUserlog " _
& "Where ProgramUser = '" _
& CurrentUser() & "' And TimeIn = #" & dteLogInT & "#"

Set rst = dbs.OpenRecordset(strSQLUser)
With rst
If Not (.EOF And .BOF) Then
'Record was found
.Edit
!TimeOut = Now()
.Update
End If
End With

ExitPoint:
' Cleanup Code
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub

ErrorPoint:
' Unexpected Error
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub
'*************Code End***************

This has worked fine for me for many years.
I can then create various reports off this table information.

Side note - Make sure you grant your custom groups appropriate
permissions to this table and/or change the code to use a saved
RWOP query.

Hope that helps,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top