User name stamp

M

Mohd

In previous versions of MS Access I was able to use the Environ (UserName)
function in the default value field of a text box to have it display the
users login name from Windows. I have put a database that I previously made
(Access 2003/WinXP Pro) onto a machine running WinXP Access 2007. I
get an error regarding the Environ function in the text box, and the username
will not display. I had to remove the function in order to use the the
tables db,
since the error would continually pop up if I moved to a new field on the
form. Does this function still exist in Access 2007 and/or is there anything
to be done to be able to getback the same fuction ??? I did copy
http://www.mvps.org/access/api/api00.08.htm but it didn't work with me ?? I
don't know why ? Can anybody explain this to my by baby steps hence I am not
a programmer .
thanks
 
D

Douglas J. Steele

As far as I know, the Environ function still works in Access 2007, but using
it to retrieve the user name has never been a good idea. It's trivial to
reset the value of the Username environment variable for the duration of the
Access session, so that it cannot be trusted. You really should be using the
code from http://www.mvps.org/access/api/api0008.htm

Copy everything that's in the shaded area (between Code Start and Code End)
and paste it into a new module (not a class module, nor a module associated
with a form or report). When you save the module, make sure you give it a
unique name: modules cannot be named the same as functions or subs contained
within them. A call to fOSUserName() will now give you the network id of the
current user.
 
V

Vincent Isoz

Hi,

I'm an Access developper and i'm not able to make the function
Environ(UserName) work in Access 2007. My customer don't want to use VBA
modules or classes in it's database.

Any idea on how to solve the problem?
 
D

Douglas J. Steele

It should be Environ("UserName"), but why does your client not want it done
properly?

It is trivial to reset the UserName environment variable for the duration of
an Access session. Simply open a Command prompt, type

Set UserName = XXX

and hit enter. Then, in the same Command prompt, start the application from
the command line:

"C:\Program Files\...\msaccess.exe" "C:\Folder\File.mdb"

Any reference to Environ("UserName") during that session of the application
will retrieve XXX.

There's no point using functionality if it's going to return a wrong value!
 
V

Vincent Isoz

Thanks but I already know these issues about Environ( ) well and if I always
have to asks my customers when their are giving me stupid constraints I will
be asking questions during my whole life....

Reading you answer I simple see that you have no workarounds to solve this
problem without VBA.
 
D

Douglas J. Steele

My response was also intended to show that you didn't have quotes around
UserName in your call to Environ function.
 

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