Results 1 to 9 of 9
  1. #1
    Carrinmere is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    15

    VBA Password via Button

    So I would like to restrict different parts of my database for different users. For example I have several forms dedicated to managing resources, and several for administration of personnel. I dont want the administrators to have access to the resource section. So my thought was to develop a VBA script designed to request a password when a button is pressed, and if they enter the correct script, then the Form will open. Example: I have a button titled Resource_Button...when pressed it opens the form that give access to other forms that manage our inventory and distribution and other such actions. When pressed, I would like a text box to appear that says "Enter Password" and if they type "Ghostrider" the form opens up. If not then the words "Incorrect Password" and the script ends. Looking for suggestions.



    Bryan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,819
    Demanding a password is one way to go. Another is to identify user when db opens and don't even display buttons if they should not have access to certain features.

    Either presumes you've designed the db to hide Navigation Pane, disable/modify ribbon, disable/modify right click shortcut menus, and don't allow shift key bypass. Is db deployed as accde?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    In conjunction with June7' post, IMO a table of users and their permissions level (as well as other attributes) is the best approach. Also a tblPermissions table with fields for a role (e.g. admin, user, manager, etc. ) which if also given a numerical sort order field, allows you to put the levels in ascending order. That way, when you open a form, you can allow buttons to be seen by (for example) anyone with a level of 3 or greater or if need be, just with a level 3 or between 3 and 5 - any logical/mathematical comparison that can be made. Same for opening a form or viewing a report; allow or don't based on their permissions level.

    Unless users are sharing a Windows login I don't see the point of db passwords. Said table of users can hold their Windows login name (and if desired, their pc id). When anyone opens the db, if their Windows login is found, they're in. If not, they're not - no passwords and no password related maintenance required.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Carrinmere is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    15
    So the reason I am doing the password method is that I work for the military and people come and go on a fairly regular basis including myself. If and when I leave, as the creator of the database and honestly the only one who has a mild understanding of access, it is easier to pass along passwords to people as they come and go as opposed to updating security tables.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,819
    It's a common topic. Look at links at bottom of this thread.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Carrinmere is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    15
    Yes everything will be hidden. And the reason I want to do it as a password is that I work for the military and people come and go including myself. I am the only one who has a understanding of access and most people are scared they would ruin the database and get in trouble if they messed with the inner workings so people cracking the codes is not a worry.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Not trying to change your mind because you know best. I'd say that if anyone is adept at entering/modifying data it's not much of a stretch that anyone designated as an admin can enter user details in a table as easily as any other user can enter data. The rest is automatic. You want simple (I think) yet you're willing to go down a road that requires more maintenance. Who is going to help those users who have forgotten their password or want to change it (not to mention that they can share it, so not real secure there)?

    If it's military and it needs any serious level of security, then Access really isn't the right tool.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I agree with the others that your approach is not the most secure. But if you want to apply a password to a form it would be better to do it in the form's own Open event (that can be canceled) rather than in a Click event of a button that opens that form. The open event would prevent opening the form from the navigation pane while the click won't.

    Please have a look at the attached sample. Note that I added a custom system table named usysFormSecurity to store the passwords for each form to be preotected. To view the table go to File\Options\Current Database and under the Navigation Options turn on visible system objects.

    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The click event won't even open a form if you exit when validation of the user fails. Then you don't have to deal with trapping error 2501 ( going on memory there).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-27-2019, 09:42 PM
  2. Replies: 8
    Last Post: 05-08-2016, 09:41 AM
  3. button a form to open But with password
    By azhar2006 in forum Forms
    Replies: 2
    Last Post: 04-08-2015, 11:24 AM
  4. Replies: 5
    Last Post: 11-26-2013, 09:20 AM
  5. Password Protect button on Switchboard
    By rosaj in forum Access
    Replies: 1
    Last Post: 08-04-2011, 11:08 AM

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