Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    214

    Question Unanswered: How can I create a log of users opening a database

    I am running MS Access 2003, and I have the security and permissions set up. I want to be able to keep a log of the username and the time/date when they logged into the database. When the next person logs in, it will just append to the exisiting log.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Basically, to create a log table for a specific mdb and tracking when users get into it, you want to create a table with a LoginID (text) and DateTimeLoggedIn (date/time) fields.

    You can then put in code in the form which initially opens (not the Mainform which may open multiple times but an "initial" form such as a background form which opens once and initially - or just call the function to do the appending and then open your MainForm in the Tools->Startup). Your code will get the username/LoginID (see getuser() function here or in the code bank: http://www.dbforums.com/showpost.php...0&postcount=20) and will append the username/LoginID and the current time (i.e. Now()) to the table. Here's an example of code you could have in the onOpen event of the "background" or initial form which opens:

    (note: uses ADO)
    Dim rs as adodb.recordset
    set rs = new adodb.recordset
    dim strSQL as string
    strSQL = "Select * from MyLoginTableName"
    rs.open strSQL,currentproject.connection,adopendynamic,adl ockoptimistic
    rs.addnew
    rs!LoginID = getuser() <- from the getuser function
    rs!DateTimeLoggedIn = now()
    rs.update
    rs.close
    set rs = nothing
    Last edited by pkstormy; 11-21-07 at 16:12.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •