X
xbound
I have the following code to get the network login name:
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
This code is available widely from the internet and I've been using it in a
couple of my Access projects with no problem. Then lately I created a new
Access project and import the form containing that piece of code straight
from one of the old projects. However; as soon as that function is
entered, I would get an error : "Compile error. Type declaration does not
match declared data type." such that I couldn't examine the values of
variables there. It seems the statement "fOSUserName = Left$(strUserName,
lngLen - 1)" is causing trouble. If I comment out that statement, I don't
get any error but of course I won't get the network login name either. As
a precaution I stepped through the function in the old project and found
that everything is working as expected.
The old adp projects were created in Access 2003 on a XP workstation. The
new project was created in Access 2007 on a Win 7 workstation. Since the
old projects are functioning perfectly on the Win 7 machine, I gather that
the Access version and the OS platform are not the issues. This only
makes the problem more baffling to me. Maybe someone could spot or have
an idea what I've missed?
thanks.
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
This code is available widely from the internet and I've been using it in a
couple of my Access projects with no problem. Then lately I created a new
Access project and import the form containing that piece of code straight
from one of the old projects. However; as soon as that function is
entered, I would get an error : "Compile error. Type declaration does not
match declared data type." such that I couldn't examine the values of
variables there. It seems the statement "fOSUserName = Left$(strUserName,
lngLen - 1)" is causing trouble. If I comment out that statement, I don't
get any error but of course I won't get the network login name either. As
a precaution I stepped through the function in the old project and found
that everything is working as expected.
The old adp projects were created in Access 2003 on a XP workstation. The
new project was created in Access 2007 on a Win 7 workstation. Since the
old projects are functioning perfectly on the Win 7 machine, I gather that
the Access version and the OS platform are not the issues. This only
makes the problem more baffling to me. Maybe someone could spot or have
an idea what I've missed?
thanks.