• need %UserName% (2002) – SOLVED

    • This topic has 4 replies, 3 voices, and was last updated 19 years ago.
    Author
    Topic
    #431837

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #1011682

      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”).

      • #1011809

        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

        • #1011871

          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.

    • #1011675

      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%

    Viewing 1 reply thread
    Reply To: need %UserName% (2002) – SOLVED

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: