Problem with Environ("Username")

Rainbowhawk

Registered User.
Local time
Today, 11:09
Joined
Oct 8, 2007
Messages
54
Hi All

I have an update query that uses the Environ("Username") command to populate a field, however I am encountering the following Issue

This database in Access 2000 however the operating system various from computer to computer.

The query works on Windows XP systems, but does not work on Windows 2000 systems.

However just to complicate things, I have the same command on another database, this one in Access 97 running on Windows 2000 and it has no problems.

Any advice?
 
You could try this code that I use in my applications

Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
'-----------------------------------------------------------------------------------------
Code:
 The basis for this code is used to retrieve the network user name by accessing the API apiGetUserName.
' Created by: Unknown (Found on Dev Ashish web site http://home.att.net/~dashish/api)

' Added to database: 27 dec 1999
' Added by: Richard Rensel
'-----------------------------------------------------------------------------------------
Function fOSUserName() As String
On Error GoTo fOSUserName_Err


Dim struser As String
Dim intStringCount As Integer
Dim strTempName As String

intStringCount = 0
strTempName = ""


Set objSysInfo = CreateObject("ADSystemInfo")
struser = objSysInfo.UserName

intStringCount = Len(struser)

For intstr = 4 To intStringCount
    If Mid(struser, intstr, 1) = "," Then
        struser = strTempName
        insstr = intStringCount
    End If
    strTempName = strTempName & Mid(struser, intstr, 1)
Next intstr

fOSUserName = struser

fOSUserName_Exit:
Exit Function

fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function
 

Users who are viewing this thread

Back
Top Bottom