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
Microsoft Access

Avatar of undefined
Last Comment
developingprogrammer

8/22/2022 - Mon
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

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
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

ASKER
developingprogrammer

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!! = ))
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
developingprogrammer

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
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
developingprogrammer

cool! that makes perfect sense = )

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

thanks mx! = )
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

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' ... :-)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
developingprogrammer

GULP - not the PRO way of doing it.

GOTTA CHANGE IT NOW!!

developingPROprogrammer in action!! haha = ))

thanks so much mx once again as always!! = ))
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

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
ASKER
developingprogrammer

Whao!! YES SIR!!

Haha okie dokes! Have a good rest and sweet dreams!! = ))
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Bitsqueezer

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
ASKER
developingprogrammer

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!! = ))
ASKER
developingprogrammer

guys all code changed already! thanks so much for your help!! = ))
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.