views:

462

answers:

3

Is there a way to set up a function that will get the user name of the user's LAN sign on, to use for the =(getusername) within Access? Is there some general vb that will work for this idea?

thanks!

+3  A: 

An article with some code: you just need a call to the Windows API.

gbn
thanks very much for the help!! much appreciated!
Justin
+2  A: 

The most painless way is:

myLanName = Environ$("USERNAME")
Oorang
thanks very much!
Justin
Environ is one one of the functions that is blocked in sandbox mode: http://office.microsoft.com/en-us/access/HP010447361033.aspx
Remou
It will only be blocked if you try to use it unwrapped in validation rules, SQL etc. But you can call it via VBA just fine. And if you happen to want to call it via a form validation rule you just need to wrap it in a UDF. (Just as you would have to call your COM function via VBA.)
Oorang
And it can be changed at runtime by the end user. Open a command prompt, change the environment variable, and then run Access from that command prompt and you'll get whatever the hell the user put in the environment variable. NOT RECOMMENDED -- the API call is vastly more reliable.
David-W-Fenton
That's not true, try it:) The OS will make it look like you have changed it for the console session, but it's not really changed. If you close the cmd window and reopen it you will see the USERNAME variable has reverted to it's proper value. At all times the Environ$ command will continue to report the correct value. There is, therefore, still no reason to engage in such a over-engineered approach.
Oorang
+1  A: 

Answered: http://stackoverflow.com/questions/168659/how-can-i-get-the-currently-logged-in-windows-user-in-access-vba

Remou
cool thanks! i didn't see it!
Justin