Link to home
Start Free TrialLog in
Avatar of developingprogrammer
developingprogrammer

asked on

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
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

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
Avatar of developingprogrammer
developingprogrammer

ASKER

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!! = ))
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!! = ))
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cool! that makes perfect sense = )

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

thanks mx! = )
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' ... :-)
GULP - not the PRO way of doing it.

GOTTA CHANGE IT NOW!!

developingPROprogrammer in action!! haha = ))

thanks so much mx once again as always!! = ))
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
Whao!! YES SIR!!

Haha okie dokes! Have a good rest and sweet dreams!! = ))
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
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!! = ))
guys all code changed already! thanks so much for your help!! = ))