password to forms (1 Viewer)

steve111

Registered User.
Local time
Today, 22:22
Joined
Jan 30, 2014
Messages
429
hi,


i have a form called departments . one that form i have 5 buttons
I want this form only to open when some logs onto the database
the buttons represent each department
1. sales
2 purchasing
etc etc


is it possible to assign a password to those buttons so each department has security to thier own form

steve
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:22
Joined
Feb 19, 2013
Messages
16,618
is it possible to assign a password to those buttons so each department has security to thier own form
yes, a number of ways, but without an explanation of what you have at the moment in the way of storing user data (e.g. username, password) there is no way to determine which is appropriate for you

A very simple way would be

Code:
 Private Sub btnSales_onClick()
  
     if inputbox("Enter Password")="password" then docmd.openform....
  
 End Sub
change "password" to that required for sales

But this is not very secure (someone from purchasing could be looking over the shoulder of someone from sales), the password is hard coded, etc

If it meets your needs, great, otherwise you need to be a lot clearer about what you require
 

Mile-O

Back once again...
Local time
Today, 22:22
Joined
Dec 10, 2002
Messages
11,316
Perhaps a bit more complex, but one thing I do i:

1) Have a User table. One of the fields in this will be the user's Windows ID
2) Have a query on the User table, where the criteria is based on the Windows ID (see fOSUsername() function - google it!)
3) Create a User class with properties that store information about the current user.


Therefore, I can declare globally the class module, like so:

Code:
Public ThisUser As New User

Then, in my database I can refer to my relevant properties, such as:

Code:
If ThisUser.CanViewAdminMenu Then

If ThisUser.UserLevel = ulAdministrator Then

ThisUser.Name

ThisUser.Email

etc

For basic menus, perhaps a Yes/No field would work in the User table. For more complex permissions based (i.e. Users to UserLevels to UserLevelsToPermissions to Permissions [to PermissionCategories!] then more work is involved.
 

steve111

Registered User.
Local time
Today, 22:22
Joined
Jan 30, 2014
Messages
429
hi

thanks

I put this in but got an error " argument not optional"
Private Sub Command369_Click()

If InputBox("Enter Password") = "sales" Then DoCmd.OpenForm.sales orders
End Sub

steve
 

Mile-O

Back once again...
Local time
Today, 22:22
Joined
Dec 10, 2002
Messages
11,316
Your issue is:

Code:
 OpenForm.sales orders

Should probably be DoCmd.OpenForm "Sales Orders"

Basically, it thinks Sales is a method of the OpenForm command and Orders is a parameter you are passing to it.
 

steve111

Registered User.
Local time
Today, 22:22
Joined
Jan 30, 2014
Messages
429
thank you that part is working ok
how do we modify it to say "wrong password " until the correct password is entered

steve
 

spikepl

Eledittingent Beliped
Local time
Today, 23:22
Joined
Nov 3, 2010
Messages
6,142
@Mile-O, #3

I think it would be a very valuable addition to the code repository, if you could extract your login-class and examples and store it there.
 

steve111

Registered User.
Local time
Today, 22:22
Joined
Jan 30, 2014
Messages
429
hi
I have found this
rivate Sub Command370_Click()
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Please Enter the password to allow access."
strInput = InputBox(Prompt:=strMsg, Title:="Special Password")
If strInput = "steve" Then 'password is correct
DoCmd.OpenForm "sales orders"
DoCmd.Close acForm, Me.Name
Else 'password is incorrect
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access to the ''sales form''.", vbCritical, "Invalid Password"
Exit Sub
End If
End Sub
 

Mile-O

Back once again...
Local time
Today, 22:22
Joined
Dec 10, 2002
Messages
11,316
@Mile-O, #3

I think it would be a very valuable addition to the code repository, if you could extract your login-class and examples and store it there.

Perhaps I will. Would need to detach it from lots of other stuff, etc. Plus comment it for an example, etc.
 

mjdemaris

Working on it...
Local time
Today, 14:22
Joined
Jul 9, 2015
Messages
426
Thank you, Mile-O! I was just thinking about creating a user class for my new application, since I will be needing to lookup various data for permissions, and decided to use Google's Advanced Search on this site, et voila!

mjd
 

Users who are viewing this thread

Top Bottom