Solved

Access 2003 VBA and Windows Username question

Posted on 2007-04-11
3
630 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

937 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

3 Experts available now in Live!

Get 1:1 Help Now