473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Password protecting a surname combo box on a form in access with VBA

I wonder if anyone is able to assist with this. I am trying to password protect a combo box so only certain people can select data. I want to be able to click in the combo box have a subform appear for a person enter a user name and password. The form will then close on the click of a button and they will then be able to select there name from the combo box list and update the record. I have the user name and password details stored in a table called [STAFFDETAILS]

Does anyone have some example code that may do this or be able to give some advice.

Many thanks in advance.
Jan 14 '16 #1
2 1311
zmbd
5,501 Expert Mod 4TB
dholdaway: Keep in mind that anything you do in Access can be bypassed by a fairly knowledgeable person.

There are a few ways to accomplish your goal; however, you do not mention which version of Office/Access you are using.

Generally, I use the before_update event of the control. Simplest would be to prompt for the password static password and then the code to check for a valid entry - using the me.undo and setting the update Cancel equal to true if the entry isn't valid.

You can get more complex from there... having tables that hold the user name and plain text (not advised) password to tables that have the user name and hashed (explanation of SHA2 hash)(better) password to tables that have the user name, possibly hashed, and password hashed with a random salt (best?) - along with forms and code that handle the user rights.

As for code and examples, that's not really what we do here; however, you might find TwinnyFo's treatment of user permissions to be interesting. I personally use a slightly different version of this; however, in the end, it's all the same.
Jan 15 '16 #2
jforbes
1,107 Expert 1GB
First I want to reinforce Zmbd's statement of:
Keep in mind that anything you do in Access can be bypassed by a fairly knowledgeable person.
This couldn't be truer.

I also want to point out that there is an alternative to Passwords and a Password Dialog and that is looking to the OS to get the Logged in Windows User and then Enabling and Disabling Buttons and other Controls based on the Users permissions. The advantages are:
  • There is no login process. Which is a minor thing, but helps a lot with the flow of the application as the user just launches it.
  • There is no Password maintenance. There is still maintenance because someone as an administrator will need to grant the rights to the different objects. But Passwords are not saved in the database, so people can't inadvertently find out someone else's Windows login through the use of password sharing. (Or a frisky user hacking the database)

To accomplish this, you will need a table to store whatever user based scheme of security you come up with, a function to get the User Name from Windows, place code at the form level enable/disable objects based on the currently logged in User's Permissions.

To get the User Name from Windows, place this function in a VBA Module. This piece of code is all over the Internet in quite a few different variations. This version is the one I've been using for the last couple years, but here is another version from MMcCarthy :
Expand|Select|Wrap|Line Numbers
  1. Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  2.  
  3. Public Function GetWindowsUser() As String
  4.     On Error GoTo ErrorOut
  5.  
  6.     Dim lngResponse As Long
  7.     Dim strUserName As String * 32
  8.  
  9.     lngResponse = GetUserName(strUserName, 32)
  10.     GetWindowsUser = Left(strUserName, InStr(strUserName, Chr$(0)) - 1)
  11.  
  12. ExitOut:
  13.     Exit Function
  14. ErrorOut:
  15.     MsgBox Err.Description
  16.     Resume ExitOut
  17.  
  18. End Function
  19.  
You can then marry up the Logged in User to their permissions however you want. Typically, I use some global Boolean variables for some basic permissions, like Manager, Administrator, Human Resources and set them when the application first starts up. Then code like the following can be placed in the Form_Current or Form_Load Event:
Expand|Select|Wrap|Line Numbers
  1.    Me.cmdLaunchAdministratorForm.Enabled = gAdministrator
  2.    Me.cboRecordOwner.Enabled = gManager
  3.    Me.cmdViewSalaries.Visible = gHR
One nice thing about coding it this way is that if someone forces a break in the code execution and somehow resets the Global variables, all the Globals get reset to False and it pretty much locks down the entire application.

This is just another option for you.
Jan 15 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: edd | last post by:
Ive seen a few examples of how to password protect my pages by either textfiles / access. But how can I make the pages so that no one can just enter the url and bypass the login page. Im trying...
0
by: Senthil Kannan | last post by:
Hi all, Currently i have a FORM_BASED Authentication of tomcat5.0 to store and retrieve passwords in my homepage.Now when i try to Store my password in a encrypted form i am having some problems,i...
1
by: M.C. Radhakrishnan | last post by:
Hi, I need to provide a facility to do routine database administration (backups, etc.) without allowing the logged in user to modify the data in any of the SQL server tables. Is there any way...
3
by: netsurfer | last post by:
hi..I'm working on a project that requires files to be password protected on a UNIX based site. The people that own the web site want to be able to change the password every so often. ...
8
by: Iain Napier | last post by:
I'm in the middle of developing a website with a downloads section. It's a wad of educational software for an LEA which for obvious reasons needs password protecting. Users have to authenticate...
1
by: anilla | last post by:
in order to access my system, users have to log in using username and password. i have a form where users can update or delete certain information. these information currently can be deleted or...
3
by: Porkie999 | last post by:
-----------------------------------------------------------------------QUESTION hi i am really stuck with this and its only a small problem. i want to be able to type ......... dsfsjfjsjjfs in...
8
djsjm
by: djsjm | last post by:
Hello again. So I googled myself into finding this code: <?php // Define your username and password $username = "someuser"; $password = "somepassword"; if ($_POST != $username || $_POST...
4
by: student2 | last post by:
Hi. I've placed the following code on the click event of a command button that leads to a form that is password protected:- Private Sub cmdSales_Click() Dim strPasswd strPasswd =...
5
by: SeadooRider | last post by:
The following code on form_load does ask for a password and opens the desired form if the password is entered correctly. However, if no password or the incorrect password is entered, I get the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.