Link to home
Start Free TrialLog in
Avatar of Nero83
Nero83Flag for United States of America

asked on

access 2010 - getting user info using environ()

I'm beginning work on a new database using Access 2010.  An idea I had was to record the user's information when a new record was created, or perhaps when it is changed.  Anyway, I was considering using Environ("USERNAME") and I've done a bit of research but can't figure out how to implement it so that it populates a field I have reserved for this in my table/form.

I think part of my problem is that I don't know VB.  

Could someone assist me with some advice built for a newb?  I've seen some code snippets on this, but I don't know where this code needs to go or the best way to trigger it to populate the record...

Thanks Experts!!
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

1). Is your database in a Trusted  Location.

2) Is Macro Security set to Low?
Avatar of Nero83

ASKER

Thanks.

Yes and yes.
and 3)
Open VBA Editor >> Tools>>References.
Are any shown as

**MISSING <SomeReferenceName>

?

If so, resolve this.

mx
Avatar of Nero83

ASKER

It's clean.
Avatar of Nero83

ASKER

No error, I don't know how to set it up in the first place...sorry if I was unclear.  I've never used it before.  My issue is that there are many people who will be using it and my company has a lax security policy, and I was looking for a solution to record who does what besides people self-reporting their name on the record.
oops ... sorry, I completely misunderstood the Q - thought you were having the typical issue with Environ().

OK ... this is the basic idea in VBA Code
You use the Form's BeforeUpdate event, which would end up looking like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord = True
    Me![YourUserCreatedNameField] =Environ ("UserName")
Else
   Me![YourUserLastUpdatedNameField] =Environ ("UserName")
End If

End Sub

Of course, use your actual Field Names in the underlying table or query driving the form.

mx
Avatar of Nero83

ASKER

Thanks much.  You always help me out with my Access issues.  I'll give it a try and Accept as Solution afterward...looks simple enough even for me.
OOPS ... left of a 'Then'

If Me.NewRecord = True Then

User generated image
Avatar of Nero83

ASKER

OK, thanks.
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
Avatar of Nero83

ASKER

Perfect!  I've heard there are problems with Environ, so I like this function, too.