Solved

access 2010 - getting user info using environ()

Posted on 2013-06-20
13
516 Views
Last Modified: 2013-06-28
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!!
0
Comment
Question by:Nero83
  • 7
  • 6
13 Comments
 
LVL 75
ID: 39263951
1). Is your database in a Trusted  Location.

2) Is Macro Security set to Low?
0
 
LVL 75
ID: 39263973
1
2
0
 

Author Comment

by:Nero83
ID: 39263977
Thanks.

Yes and yes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 39263982
and 3)
Open VBA Editor >> Tools>>References.
Are any shown as

**MISSING <SomeReferenceName>

?

If so, resolve this.

mx
0
 

Author Comment

by:Nero83
ID: 39264019
It's clean.
0
 
LVL 75
ID: 39264037
What is the exact error ?
0
 

Author Comment

by:Nero83
ID: 39264054
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.
0
 
LVL 75
ID: 39264073
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
0
 

Author Comment

by:Nero83
ID: 39264087
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.
0
 
LVL 75
ID: 39264109
OOPS ... left of a 'Then'

If Me.NewRecord = True Then

1
0
 

Author Comment

by:Nero83
ID: 39264130
OK, thanks.
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 39264132
Sorry about all the confusion at first.  Whenever I see Environ() ... I immediately assume an issue.

FYI ... this is the better and safer approach to getting the User namne

http://access.mvps.org/access/api/api0008.htm

Put that code in a standard VBA Module, then call  fOSUsrName() instead of Environ()If Me.NewRecord = True Then
    Me![YourUserCreatedNameField] =  fOSUsrName()
Else
   Me![YourUserLastUpdatedNameField] =  fOSUsrName()
End If

End Sub
0
 

Author Closing Comment

by:Nero83
ID: 39285962
Perfect!  I've heard there are problems with Environ, so I like this function, too.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Saving data on a subform when I close the form 12 33
Access Query: Text to Date 10 34
ASP Classic Query that needs to display more information 18 37
Append Query Access 2010 4 28
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question