2

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!

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
Justin
  • 4,461
  • 22
  • 87
  • 152

2 Answers2

3

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

gbn
  • 422,506
  • 82
  • 585
  • 676
2

The most painless way is:

myLanName = Environ$("USERNAME")
Oorang
  • 6,630
  • 1
  • 35
  • 52
  • Environ is one one of the functions that is blocked in sandbox mode: http://office.microsoft.com/en-us/access/HP010447361033.aspx – Fionnuala Jul 20 '09 at 10:31
  • 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 Jul 21 '09 at 04:26
  • 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 Aug 08 '09 at 00:01
  • 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 Aug 10 '09 at 14:56