Determing who added a record

D

Dave

Access 2003

I have in the past, included the following as the default value in a field
"AddedBy" to determine who has entered a new record:

=Environ("username")

This seems not to work on Access 2007 (or Vista - I forget which).

So what would be the proper way to "CODE" this as a module and use it more
readily and without version issues.


tia
Dave
 
A

Arvin Meyer [MVP]

Dave said:
Access 2003

I have in the past, included the following as the default value in a field
"AddedBy" to determine who has entered a new record:

=Environ("username")

This seems not to work on Access 2007 (or Vista - I forget which).

So what would be the proper way to "CODE" this as a module and use it more
readily and without version issues.

This code has been tested and works in both Vista and Access 2007

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

Save the code and api in a module with a name other than the function's
name. You can then use the name of the function as a query criteria, or in
the AddedBy field like:

=fOSUserName()
 
A

aaron_kempf

wow that is funny.

Do you even realize that this is built into SQL Server?

select suser_sname() as thisUser

that's all you got to do to get to this info in SQL Server.
Wouldn't it be nice if things 'just worked' out of the box??

-Aaron
 
D

Dave

Arvin,

Thanks for the link.
I am however having some trouble using it.

I crerated a Module called "UserName"

I pasted in the code exactly as it was in the link.

I then tried both of these as default value:

=fOSUserName()

=UserName()

Both gave me errors.

Should this be public and not private?
Or am I missing/not doing something else wrong?

Dave
 
D

Dave

Aaron,

I am not sure if you are making fun of my ignorance here or I am too dumb to
use the information you provided but I don't understand how this helps me.

Thanks for the reply,

dave

wow that is funny.

Do you even realize that this is built into SQL Server?

select suser_sname() as thisUser

that's all you got to do to get to this info in SQL Server.
Wouldn't it be nice if things 'just worked' out of the box??

-Aaron
 
A

Arvin Meyer [MVP]

Dave said:
Arvin,

Thanks for the link.
I am however having some trouble using it.

I crerated a Module called "UserName"

I pasted in the code exactly as it was in the link.

I then tried both of these as default value:

=fOSUserName()

=UserName()

Both gave me errors.

Should this be public and not private?
Or am I missing/not doing something else wrong?

Not sure what the problem is. Have you copied the api code? Have you
compiled the code? Does it compile? If not, what is the error message? If it
does compile try running something like this in a query;

SELECT FirstName, LastName, fOSUserName() AS Expr1
FROM MyTable;

Of course you'll need to put your own field and table names in.

One other thing that occured to me, you cannot use non-built-in functions in
a table because the expression service doesn't run in tables. But it should
work in a query, form, or report.
 
A

Arvin Meyer [MVP]

Dave said:
Aaron,

I am not sure if you are making fun of my ignorance here or I am too dumb
to use the information you provided but I don't understand how this helps
me.

Thanks for the reply,

Dave,

His information is not designed to help you. Aaron is what is known in the
newsgroups as a troll. He wanders around looking for arguments. He thinks
he's smarter than everyone, but contantly proves otherwise. I have him
blocked so the only time I see his inane remarks is when he's quoted in
someone else's reply.

Aaron threatened one of the Microsoft MVPs (Tom Wickerath) and this was the
result:

On Saturday, June 30, 2007, Aaron was taken down by the Tacoma Police Dept.
SWAT Team after earlier making public threats to Tom's safety in the
newsgroups.
He ended up pleading guilty to the crime of cyberstalking, which the
Prosecutor later decided to pursue as a misdemeanor instead of a felony. On
Dec. 7, 2007, the judge handed down the following sentence:


1.) Pay $500 court costs
2.) 24 months probation
3.) He must use his name in any electronic postings
--no aliases allowed.
4.) Complete an anger management session.
5.) Perform 136 hours of community service.

It looks to me as if the anger management session hasn't been started yet.
 
D

Dave

"Have you copied the api code? Have you
compiled the code? Does it compile? "

Well I am totally missing something.
I copied the code that was one the link you posted into a new module.
I am not sure what the api code is but I am sure I have compiled nothing.
sounds like this is going to be above my head for what I was hoping was
simple :(

Thanks for the tip about aaron

dave
 
P

Pete D.

I have used this for years in the form before update. I also display it on
the form, tends to make users more aware of attention to details. Also when
I had to go to a hearing I had to place individual at the machine, not just
someone used thier logon so with witness that they were at that machine case
closed. fOSMachineName is also on same web site. Much thanks to Dev Ashish
for fOSUserName and fOSMachineName.

'------------------------------------------------------------
' M_LastModified
'
'------------------------------------------------------------
Function fLastModified()
On Error GoTo fLastModified_Err
With CodeContextObject
.DateModified = Date
.TimeModified = Time()
.UserLogon = fOSUserName()
.MachineName = fOSMachineName()
End With
fLastModified_Exit:
Exit Function
fLastModified_Err:
MsgBox Error$
Resume fLastModified_Exit
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top