Results 1 to 7 of 7
  1. #1
    Monty51 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    48

    Restrict a .accde file to a particular user

    I'm almost done converting an Access 97 application to Access 2016 except for this one thing: with the Access 97 version, launching of the application was limited to a particular user from the command line with the /user switch, in this case "/user aeroclub". A user name "aeroclub" was defined with 97's user-lever security functions and listed in the system.mdw file. Access 2016 does not have that and, if I'm reading things right, relies on the creation of a .accde file to prevent users from manipulating the application. I'm all for that, but is there still a way to restrict launch of the application to a particular user? I.e., I only want a user named "aeroclub" (or another appropriately named user) to launch the application. All others should get some kind of "permission denied" kind of error.



    Any help on this is greatly appreciated.

    Monty51

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    at the start up form ,
    on form_Load event get user info then lookup in tUser list of authorized people:


    Code:
    sub form_Load()
    if IsValidUser() then
       'continue here w stuff
    else
        msgbox "You are not authorized"
        docmd.quit
    endif
    end sub
    
    
    
    Public Function IsValidUser() As boolean
    dim sUserID as string
    sUserID = Environ("Username")
    IsValidUser=not Isnull( Dlookup("[UserID],"tUsers","[UserID]='" & sUserID & "'") )
    End Function

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    Use the same functionality?
    https://youtu.be/rwkff-jsNHQ
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Monty51 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    48
    Quote Originally Posted by ranman256 View Post
    at the start up form ,
    on form_Load event get user info then lookup in tUser list of authorized people:


    Code:
    sub form_Load()
    if IsValidUser() then
       'continue here w stuff
    else
        msgbox "You are not authorized"
        docmd.quit
    endif
    end sub
    
    
    
    Public Function IsValidUser() As boolean
    dim sUserID as string
    sUserID = Environ("Username")
    IsValidUser=not Isnull( Dlookup("[UserID],"tUsers","[UserID]='" & sUserID & "'") )
    End Function
    Ah! I was not aware of the Environ() function. If I read your suggestion correctly, it relies on a table named tUsers with at least one field, named UserID. I can do that.
    I think I'll be going this way, and thank you for your input.

  5. #5
    Monty51 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    48
    Quote Originally Posted by Welshgasman View Post
    Use the same functionality?
    https://youtu.be/rwkff-jsNHQ
    Thanks for the link. There's a lot of good stuff in there. However, I think I'll be going with ranman256's suggestion. I find that a little easier to digest (unless I'm missing something obvious, which could be).

    Thanks for your input.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    Quote Originally Posted by Monty51 View Post
    Thanks for the link. There's a lot of good stuff in there. However, I think I'll be going with ranman256's suggestion. I find that a little easier to digest (unless I'm missing something obvious, which could be).

    Thanks for your input.
    Seems like it.
    You can pass in the username like you did before with the cmd switch?
    I have never used an .mdw file and when I wanted to restrict users, I used a table as Ranman256 suggests. However that linked way seems to copy what you did before?
    However, it would not be difficult for someone to copy the shortcut properties and be able to open the db as aeroclub?

    If you are going to have a user table, then you will also need a password for that user?, else I could just say I am aeroclub ?
    Very easy to change username for environ as well.

    Open a command window and type set and press enter
    What is USERNAME
    Then key in 'set USERNAME=aeroclub' (without the quotes) and press enter. Now key in set and press enter again.
    Now what is the USERNAME ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Monty51 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    48
    Quote Originally Posted by Welshgasman View Post
    Seems like it.
    You can pass in the username like you did before with the cmd switch?
    I have never used an .mdw file and when I wanted to restrict users, I used a table as Ranman256 suggests. However that linked way seems to copy what you did before?
    However, it would not be difficult for someone to copy the shortcut properties and be able to open the db as aeroclub?

    If you are going to have a user table, then you will also need a password for that user?, else I could just say I am aeroclub ?
    Very easy to change username for environ as well.

    Open a command window and type set and press enter
    What is USERNAME
    Then key in 'set USERNAME=aeroclub' (without the quotes) and press enter. Now key in set and press enter again.
    Now what is the USERNAME ?
    Within the application all users have their own login. I just felt the need to restrict launching the application to a select user. The old user-level security of Access 97 - 2003 made that possible. With 2016 it looks as though I'll have to account for legitimate users in the application, so I'll be testing the Environ(Username) to see that only the correct user (a specified Win 10 user account) is launching the app. In this case that would be the "aeroclub" Windows account. This accomplishes what I want.

    Thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 12-17-2020, 08:55 PM
  2. Restrict user access
    By aliaslamy2k in forum Access
    Replies: 5
    Last Post: 05-12-2020, 01:48 PM
  3. Replies: 7
    Last Post: 03-27-2018, 06:07 AM
  4. Restrict linking table access to one file
    By gottnoskill in forum Import/Export Data
    Replies: 1
    Last Post: 04-15-2014, 06:04 PM
  5. Restrict user to navigation form
    By Whelt in forum Access
    Replies: 3
    Last Post: 04-22-2012, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums