Access CurrentUser Function: Are There Any Benefits Here?

Access CurrentUser Function: Are There Any Benefits Here?

Some of my students during a training session recently discovered the Access CurrentUser function listed from the Expression Builder tool which is one of the predefined members of the MS Access ‘built-in functions’ category and assumed it would return the currently logged on user (via a network) but in all cases it showed as ‘Admin’.access currentuser

So why bother using this function at all? Well, it’s really a legacy function from the throwback to the earlier format ‘MDB’ files which used the Workgroup Security utility (and has now been dropped with the later ‘ACCDB’ versions).

Also, every time you started your Access database, the system generates a same named locking file (ldb/laccdb) which stored one or more of the machine’s name (multi-users) but not the actual user so this is really not the same thing. So how do you  get the true user name via a network ID in your Access database to really identify who’s who?

Access CurrentUser Function: A Bit Of VBA Is The Answer Here

The answer is naturally going to mean some Access VBA code but don’t worry about not being a programmer. Here’s some VBA code for you to replicate into a blank new module:

VBA GetUserName Function

I’m not going to explain how it works just accept that it does. What we needed to do here is use what is known as a Windows API call which is shown above the dividing line there and the next part being the actual function to return the network user name and that is called in the same away any Access built-in function is utilised which means via a query, form or report.

So, in my query example (below) you can now see both the built-in Access CurrentUser function and the newly added custom function (column two) called GetUserName.

access currentuser

This function is also reusable across one or more objects or databases and you may want to start keeping a library of useful and generic Access VBA codes that can either be copied/pasted or imported into your Access databases.

Some developers have built there own user log-in tools including the one I offer here too which is guaranteed to work and comes with a 100% refundable no questions asked policy if you are not satisfied!

Therefore, are there any benefits to using the built-in CurrentUser function with modern Access database files? No, not really!

This entry was posted in Database Theory, Modules, MS Access, VBA and tagged , , , , . Bookmark the permalink.

One Response to Access CurrentUser Function: Are There Any Benefits Here?

  1. After exploring a number of the blog posts on your blog, I seriously like your technique of writing a blog.
    I added it to my bookmark website list and will be checking back soon.
    Take a look at my web site too and tell me what you think.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Confirm you are human.