Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Loged in user

  1. #1
    Join Date
    Jun 2006
    Posts
    72

    Unanswered: Loged in user

    Access 2003

    With user level security, is it possible in VBA to determine who is loged in and perhaps even their user group?

    Something like

    CurrentDB.CurrentUser.Name
    CurrentDB.CurrentUser.UserGroup

    would be perfect. Obviously those don't exist but that's what I'm after.

    [EDIT]

    I've done some reading and I've found you can determain if the current user has permission to do certain things to certain objects but not who the current user is and I can technically do what I want to with that but it would be dirty.
    Last edited by Access Junkie; 08-20-07 at 22:38.

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Here's an example you can look at for getting the windows user login and establishing a "security" type table:

    http://www.dbforums.com/showpost.php...0&postcount=20

    Using the SystemInfo class module you can return more than just the user login name but read the comments in this module. (Note: you need the SystemInfo module in your mdb but I've used this error free for quite a number of years now.)

    The nice thing about the Function: GetUser() is that I can utilize it anywhere (ie. I can set the default value of a text field to =getuser(), or the control source =getuser(), or I can use it in an expression in a query, etc..)

    This is just one way to do it. There are other ways. You can also research tapping into Active Directory values.
    Last edited by pkstormy; 08-20-07 at 22:58.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jun 2006
    Posts
    72
    While waiting for a reply in this thread I found a way to do what I wanted.

    DBEngine.Workspaces(0).UserName
    DBEngine.Workspaces(0).Users(DBEngine.Workspaces(0 ).UserName).Password

    I couldn't get the password one to work but that may be because I wasn't logged in as a user with a password.

  4. #4
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Just cuurrentuser wil return the username. problem is - that it is the Access MDA/MDW user not the NT Authentication/Windows username

    There is some great API code to return the username and machine name of windows users. That is how I usually handle security in Access - not the Access security module. Remember - windows enforces the most restrictive - Access enforces the least restrictive, thereby creating chaos when you add additional objetcs(forms, reports, pages, etc)

    go to support.microsoft.com and search :
    VBA: Sample Code to Retrieve the Current User Name

    Here is the link if you have never been there:

    http://support.microsoft.com/kb/161394/en-us

    everyone should have this in their library

    By using this type security you can control from a table lookupp who can open forms to modify data, delete data, etc.
    Dale Houston, TX

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You may want to just take a look at the example I posted if you get a chance (never hurts to look at code from a trusted source). There is a lot of information which can be returned using the SystemInfo class module in the example and it does return the "windows" user login. Plus there are a few other things which you may find helpful in the example.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Mar 2007
    Posts
    277
    JUst a bit off topic but Jeff Conrad has had that handle for a number of years.
    http://www.accessmvp.com/JConrad/accessjunkie.html
    RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP, ac07, ac10 - WinXP Pro, Win7 Pro
    Please reply to this forum so all may learn.

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I'm not claiming any credit on the coding to get the user login name (I could not find Jeff Conrad's name in the MVP listing on Microsoft's website - could you please supply the link to his MVP name on Microsoft's website?)

    I believe it was around 2001 where I used the Sybex book and SystemInfo module to get the user login name. The technique I'm referring to in the example that I think is worth looking at is the way it locks the form as a popup modal using the FormInfo to remove the caption and preventing the user from easily getting behind the scenes (or using any of the MSAccess menu items). A developer can click an "admin" close button on the form to quickly get behind the scenes. Another form will open depending on whether the user is in the security table (dbo_Admin table) or not. Getting the user login name is only part of the technique in the example and all the credit using this method for retrieving the windows user login name goes to Sybex which developed the SystemInfo module in 2000. I could only find information on Jeff Conrad's MSAccess book on his website for MSAccess 2007. There are 4 reviews on his MSAccess 2007 book which are all excellent (5 stars) and I'd like to learn more about his book.

    My own personal opinion is that the Sybex books are excellent MSAccess resource books with great examples on the included cd. But that is my own personal opinion (and no disrespect to Jeff Conrad or you RuralGuy.) I believe the book referred to in the link provided for Jeff Conrad's book has a cd with the book (as does the Sybex books.) I'm not sure if Jeff Conrad's cd uses a setup.exe file that the user must install to see the examples and I'd like to learn more about the cd. Personally (and again, just my personal opinion) is that I don't like running a setup.exe file to install "all" the examples but would rather just see the mdb files on the cd in each corresponding folder matching the chapters. This is so I can copy the folders/mdb files off the cd as I read or need them to the computer I'm working on.

    Could you please supply more information on Jeff Conrad's book so I can learn more about it?
    Last edited by pkstormy; 08-21-07 at 23:58.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  8. #8
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Function GetXLUserName() As String
    ‘Returns the user name entered under
    ‘Tools>Options>General
    GetXLUserName = Application.UserName

    End Function


    Declare Function apiGetUserName Lib “advapi32.dll” Alias _
    “GetUserNameA” (ByVal lpBuffer As String, _
    nSize As Long) As Long


    Function GetUserName() As String

    Application.Volatile
    Dim sBuff As String * 25
    Dim lBuffLen As Long

    lBuffLen = 25
    apiGetUserName sBuff, lBuffLen
    GetUserName = Left(sBuff, lBuffLen - 1)
    debug.print GetUserName
    End Function
    Dale Houston, TX

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by Error Message
    Compile Error:

    Method or data member not found
    Code:
    Application.Volatile
    Code:
    GetXLUserName = Application.UserName
    George
    Home | Blog

  10. #10
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5

    it was a quick post

    more for reference than 100 percent functionality but I use it in every app I build
    Dale Houston, TX

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    It looked good, so I tried it - but obviously missing something!
    Fancy pointing me in the right direction to get it to work?
    George
    Home | Blog

  12. #12
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Dale Houston, TX

  13. #13
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5

    tons of great vb code there

    great forum the link I sent has the returnusername function halfway down the page
    Dale Houston, TX

  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Yes - there's a lot of good vb code in the link you provided axsprog - thank you - it is very helpful.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  15. #15
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Excellent developers do not need to know everything - they just need to know where to find it. I must admit that there have been times that I have used snippets of code that I really did not grasp fully what they were doing other than solving my issue. Smoke and mirrors - smoke and mirrors.

    In all seriousness - that VB forum is for vb , on the same level that this one is for DB's

    have a good day Storm and thank you for your professional resolutions here.
    Dale Houston, TX

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •