Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log Users Without Setting Up - User Groups?? 3

Status
Not open for further replies.

bigred925

MIS
Jul 6, 2001
15
US
The Mgt wants to be able to log who is using the database(by system #), but they don't want me to assign user groups because then someone would have to maintain them. Is there a way to do this. Thanks
 
Go to microsoft site and download a small program called LDBView.exe

This shows all the current users by machine number.

There is also some code you can downlaod so you can incorporate the ldb viewwer into your applications if needed
 
Red,

Assuming you only wish to see who has logged on and when:

Create a new table

tblUsers

Fields:
UserName
DateTimeLoggedOn

Then create a public sub

Public Sub UserLogon()

Dim myDb as Database
Dim myRst as Recordset

Set myDB= CurrentDB
Set myrst=currentdb.openrecordset("select * from tblUsers")

with myrst
.addnew
!UserName= Environ("username")
!DateTimeLoggedOn=now()
.update
end with

myRst.Close
myDB.Close

End Sub

Call the sub from an appropriate point and it will append a new record for every log on.

Not tried it but should work in an NT environment.

Craig
 
How/what value do you pass to the sub routine when you call it?
 
There's nothing to pass to the sub. It's not a function so it doesn't need anything to be passed into it.

All it does is open up the table, add a new record, write to the record and close the recordset. Worked for me this afternoon when I tried it.

Craig
 

Personally, I like the following code because it is simpler. Call the subroutine from an appropriate place in the application such as the On Open event of the starting form.
[tt]
AuditTrail table
RecID Autonumber
LoginName Text ' Access login
UserName Text ' Windows Username
AccDateTime date/time ' current datetime

Sub AddAuditRec()
Dim db As Database
Set db = CurrentDb()
db.Execute ("INSERT INTO AuditTrail (UserName,CompName, AccDateTime) SELECT CurrentUser(), '" & Environ("username") & "', Now();")
db.Close
Set db = Nothing
End Sub[/tt] Terry Broadbent

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 

PaulF,

Excellent reference. Thanks. Terry Broadbent

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Terry

thanks... it's amazing what you can find out there in the MS site, if you do a little rummaging around.

PaulF
 
JUst a brief not of caution. For the ".LDB" file approach, you NEED to be aware that the file IS NOT an accurate reflection of who is currently "Logged On" the db. It is an internal system file for record locking and may (often does) include the "names" of users who have been logged on - but who have logged off and gone on to other endeavors.

For the Ms. Soloution, the file/table of users will ONLY be an actual list IF no user has exited the system via any path other than the Startup form. This INCLUDES users who have simply turned off their machines, those who have had their system 'Crash', the ones who got tired / lazy and jsut used task manager to "Kill" the app ... Further, to even make the process semi-reliable, you need to remove ALL of the normal exit paths, such as the "Close" button on the titlebar, the Exit item on the file menu, the Open Item on the file menu, The Close button on the database window title bar ... I really don't know how many others. The capability to use the immediate window ... (Yes Dorthy, typing quit into the immediate window WILL CLOSE Ms. Access). Stop users from creating or modifying Macros and procedures ...

If you still think maintaining the users and groups is less "trouble" than the above, then you should "Go For It". But JUST one more item. To be useful, you not only need to know that a user was "in" the data base, but what the "DID", as in records added/edited/modified. There is an Wxcellent FAQ (pat my back, pat my back, pat my back) on maintaining a transaction log for Ms. Access faq181-291 which is useless if you do nnot have "proper" usenames.

O.K. No more 'soap box'.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Craig0201's approach does exactly what it say's on the tin; and DOES with NT. V useful.

Thanks
 
For Craig0201,
Tried your code out of curiosity and
DateTimeLoggedOn
returned an invalid field name error.
Changed it and the code and it worked fine.

Throadbents worked also and did a wee bit better.

Just an FYI
Rhonin
"too many questions, too little time..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top