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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

environ("username") won't work

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
I just received a new pc and when using environ("username") as a default value for a textbox, it no longer works. the value displayed is #Name?

when I use environ in code, it works fine.

this code works fine on other machines.

Anybody have any sugestion for this?
 
A security issue (SandBox I guess)
Create the following function in a standard code module:
Code:
Public Function getWinUser() As String
getWinUser = Environ("UserName")
End Function

and now, use getWinUser()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you, but that didn't work either. Seems as though there must be a setting in Access??
 
Works for me (ac2003, Jet SP8) for the DefaultValue property of a form's TextBox.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You can try this way. Depending on whether you are using AD or NT authentication.
''-- set a Reference to "Active DS Type Library" - activeds.tlb
Dim ad As New ActiveDs.ADSystemInfo
Dim NT As New ActiveDs.WinNTSystemInfo
Debug.Print "ad computer = "; ad.ComputerName
Debug.Print "ad user = "; ad.UserName
Debug.Print "ad site = "; ad.SiteName
Debug.Print "NT name = "; NT.ComputerName
Debug.Print "NT user = "; NT.UserName
Debug.Print "NT domain = "; NT.DomainName
 
Use the API call from the Access Web
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 **************************

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
ItIsHardToProgram,
Are you suggesting that I shouldn't have posted the code here? I can ask Dev if we need a clarification.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top