Hmmm. I think I may have overlooked the obvious ….. I can probably use CurrentUser, correct?
Sometimes it just helps to talk out the problem with someone else. Thanks for listening.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » need %UserName% (2002) – SOLVED
CurrentUser will return the Access username. If you have applied user-level security, so that users have to log into the database with a username and password, that is fine. However, if you have not applied user-level security, CurrentUser will always be Admin (the name of the default user). If you want the Windows username, you can use Environ(“username”).
Hans, hoping this will work for Rudi. The “environ()” used to return such useful information consistently, and probably still does but at one point, either after Windows 98 or Windows XP, it didn’t seem to work any more — not just in Access, but in a couple of other programs that were using something similar to the “environ()” function. In VB, we shifted over to that API call, the “getusername” (I think) which you and others have so kindly posted here at times. That’s been very dependable, whereas the “environ()” may have lost some of it’s “charm.”
Thanks for all you do, Hans.
Pat
Just to follow up, the use of Environ appears to be working good with Access 2003 on XP Pro system.
I am using the following code in a menu OnLoad trigger.
———————————————————-
Dim strUserName As String
strUserName = Environ(“UserName”)
If strUserName = “admin” Or strUserName = “bill” Or strUserName = “mary” Then
cmdDisplayDatabaseWindow.Visible = True
Else
cmdDisplayDatabaseWindow.Visible = False
End If
———————————————————-
Thanks to all for your inputs.
How can I get %UserName% from environment variable when database opens and then use that to allow acrivities?
Example, when Main Menu opens, some buttons should show for UserA and others show for UserB? Other actions would also be controlled by use of %UserName%
I can handle the code for the visibility, etc., I just need to know how to capture %UserName% ,as some type of global variable, for the session, to use in the IF statements.
We do not want to use the Access Security tools, just the %UserName%
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications