How to use "=username()"

D

Didi

I need to include in my report every user name on their computer when print a
report. The way I always use is to put =username() in a textbox. But somehow
it doesn't work anymore, everytime I do it I get a "#Name" on the report. Can
someone help me with this question? Thank you very much in advance.
 
D

Douglas J. Steele

Do you have a function named username() in your application? There is no
such function built into Access, so you must have your own. If you do, does
it work in the Immediate Windows (Ctrl-G)?
 
J

Jeff C

If the computers are networked The "environ$" variable works with this.

=environ$(username)

Depending on the environment variables set up. From Dos Prompt type "set"
to view variables offered.

In your table for example, when a record is created if the default value for
one of the fields is "=environ$(username) then the person logged into the
network creating the record is automaticall entered.
 
O

OfficeDev18 via AccessMonster.com

Or, to be more exact,

=environ$("username")

with the arguement 'username' in double-quotes.

Sam

Jeff said:
If the computers are networked The "environ$" variable works with this.

=environ$(username)

Depending on the environment variables set up. From Dos Prompt type "set"
to view variables offered.

In your table for example, when a record is created if the default value for
one of the fields is "=environ$(username) then the person logged into the
network creating the record is automaticall entered.
Do you have a function named username() in your application? There is no
such function built into Access, so you must have your own. If you do, does
[quoted text clipped - 7 lines]
 
A

Ann Scharpf via AccessMonster.com

I thought this looked like something I could use in my database. I tried to
copy and paste the statement into the default value of a UserID field I added
to my table. When I try to save the table, I get the error:

Unknown function 'Environ$' in validation expression or default value on 'tbl.
UserID'.


Can you tell from this information whether I am not following the
instructions properly? Thanks.

Ann Scharpf
 
S

strive4peace

Hi Sam and Ann,

try

=environ("username")

(without the $)

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
D

Douglas J. Steele

I don't think that's the problem, Crystal.

Environ$ is a valid function. If it's not working, odds are there's a
problem with the References collection (and so Environ won't work either).

On the machine(s) where it's not working, open any code module. Select Tools
| References from the menu bar. Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)

Having said that, though, I always cringe when people suggest using an
environment variable to retrieve the User Id, given how easy it is to reset
an environment variable.

Far safer, in my opinion, is to use the GetUserName API call. See
http://www.mvps.org/access/api/api0008.htm at "The Access Web" for a
complete sample.
 
S

strive4peace

Thanks for the link, Doug, much better way.

Actually, $ was a problem for me... didn't evaluate in the Debug window
until I removed it... Environ worked but Environ$ didn't...

Sam and Ann,

To understand better what Doug is saying about references, here is a
little video you can watch:

http://alexdyb.blogspot.com/2006/05/how-to-deal-with-missing-references.html

It was put together by Alex Dybenko (and also has a link to Doug's page
with Access Reference Problems)

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top