?
Solved

Access 2003 VBA and Windows Username question

Posted on 2007-04-11
3
Medium Priority
?
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 18890421
Use the following VBA:

strUserName = environ(UserName)
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 18890432
Except use quotes:

strUserName = environ("username")
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 1000 total points
ID: 18890442
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

770 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