Last Accessed




Is there a way to capture a persons pc user's login in a table in access
when it is opened.

eg User "A" opens the database, a table records that users pc user login,
then user "B" opens same database and a table records their pc user login as
the next record etc etc...

What I am trying to do is capture who last opened that database and or made


Douglas J. Steele


Douglas J. Steele

A switchboard is a form, so you've already got that part happening.

Take the code from and copy it
into a new module. (Make sure you don't name the module fOSUserName: modules
can't use the same name as routines within them)

Create a table (let's name it Usage for the sake of argument) that contains
at least 2 fields: UserId (a text field that's at least as long as your
longest user name) and LoginDtm (a date field)

Open your switchboard in Design mode, then add the following code to either
its Open or Load event:

Dim strSQL As String

strSQL = "INSERT INTO Usage(UserId, LoginDtm) " & _
"VALUES ('" & fOSUserName & "', " & _
Format$(Now, "\#mm\/dd\/yyyy hh\:nn\:ss\#") & ")"

CurrentDb.Execute strSQL, dbFailOnError

Each time the switchboard form is opened up, a row will be written to your

Doug Steele, Microsoft Access MVP

(no e-mails, please!)

pjd said:
Thanks for the reply.

I've set the database so that a switchboard opens automatically when the
databased is opened.

How do I "have a form that opens when you open the database, and have its
Open event write the user ID to a table"

I know very little about VBA.


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

Similar Threads

Record-Locking remains open after closing 0
Login capture 4
Access User Login form in Access with Ristriction 0
Employee Time Tracking 9
Security-Open Exclusive 8
Locked Records 2
Access query 2
Record Locking 2