Experts:
I am using a module (see below) to "get the username". This module/function works fine when I'm on my work computer (on a network).
However, if I work from home (off network), I have to comment out the two lines starting with "Private Declare Function" and "lngX = apiGetUserName" (as shown below).
I use Office365 on my home computer and Office2010 on my work computer. How should the module be modified so that I don't constantly have to comment/un-comment the two lines?
Thank you,
EEH
Code:
Option Compare Database
'Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long '*** Errors on home computer; works fine when on company network
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) '*** Errors on home computer; works fine when on company network
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function