Viewing user ID of Users in a DB

andydtaylor

Active Member
Joined
Feb 15, 2007
Messages
360
Office Version
  1. 2016
Hi,

I found some code here which gives me the machine name:

http://support.microsoft.com/kb/198755

But this still requires I call IT to translate into user IDs.

Does anyone have any code I can recycle which captures the =Environ("username") of a user to a table when they log in, then detetes it when they log out?

Else can you suggest how I can code the 'delete when they log out' segment?

Thanks,


Andrew
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The first part's simple. On the main menu form (the one that launches when you open the DB), create a textbox with the expression
=Environ("username"). If you don't want users to see it, set Visible to No.

For the other bit, here's some air code:

You'll need some code that writes a record to a table like tblUserLog:
the table itself probably only needs 4 fields,
LogID (Autonumber)
UserID (Text)
LogOn (Date/Time), default value =Now()
LogOff (Date/Time)

You can write the record using SQL or DAO code; make the routine a function so it can be called from a macro, then create an autoexec macro that runs the function. That will create a new log record when a user opens the DB.

To log off, you need code that finds the user's current record and writes the current date/time to LogOff. This needs to be triggered when the user shuts down the DB.

Then, to see who's on, create a form with a listbox that displays all tblUserLog records where LogOff is Null.

Denis
 
Upvote 0

Forum statistics

Threads
1,215,809
Messages
6,127,012
Members
449,351
Latest member
Sylvine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top