Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get user's windows ID 2

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
I need to get the user's windows ID:

This works in classic asp:
userName = request.ServerVariables("AUTH_USER")
userName = Mid(userName, 5)

In VBA we do not have a request object. So how do I get the user's ID?
 
You may try Environ("USERNAME")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Or, Application.CurrentUser, but I think you may prefer PHV's suggestion.
 
Beware!

Application.CurrentUser does NOT return the same as Environ("Username")

Application.CurrentUser returns the database username of the current user, i.e. in an unsecured db will return the default value of Admin

As PHV indicates, Environ("USERNAME") returns the operating system user account name, so it's this you should check out.
 
so the fact I use the following , is that overkill?
Code:
'used for machine name
Declare Function WNetGetUserA Lib "mpr" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
=================================================
Function GetUserID() As String

Dim sUserNameBuff As String * 255

sUserNameBuff = Space(255)

Call WNetGetUserA(vbNullString, sUserNameBuff, 255&)
GetUserID = Left$(sUserNameBuff, InStr(sUserNameBuff, vbNullChar) - 1)

End Function
=============================================
Function GetWSID() As String

Dim sBuffer As String * 255
Dim X As Long

If GetComputerNameA(sBuffer, 255&) > 0 Then
    GetWSID = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
Else
    GetWSID = "?"
End If

=================================
Sub displayUser()

MsgBox GetUserID & ", " & GetWSID

End Sub

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF, your functions are mandatory for 9x (win95, win98, winME).
 
ahhh, that be why my trainer taught me that way, thanks PHV

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi,
I am trying to do the same as above and can get the field to update on the current form.

This works a treat:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then Me.LastUpdate = Now()
ConChangeBy = Environ("USERNAME")

I cant get it to work when trying to update the field when something changes in a subform.

My Code for this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then [tblContractDetails]![LastUpdate] = Now()
[tblContractDetails]![ConChangeBy] = Environ("USERNAME")

I think i am missing some formatting in the code?
Any help would be much appreciated

Thanks in advance
Dazz
 
I will help you if you are still experiencing the problem. Here are my initial thoughts:

1) The problem is not directly related to getting the username. It is TRANSFERING the value from the subform to the main form.

2) Why move the value to the main form? You could store it in a table easily. Then if you wanted to display it, you could bind something in the main form to the new table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top