|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am attempting to try to write some code based on who is logged on to the current session of the database. How do I get the username into a variable so that I can work with it? Thank you
I read a post submitted by Woods and responded to by lwells. Followed link to following 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********************** Now I cannot get any response when I attempt to use it. I am attempting to call the function from a form load event. MsgBox comes up with null for name. What am I doing wrong? '****** Code Begin***** Private Sub Form_Load() Call fOSUserName MsgBox "User Is " & fOSUserNamEnd Sub '****** Code End******* Last edited by BetsyBean : November 15th, 2004 at 03:32 PM. Reason: Attempted to try some code and still having problems |
|
#2
|
|||
|
|||
|
Hi BetsyBean
Take this part of the code Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Place it at the top of the code window directly below the Option Explicit in the declarations area of your code In your post it was commented out so make sure you remove the comment Thats the ' character in front of the code. Also Remove the Call function before your message box. lwells |
|
#3
|
|||
|
|||
|
Thank you very much, lwells. It works just fine now. To any regular user: This is my first post ever. Am I responsible for deleting this post? Thanks
|
|
#4
|
|||
|
|||
|
Hi BetsyBean,
You are welcome. No leave the post for others to read. It might solve their problem when searching for a solution. lwells |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > How To Get The UserName |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|