How to create a password access within Database

John Lee

New member
Local time
Today, 04:12
Joined
Dec 1, 2024
Messages
16
I have my database which has a number of form views and I want to password protect one of my forms [Employees] so that only authorised individuals can access that part of the database, my form object name is frmEmployees and the button the is clicked to open this form is named cmdOpenfrmEmployees.

So what I would like to achieve is that when a person clicks on this button that they are prompted for their login ID and password, the password needs to masked as you would normally when logging into any application.

Any assistance would be most appreciated.
 
Do you have a working login form already?
 
Do you have a working login form already?
No, as the rest of the database doesn't need it, just this one form needs to have some level of protection from unauthorised users
 
Just use the password format of the textbox to mask the entry.
Where do you intend to keep the password? in code or in a table?

What I did was hide anything from users who were not meant to use it. So check the user when they login and hide that button if not authorised.
 
Just use the password format of the textbox to mask the entry.
Where do you intend to keep the password? in code or in a table?

What I did was hide anything from users who were not meant to use it. So check the user when they login and hide that button if not authorised.
Hi, my thoughts were to have the passwords stored in a table for ease, but I suspect that might not be a good idea.
 
Hi, my thoughts were to have the passwords stored in a table for ease, but I suspect that might not be a good idea.
Well the password will not be visible if you use the Password Input Mask on the field.
1734705320883.png
 
You could just check the username

Environ(“username”)

If it’s not you (or whoever has the authority to open the form) hide the button that opens the form

Button.visible =Environ(“username”)=“harry”
 
You could just check the username

Environ(“username”)

If it’s not you (or whoever has the authority to open the form) hide the button that opens the form

Button.visible =Environ(“username”)=“harry”
Hi CJ, thank you for that, I'll let you know how I get on.
 
try this code on the cmdOpenfrmEmployees Click event:
Code:
Private Sub cmdOpenfrmEmployees_Click()

    If InputBox("Enter password to open Employee form", "Password Protected") = "yourPassword" Then
        DoCmd.OpenForm "Employees"
    End If
    
End Sub
 
Could as suggested check username, then in the Form Load
Code:
Me.cmdEmployee.Visible = Environ("username") = "JohnL"
and make the button invisible to start with.
If you do it the other way, then the button is visible for a split second.
 
try this code on the cmdOpenfrmEmployees Click event:
Code:
Private Sub cmdOpenfrmEmployees_Click()

    If InputBox("Enter password to open Employee form", "Password Protected") = "yourPassword" Then
        DoCmd.OpenForm "Employees"
    End If
   
End Sub
Hi Thank you.
 
You could just check the username

Environ(“username”)

If it’s not you (or whoever has the authority to open the form) hide the button that opens the form

Button.visible =Environ(“username”)=“harry”
Hi CJ, where would I place this bit of code you've provided, would it be on the main menu where the Employee button resides?
 
If you want to manage passwords, you need logins and all that entails. Here is a very simple sample that you can strip down for your needs. To mask the password, use the password format for the field.

 
Could as suggested check username, then in the Form Load
Code:
Me.cmdEmployee.Visible = Environ("username") = "JohnL"
and make the button invisible to start with.
If you do it the other way, then the button is visible for a split second.
Hi, just to confirm, I would need to write the above code for each individual I want to have access to that form, I just tested it using my email address and the button was hidden, however I don't know what user name it is looking for on my home PC, so I'm not able to check if it displays the button for an authorised user, any assistance is appreciated.
 
Hi, Whats the purpose of PositionID and Userlevel as numbers?
Just data for the system. I used them to do what you are attempting.
PositionID is their positions in the company
Userlevel self explanatory.

Just because someone was in a certain position did not mean they got the same userlevel as others in the company at that position.
 
Hi, just to confirm, I would need to write the above code for each individual I want to have access to that form, I just tested it using my email address and the button was hidden, however I don't know what user name it is looking for on my home PC, so I'm not able to check if it displays the button for an authorised user, any assistance is appreciated.
In the debug window enter
? environ("username") to see what your username is on that computer.

If you are going to have a bunch of users, then have a flag in a table that you can lookup.
 
I would need to write the above code for each individual I want to have access to that form
it depends on how sophisticated you want to get. You could have a table of allowed users and your code could be

Button.visible =dlookup("username","tblAllowedUsers","username ='" & (Environ(“username”) & "'")<>""

I presume you have other security in place such as preventing users from viewing the navigation pane which would allow them to open the form just by clicking on it.
 

Users who are viewing this thread

Back
Top Bottom