windows user id

D

David Widener

I ment to say How do I Access a windows user id from a VBA event in Access
2000 ?
 
D

David Widener

This gives me Database username I need Windows Logon Name any help is
appriciated.
 
G

Guest

which event?
what do you mean windows user id?
-----Original Message-----
I ment to say How do I Access a windows user id from a VBA event in Access
2000 ?

in Access 2000 ?
.
 
D

David Widener

I am trying to capture the The windows Ligin UserID or Network ID witch is
the same thing in the After Update event in order to log Updates, I have
tryed UserID = CurrentUser() but I get Admin not the windows UserName.
Thank You
 
B

Bunky

I went to that link, copied the code to a module and tried to call the module
I created. I know I am extremely green in VB code and am trying to learn
from a book. I put the call in a form textbox in the event procedure for
MouseMove then I moved the call to AfterUpdate. It does not return the name
to the textbox. I am not certain how to check to see what is happening. I
step through the new module and can see the value I want in StrUserName.
Here is the code for the call I used.

Private Sub Text0_AfterUpdate()
Call fOSUserName
Text0 = strUserName
End Sub

Text0 is the name of the textbox. Ideas?
 
G

George Nicholson

I step through the new module and can see the value I want in StrUserName.

Really? In strUserName? I don't see how.You are calling the function
fOSUserName but you aren't assigning its returned value to anything. You
sure you don't mean that you see the value in fOSUserName before it exits?

strUserName = fOSUserName
Text0 = strUserName

or just

Text0 = fOSUserName

....not sure if Text0_AfterUpdate is the best place to change the value of
Text0, but that's a separate issue....

HTH,
 
B

Bunky

You are an absolute mind-reader; yes, that is exactly what I meant. I put
the line in 'Text0 = fOSUserName' and I can see the value I want in Text0.
However, it still does not show on the form. I did not change the call at
all. Ideas?
 
P

Pieter Wijnen

And Text0 IS a Control on your Form?
One reason to always write the whole syntax & have Option explicit turned on
in all modules

ie

Me.Text0.Value = fOSUserName()

HTH

Pieter
 
B

Bunky

I have a test form that is called 'Form1'. On this form I have a textbox
called 'text0'. What I want to happen is show the ID of the person who is
signed onto the computer when 'some event' occurs. I was trying initially to
have it show on MouseMove then changed it to AfterUpdate. Neither has
worked.

On the form in the event procedure for 'on enter' I have the following code.

Private Sub Text0_Enter()
Call fOSUserName

Text0 = strUserName

End Sub

In the module named 'apiGetUserNameA', I cut and pasted the following code

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If ( lngX > 0 ) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************
Where am I going wrong? Please be detailed as possible as I am trying to
learn VB code on the fly from a book.

Thanks
 
P

Pieter Wijnen

Your code has no link between the Function & the TextBox
Call fOSUserName ' Execute the Function, discard return value
Text0 = strUserName ' Set Text0's default property (value), to the (empty?)
string variable strUserName's value

Try

Private Sub Form_Current()
Me.Text0.Value = fOSUserName()
End Sub

Pieter
 
W

WildlyHarry

I have tried everything you guys have posted to the letter but when I enter
the code

Private Sub Form_Current()

Me.DAE.Value = fOSUserName()

End Sub

Where DAE is my text box. I get an error that states "Expected variable or
procedure, not module" Any ideas?
 
P

Pieter Wijnen

You can't have the module have the same name as the function, rename to
basUtilities or whatever

Pieter
 
E

Erin Freeman

I have done this,
However i have a silly question.

I have a form that is a checklist that is based on a project ID. I have a
"Get User" button beside about 100 checklist items so people dont have to
type in their name in the fields on a form. however, i have the code populate
an unbound textbox with thier name,
So on the main project form ,i have a button that goes to the checklist
based on teh project ID. I fill out the fields, click the Get Username and it
populates my name and the date. However when i open that particular checklist
up again my name and date is not there.... I know it is because it is unbound
right? please help. I dont think that having 100 "Employee Name" fields is
the way to go so I would love some insight of an easy way to do this. Thank
you for taking the time to respond.
 

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