textbox control source = environ("username") not working

hey guys!

i know how to get the environ("username") in VBA no problem but recently i read this website (http://www.access-programmers.co.uk/forums/showthread.php?t=140708) and i wanted to try out the same but failed (attached is my empty database with just two textboxs and a form).

could yall share with me why it can't work? i don't think it's cause of sandboxing.

thanks guys!! = ))
Database1.mdb
developingprogrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Just use this
http://access.mvps.org/access/api/api0008.htm
so you don't have to worry about.

Time to move past Environ ()  :-)

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
0
developingprogrammerAuthor Commented:
cool!! thanks mx!! = ))

ok i'm reading up now on the Declares statement to understand a bit more on this topic.

hrmm mx,

1) why is the windows API better than environ() statement?
2) and also if you don't mind just for my learning purpose, why is my database not working when i put Environ("username") in the control source? thanks!! = ))
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

developingprogrammerAuthor Commented:
oops and mx, and did i use the term windows API wrongly here?

why is it better to use a call to a DLL rather than then environ which belongs to the interaction class in the vba library? i suppose the environ function is also calling to the dll? = )

thanks mx!! = ))
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Well, db needs to be in a Trusted Location and Macro Security set to Low.
And I think there is some other Sandbox setting in the Registry that needs to be tweaked - which  may not be feasible on a given user's system at a given Company.

Envrion() can easily be spoofed - to fake a user name.  You cannot spoof the Win API in this context.

I moved away from Environ() 3-4 years ago.

I would not worry about the Declares too much. They are what they are ... and this Function is flawless. It's in all of my apps at work.

Just put the code in a standard VBA module, and then put

=fOSUserName()  

in your text box.

Of course, you can rename the Function to something else if you like ... for example

GetUserName() or whatever.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
developingprogrammerAuthor Commented:
cool! that makes perfect sense = )

but how does one fake a username? i thought environ would get the windows ID direct.

thanks mx! = )
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You can Fake it from the Command Line in Windows ...

Something like

> Environ("UserName") = "BillyBobJo"

I've actually done in the past, just cannot remember the exact syntax
The bottom line is ... you can Set most (if not all) Environ variables.

It's  just not the 'pro' way to do things.

You can probably Google 'Spoof the Environ variable' ... :-)
0
developingprogrammerAuthor Commented:
GULP - not the PRO way of doing it.

GOTTA CHANGE IT NOW!!

developingPROprogrammer in action!! haha = ))

thanks so much mx once again as always!! = ))
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
lol ...
You're alright bro ...
take care. ...
zzzzzzzzzzzzzzzzTime ... in CA

Oh ... get This Book   now.

That ... is an order.
Don't ask questions ... just-do-it :-)

mx
0
developingprogrammerAuthor Commented:
Whao!! YES SIR!!

Haha okie dokes! Have a good rest and sweet dreams!! = ))
0
BitsqueezerCommented:
Hi,

the "Environ" function does not call any Dll. It is very primitive what it does: It uses the "environment variables".

Open a command line window (formerly called "DOS") and enter "Set" and enter key. You will see a more or less long list of variables where you also can see "Username" or "Computername". These are the variables which "Environ" reads out and gives back to you, nothing more.

The Windows API gets it's information directly from the Windows system, so there is no way to change the result, it is coming from the approved Windows login (of course some hackers or viral code could change that, but that's not important here).

You can use the environment variables on your own, for example, the Java runtime uses the PATH variable in Windows to let the system know where to find the Java executables. You can invent your own variables simply by using "SET MYVARIABLE=My Value" in a command window. You can do the same with the Username variable - but it would not change the Environ result as it is only valid in the running command window. If you want to set that permanently you must only go into the Windows system settings, there you'll find a dialog to change or add environment variables, separated by system and user environment variables where the first kind of variables is used for any user.

But it's not a secure way as you see it can be changed by anyone. Instead of using environment variables it is better to use registry settings (can of course also be changed, but the chance is not so high that someone changes something here).

Cheers,

Christian
0
developingprogrammerAuthor Commented:
thanks Christian for your very comprehensive explanation!!

now i understand it so much better!!

yup i'm DEFINITELY going to change all my environ("username") code to the windows API code = ))

thanks Christian!! = ))
0
developingprogrammerAuthor Commented:
guys all code changed already! thanks so much for your help!! = ))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.