Network user name

S

slickdock

How can I default a field in Access to equal the name the user is
logged in to the Windows server network as?
 
S

slickdock

And make sure to name the module something OTHER than the function name
(fOSUsername).
--
Bob Larson

Free Tutorials and Samples athttp://www.btabdevelopment.com

__________________________________





- Show quoted text -

Beautiful! Thank you everyone! It works perfectly for the
[RecordCreatedBy] field.
How can I make it work for the [RecordRevisedBy] field? I assume I
have to assign a macro to the Before Update property of the form that
Runs Code =fOSUsername() and places that value in the
[RecordRevisedBy] field, but my lame attempts have failed due to my
limited VBA experience.
 
B

boblarson

It would just be:

Me!RecordRevisedBy = fOSUsername()
--
Bob Larson

Free Tutorials and Samples at http://www.btabdevelopment.com

__________________________________


And make sure to name the module something OTHER than the function name
(fOSUsername).
--
Bob Larson

Free Tutorials and Samples athttp://www.btabdevelopment.com

__________________________________





- Show quoted text -

Beautiful! Thank you everyone! It works perfectly for the
[RecordCreatedBy] field.
How can I make it work for the [RecordRevisedBy] field? I assume I
have to assign a macro to the Before Update property of the form that
Runs Code =fOSUsername() and places that value in the
[RecordRevisedBy] field, but my lame attempts have failed due to my
limited VBA experience.
 
S

st8employee

I followed you guys' instructions:

I created a module,
pasted the code in a new module,
named the new module "GET USERNAME",
created anew form,
inserted an unbound text box,
and set the default value property to "=fOSUserName()"

....but all I get is "#Name?" in the text box. SO there's something I am not
doing correctly...

I am not a programmer...Please advise me. THANX.

-St8employee
 
A

Arvin Meyer [MVP]

So I followed your instructions exactly and it worked as expected. I can see
a possible mistake that you may have made:

You didn't copy all of the code, specifically the declare:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
S

st8employee

I copied everything from where it says ***code start*** to where it says
***code end*** ...asteriks and all...

what am I doing wrong...? (I am really a novice with programming...have
literally NO experience outside of writing complex command strings in Access
query criteria and building snazzy macros...)
 
S

st8employee

I started over, following each step just as before, named the module
"basutilities", and set the default value of the unbound text box on my new
form to "? fOSUserName()"...I got an error, "the expression you entered
contains invalid syntax"...

I know there has got to be something very simple that I am missing...I just
have no clue what it is...
 
D

Douglas J. Steele

Arvin didn't say to set the default value of the text box to ?fOSUserName.

He said to go to the Immediate Window (which you can get to using Ctrl-G),
type ?fOSUserName in the bottom half of that window, then hit Enter. What
happens when you do that? Do you get your user id, or do you get an error?
If you get an error, what's the exact error message?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
S

st8employee

OH! I guess I didn't know what the Immediate window was...YAY! That gave me
my username! Thanks, guys so much...

So, now how do I get this to show up on my form so it can be logged in a
table? I need to log what user was edititng the open record...
 
D

Douglas J. Steele

Okay, now that you know the function works, set the DefaultValue property of
the text box on the form to =fOSUserName(), complete with equal sign and
parentheses.
 
S

st8employee

Still returns "#Name?" in the form view...Is there something else I'm missing
here?
 
S

st8employee

Yes it is compiled...

OMG I fig'd it out! I created a new field in a new table and labeled the
field "loguser"
I set that table as the data sorce for the form, set "loguser" as the record
source for the textbox. It displays my name! It wasn't displaying because the
text box was unbound, I guess...

THANK YOU ALL SOOOOOO MUCH...I can't tell you how important this simple
little function is going to be for our security audits!

-St8employee
 

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