A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

get network login name



 
 
Thread Tools Display Modes
  #11  
Old March 9th, 2010, 10:12 PM posted to microsoft.public.access
J_Goddard via AccessMonster.com
external usenet poster
 
Posts: 221
Default get network login name

Hi -

You could also try the MS Access function Environ, which returns the current
value of a specified Environment variable. Since you are on a network, there
is almost certainly going to be an environment variable with the current user
login name. For example, on my network,

environ("username") returns my login name.

Might work for you, if all your users are in the same environment.

John



xbound wrote:
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.


--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201003/1

  #12  
Old March 9th, 2010, 11:11 PM posted to microsoft.public.access
xbound
external usenet poster
 
Posts: 5
Default get network login name

Yes it is. Even if it is not, I don't think one would get "Compile Error"

Right now, the Compile Error pops up at the moment when Stepping Into the
line "Function fOSUserName() As String"; while at the same time the
debugger would highlight "LEFT$" several lines down. Then can't go on
anymore.



"Gina Whipp" wrote in message
...
xbound,

Is your database in a Trusted Location?

http://www.regina-whipp.com/index_fi...edLocation.htm

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"xbound" wrote in message
...
I run the thing today and it's NOT working again. Really frustrating....

"Gina Whipp" wrote in message
...
Glad to hear all is well!

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"xbound" wrote in message
...
I've posted back last week but for some reason it's not showing up.

Thanks for all the responses. After applying SP2, the compile error
went
away. Things like this is really hard to troubleshoot ......


"Gina Whipp" wrote in message
...
Mark,

Hopefully, the OP will post back. I found I had to run my Access 2003
in
compatiblity mode, aslo 64 bit but my Access 2007 is fine as long as in
a
Trusted Location. But all we can do is wait and see...
--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"Mark Andrews" wrote in message
...
Mine is 64bit. Not in compatibility mode. However I'm not the one with
the
issue.
Mark

"Gina Whipp" wrote in message
...
Was that Windows 7 64 bit or 32 bit? And are either of you running in
Compatibly Mode?

"Mark Andrews" wrote in message
...
I just copied your code into a new database in Access 2007 sp2 on my
Windows
7 laptop and it worked fine.

HTH,
Mark

"xbound" wrote in message
...
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.




  #13  
Old March 9th, 2010, 11:35 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default get network login name

On Tue, 9 Mar 2010 15:11:58 -0800, "xbound" wrote:

Yes it is. Even if it is not, I don't think one would get "Compile Error"

Right now, the Compile Error pops up at the moment when Stepping Into the
line "Function fOSUserName() As String"; while at the same time the
debugger would highlight "LEFT$" several lines down. Then can't go on
anymore.


This appears to be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.
--

John W. Vinson [MVP]
  #14  
Old March 9th, 2010, 11:40 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default get network login name

Its generally recommended that environmental variables not be used for this.
I use:

''''module basGetUser''''
''''module starts''''
Option Compare Database
Option Explicit

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
lpBuffer As String, nSize As Long) As Long


Public Function GetUser() As String

Dim strBuffer As String
Dim lngSize As Long, lngRetVal As Long

lngSize = 199
strBuffer = String$(200, 0)

lngRetVal = GetUserName(strBuffer, lngSize)

GetUser = Left$(strBuffer, lngSize - 1)

End Function
''''module ends''''

Ken Sheridan
Stafford, England

J_Goddard wrote:
Hi -

You could also try the MS Access function Environ, which returns the current
value of a specified Environment variable. Since you are on a network, there
is almost certainly going to be an environment variable with the current user
login name. For example, on my network,

environ("username") returns my login name.

Might work for you, if all your users are in the same environment.

John

I have the following code to get the network login name:

[quoted text clipped - 35 lines]

thanks.



--
Message posted via http://www.accessmonster.com

  #15  
Old March 10th, 2010, 03:32 AM posted to microsoft.public.access
Gina Whipp
external usenet poster
 
Posts: 3,500
Default get network login name

Silly me.. John is correct it is a Reference issue...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"xbound" wrote in message
...
Yes it is. Even if it is not, I don't think one would get "Compile Error"

Right now, the Compile Error pops up at the moment when Stepping Into the
line "Function fOSUserName() As String"; while at the same time the
debugger would highlight "LEFT$" several lines down. Then can't go on
anymore.



"Gina Whipp" wrote in message
...
xbound,

Is your database in a Trusted Location?

http://www.regina-whipp.com/index_fi...edLocation.htm

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"xbound" wrote in message
...
I run the thing today and it's NOT working again. Really frustrating....

"Gina Whipp" wrote in message
...
Glad to hear all is well!

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"xbound" wrote in message
...
I've posted back last week but for some reason it's not showing up.

Thanks for all the responses. After applying SP2, the compile error
went
away. Things like this is really hard to troubleshoot ......


"Gina Whipp" wrote in message
...
Mark,

Hopefully, the OP will post back. I found I had to run my Access 2003
in
compatiblity mode, aslo 64 bit but my Access 2007 is fine as long as in
a
Trusted Location. But all we can do is wait and see...
--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"Mark Andrews" wrote in message
...
Mine is 64bit. Not in compatibility mode. However I'm not the one with
the
issue.
Mark

"Gina Whipp" wrote in message
...
Was that Windows 7 64 bit or 32 bit? And are either of you running in
Compatibly Mode?

"Mark Andrews" wrote in message
...
I just copied your code into a new database in Access 2007 sp2 on my
Windows
7 laptop and it worked fine.

HTH,
Mark

"xbound" wrote in message
...
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.




  #16  
Old March 13th, 2010, 05:43 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default get network login name


"xbound" wrote in message
...
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.


  #17  
Old March 17th, 2010, 01:39 PM posted to microsoft.public.access
joelgeraldine
external usenet poster
 
Posts: 201
Default get network login name

rh********v v

"xbound" a écrit dans le message de groupe de
discussion : ...
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.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.