Solved

access 2010 - getting user info using environ()

Posted on 2013-06-20
13
514 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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 - Access MVP) 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

808 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