Solved

Access 2003 VBA and Windows Username question

Posted on 2007-04-11
3
677 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 250 total points
ID: 18890432
Except use quotes:

strUserName = environ("username")
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

729 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