|
-
Jun 4th, 2005, 12:28 AM
#1
Thread Starter
Addicted Member
Cant get username
Hi, am trying to fill a text box with the current windows username in Access 2000, but im having trouble.
So far im using this..
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function CurrentUser() As String
Dim strBuff As String * 255
Dim x As Long
CurrentUser = ""
x = GetUserName(strBuff, Len(strBuff) - 1)
If x > 0 Then
x = InStr(strBuff, vbNullChar)
If x > 0 Then
CurrentUser = UCase(Left$(strBuff, x - 1))
End If
End If
End Function
And on my form, I have a text box with 'control source' set to =CurrentUser.
Problem is this returns 'Admin', which I assume is what im logged into the DB as. But i want the windows username, not this.
Anyone help please?
lee
Lee Saunders
Win XP Professional : VB6 Enterprise / VB 2005 Express
History admires the wise, but it elevates the brave.
-
Jun 4th, 2005, 03:12 AM
#2
Re: Cant get username
Call the function with a msgbox. I just did and got the windows user name.
-
Jun 4th, 2005, 05:40 AM
#3
Re: Cant get username
 Originally Posted by Lee_S
Problem is this returns 'Admin', which I assume is what im logged into the DB as. But i want the windows username, not this.
Anyone help please?
lee
That does return the Current Windows Username. For me it Returns Ryan Jones as that is my Windows Loggin name and, my Office Name if RJones so it does work.
Cheers,
RyanJ
-
Jun 4th, 2005, 09:06 AM
#4
Re: Cant get username
I wrote that code and it does return the current logged user username . The problem is that the
function call is conflicting with the Access Property "CurrentUser" which returns the Access logged
in user - "Admin" usually.
Change the function call to something other then CurrentUser.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|