[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

access 2010 - getting user info using environ()

Posted on 2013-06-20
13
Medium Priority
?
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

656 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