Nero83
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!!
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!!
ASKER
Thanks.
Yes and yes.
Yes and yes.
and 3)
Open VBA Editor >> Tools>>References.
Are any shown as
**MISSING <SomeReferenceName>
?
If so, resolve this.
mx
Open VBA Editor >> Tools>>References.
Are any shown as
**MISSING <SomeReferenceName>
?
If so, resolve this.
mx
ASKER
It's clean.
What is the exact error ?
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![YourUserCreatedNameFie ld] =Environ ("UserName")
Else
Me![YourUserLastUpdatedNam eField] =Environ ("UserName")
End If
End Sub
Of course, use your actual Field Names in the underlying table or query driving the form.
mx
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![YourUserCreatedNameFie
Else
Me![YourUserLastUpdatedNam
End If
End Sub
Of course, use your actual Field Names in the underlying table or query driving the form.
mx
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.
ASKER
OK, thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! I've heard there are problems with Environ, so I like this function, too.
2) Is Macro Security set to Low?