Solved

Access 2003 VBA and Windows Username question

Posted on 2007-04-11
3
617 Views
Last Modified: 2013-11-25
Can I use the windows username in a vba function to compare to a value in an access database and then return the security level based on that, I really only need help getting the Windows username from the system to the vba module, help I am constrained to VBA/Access 2003 only and I know that this would take about 5 minutes in C# and SQL Server. Any ideas would be appreciated.
0
Comment
Question by:jmcdonald69124
  • 2
3 Comments
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Use the following VBA:

strUserName = environ(UserName)
0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
Comment Utility
Except use quotes:

strUserName = environ("username")
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 250 total points
Comment Utility
U can use the api function, something I prefer cos environment variables can easily be spoofed

add this to a module

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

Public Function GetMyUserID() As String

    Dim sBuffer As String
    Dim lSize As Long
   
    sBuffer = Space$(255)
    lSize = Len(sBuffer)
   
    If GetUserName(sBuffer, lSize) = 1 Then
        GetMyUserID = Left$(sBuffer, lstrlenW(StrPtr(sBuffer)))
    Else
        GetMyUserID = ""
    End If

End Function




Now just call GetMyUserID to get your windows logon id
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now