=environ("username")

PaulO

Registered User.
Local time
Today, 03:52
Joined
Oct 9, 2008
Messages
421
I have used this formula successfully in A2003 databases to establish the Network ID of the User of a database, and use this identity to determine what menus and/or features features are made available to that User.

A2007 seems to dislike this formula! :(

For now, I have found a 'fix' of sorts by changing the MS Office 'Sandbox' settings but I'm not particularly happy with this as a solution.

What I'd like is some short code that could be run in the "On Open" property of my "Splash" form, to read the Network ID of the User and post that ID into table!field (tbl_Logged_Users!User).

Anyone know any Code that could do this?
 
I have just tested Environ("username") in the immediate window of my application and it seems to work fine. Are you sure this is the issue and not something else in you code? Could you post the code you were using in AC 2003 that is not working in AC 2007 for review?
 
Hi Alan

is your's an A2007 database?
 
I use this code to check the user's name before assigning their user level

Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetUserName() As String
Dim userName As String * 255
GetUserNameA userName, 255
GetUserName = Left$(userName, InStr(userName, Chr$(0)) - 1)
End Function

The login procedure calls GetUserName and this has always worked fine for me
David
 
I know Environ("username") is a very common way to get the user but it returns the environment VARIABLE, not the actual username. The username is the DEFAULT value of that VARIABLE and that variable is very easily changed.

Get the actual USER like David suggests or use the simpler alternative:

Code:
myvariable = CreateObject("wscript.network").username

Here is where BobLarson and I argued the toss about using the Environment Variable recently. Perhaps this thread will cure his intransigence (or not ;)).
 
Yes, I read that dialogue and it's a little above my head! It sounds like many roads lead to Rome on this one!
 
Yes, I read that dialogue and it's a little above my head! It sounds like many roads lead to Rome on this one!

Except some roads sign posted as Rome will take you to Carthage sometimes if Hannibal gets involved.;)
 
I use the code below.

Code:
Dim suser As String
    Dim sSQL As String
    Dim CurUser As String
 
    suser = Environ("username") 'Name of real person
        'MsgBox "sUser = " & sUser
    'MsgBox "curUser = " & CurrentUser()

I should point out that our network pulls the username from a physical ident card connected to the machine.
 

Users who are viewing this thread

Back
Top Bottom