Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 15th, 2004, 02:28 PM
BetsyBean BetsyBean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 BetsyBean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 15 sec
Reputation Power: 0
Red face How To Get The UserName

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

Reply With Quote
  #2  
Old November 16th, 2004, 08:14 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
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

Reply With Quote
  #3  
Old November 16th, 2004, 04:24 PM
BetsyBean BetsyBean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 BetsyBean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 15 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old November 16th, 2004, 05:13 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Hi BetsyBean,

You are welcome.

No leave the post for others to read. It might solve their problem when searching for a solution.

lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > How To Get The UserName


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT