Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Environ("Username") not working for one person

Status
Not open for further replies.

GingerR

MIS
Apr 17, 2001
3,134
US
Hey there. I've been using Environ("Username") successfully for years. Just deployed a new db recently, and one person gets an error. After investigating on his machine, the error is it doesn't recognize "Environ". I checked the references and none are missing (I have DAO 3.6 and Active X Data Objects 2.5 Library). Company standard is Windows 2000 SP4. I didn't check for SP on his machine but he has Win 2000 for sure, and chances are it's SP4 since they push our updates. Access XP (2002) SP3.

Any ideas what I can check on? Thanks.
 
Check in Control Panel>System>Advanced...

Does the environment variable exist?

Ed Metcalfe.

Please do not feed the trolls.....
 
Hi Ed. Thanks for the help.

I checked my own machine first (where of course it works fine) and do not see this variable. I hit ADVANCED, then ENVIRONMENT VARIABLES, but don't see "username" anywhere. At the top of that screen tho it says "User Variables for xxx0000" where xxx0000 is my personal 'username'. I guess I can go check that on my funky user's machine.

What do you think?
 
OK I'm on the user's machine. Do the same as I did in the last post and while the top of the ADVANCED/Environment Variables screen correctly states his 'username', access is still not reading/gleaning/getting it.
 
Following another post's tip, i've gone to command prompt, entered SET and indeed username = 000xxxx is right there with this user's correct ID that I'm looking for. eek....
 
ok more..sorry for the little notes...environ("Username") works in code module, but not in a query.
 
OK I fixed it. I'll post in case this helps someone else. And if any of you have any insight as to why this occured, please let me know. Maybe the user installed something else that changed this setting?

Searching all over today for an answer. Reading about this 'sandbox' registry setting which comes with Jet 4.0 SP8. We have SP7. So I didn't think it applied to me. Plus I don't know how that user's registry setting would get changed. My 'sandbox' registry setting was set to 2. Two coworkers = 2 as well. Bad user's = 3. I changed his setting to '2' and now it works fine.

Here's the article that helped me understand what this setting is all about, and why I get these pop-ups at home (Access 2003):
I was a little afraid that I'd someone messed up his machine because I worked on the db at home this past weekend (Access 2003) but of course there are a ton of users without the problem, and he actually reported the problem to me last week, before I took it home. phew.

although there's a post on MS about this ( at the time I read it I couldn't conceive of this being the problem, and I didn't want to mess with the registry. After a coupla hours of troubleshooting though, this was the last thing I hadn't tried yet.

WARNING: don't mess with the registry without taking precautions.
 
Use the following API and you should get by any Environ() weaknesses. That can be hacked and altered by even novice usere. Using the API is more direct and sure.
Code:
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Put a wrapper on that and it'll do fine--plus it works on win9x where Environ() may not exist at all.
--Jim

 
Hi Jim--thanks. I've seen that code before, and even used to use it a long time ago. When I discovered Environ("Username") (while working at MS, no less:)) I thought "wow this is so much easier". I've been using it just fine for years. I suppose I'll go back to the code you suggest, and go back and clean up all my existing databases. Obviously I can't expect all machines in the company to be set up properly, and exactly the same, especially when the co. allows access to the internet. I guess I've just been lucky all this time. Thanks for pushing me back over the fence...
 
Hey Jim--on second thought--i've read plenty of posts/articles this morning that cite different functions not operating as well. In the MS article it cites mulitple functions that won't operate with the various sandbox settings. So I guess the issue is more than just "environ".....I think we have to have the sandbox setting at 2 or 1 or 0....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top