Link to home
Start Free TrialLog in
Avatar of leslieinva
leslieinvaFlag for United States of America

asked on

Is there a way for Access 2007 to know the machine name of a user who opens the database?

I can put a Microsoft Access 2007 database on a public drive to share with people.  I would like this database to save the name of the user or his PC when he adds or updates a record.  Is there any code I could use to grab the name of the user, his  PC, or any other identifying info that I could then save in a record?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

user name
ENVIRON("UserName")

Computer Name

ENVIRON("ComputerName")

mx
ComputerName returns the Device ID

User Name returns the Windows logged on User Name

mx
Avatar of leslieinva

ASKER

This looks very useful.  In the table designer, I tried to set a field's Default Value to
ENVIRON("UserName"), but it gave me an Unknow Function message.  How would I set the Default Value in the table desiner using this?  (I know I said I'd use code, but the table desingers Default Value is much easier to use.)

Thanks!
You need the equals sign

=ENVIRON("UserName")

it works ... I use it all the time.

mx
I copied what you wrote here, =ENVIRON("UserName") into the Default Vaule of a field I named User_name & I got this error: "Unknown function 'Environ' in validation expression or default value on 'Table1.User_Name."

Are you using Access 2007?
"
Are you using Access 2007?"

no.

Open the VBA editor.
Tools>>References.
Be sure a reference is set to Microsoft DAO.xx Object Library

mx
I get a weird error message when I try to add the reference: "Name conflicts wit exiting module, project, or object library."  It won't let me add the rerference.
humm.  Is that reference already there?

What happens if you do (menu) Debug>>Compile?

Also ... in the Immediate Window ... type

?ENVIRON("UserName")   and Enter  (including the question mark)

what happens?

mx
No, the reference isn't there yet & it won't let me add it BUT
?ENVIRON("UserName") worked in the immediate window!  Wonder why not as a default value.
I'm pretty sure this is a Reference issue.

What happens if you do (menu) Debug>>Compile?

mx
ASKER CERTIFIED SOLUTION
Avatar of leslieinva
leslieinva
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
It's the bogus Macro Security.

Open Access - any ACCDB or none.

In A2003 ... it's Tools>>Macro>>Security .... set to LOW.

Here are some links that may help you get around that:

http://office.microsoft.com/en-us/access/HA100319991033.aspx#3  'Trusted Locations
http://office.microsoft.com/en-us/access/HA102564121033.aspx  'Trusted DB
http://www.mac-net.com/1159484.page       'Not possible to determine ....

http://msdn2.microsoft.com/en-us/library/bb421308.aspx  'A2007 Macro Security

mx
btw ... it's the same issue in A2003 ... I totally forgot about that special case.

mx
Doesn't work in 2007.  I already have macro security set "Enable all macros"  None of the "trust" related stuff makes any difference.  It's the sandbox thing wiht 2007.
Well, since I don't have A2007 loaded, I can't experiment.  I've have run into the exact same issue in A2003 - until I set Macro (in)Security to Low.

mx
"I found the answer myself. "

And the answer is ?
Access 2007 has a new "feature" sandbox blocking.
http://office.microsoft.com/en-us/access/HA012301901033.aspx
I had to edit the registry in order to use Environ at all.
"Access 2007 has a new "feature" sandbox blocking. "

This 'feature' is not new.  It surfaced just prior to the release of A2003.

mx