Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using windows permissions on a form 2

Status
Not open for further replies.

TravTrav

IS-IT--Management
Jun 4, 2002
115
US
Hello all, I am extremely new to access, so please bear with me, as I may sound like an idiot at times. What I would like to do is make a form that is only available to certain users, and I would like to either base this on windows permissions, or if that is not possible, set a password to use this form. Any suggestions on the easiest way to do this. (please break this down idiot style for me)

Thanks So Much,
Travis
 
The easiest way by far is to have an inputbox prior to the form opening - the inputbox will require a Password to allow the form to open otherwise the user will not be allowed to proceed.
The password will only be known by those with permission to use the form.


Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
This is how I would do it.

Create a password table (tblPassword). It will need 2 fields -- UserName and Password.

Create a form (frmPassword)with 2 text boxes and 2 command buttons. I'll call them txtName, txtPassword, cmdEnter, cmdCancel. Make it a popup form.

Put an input mask (Password) on the txtPassword text box so it will display ****'s when typing the actual password. Do the same thing with the Password field in the table.

On the screen/menu you are currently using to open the form you want protected, open the frmPassword form instead.

On the frmPassword form... In the click even of the cmdEnter button, place this code...
if not isnull(dlookup(me.txtName, "tblPassword")) Then
if me.txtPassword = dlookup(me.txtPassword, "tblPassword", "UserName = '" & me.txtName & "'") Then
docmd.openform "YourProtectedFormName"
docmd.close acform, "frmPassword"
else
msgbox "Invalid Password"
end if
else
msgbox "Invalid User Name"
end if


In the click event of the cmdCancel button...
docmd.close acform, "frmPassword"



Randy
 
This is what I want to do, but my real question is how do I do it?
 
In the codepage for the open form command button put this:

Dim strInput As String, strMsg As String
strMsg = "Enter the password to open this form."
strInput = InputBox(Prompt:=strMsg, Title:="User Authority")
If strInput <> "Supervisor" Then
DoCmd.Openform "frmWahtever"
Else
MsgBox "You don't have the authority to open this form - so SOD OFF!"
End If

Frank J Hill
FHS Services Ltd.
frank@fhsservices.co.uk
 
Randy,
When I try the code for cmdEnter, as soon as I click the command button, it gives me this error message:

Run-time error '2001':

You canceled the previous operation.

When I go to debug it, it highlights this string of code:

if not isnull(dlookup(me.txtName, "tblPassword")) Then

Any ideas?
 
Sorry, don't know what I was thinking. Here is the correct code...

If Not IsNull(DLookup("UserName", "tblPasswords", "UserName = '" & Me.txtName & "'")) Then
If Me.txtPassword = DLookup("Password", "tblPasswords", _
"UserName = '" & Me.txtName & "'") Then
DoCmd.OpenForm YourProtectedFormName
DoCmd.Close acForm, "frmPassword"
Else
MsgBox "Invalid Password"
End If
Else
MsgBox "Invalid User Name"
End If


Randy
 
Randy,
Same error, and it still highlights the same line of code.......
 

Private Sub Command4_Click()

If Not IsNull(DLookup("UserName", "tblPasswords", "UserName = '" & Me.txtname & "'")) Then
If Me.txtpassword = DLookup("Password", "tblPasswords", _
"UserName = '" & Me.txtname & "'") Then
DoCmd.OpenForm "Change Management Approval"
DoCmd.Close acForm, "frmPassword"
Else
MsgBox "Invalid Password"
End If
Else
MsgBox "Invalid User Name"
End If



End Sub
 
I can find nothing wrong with your code and the identical code works in my applications. The only thing I can think of is that something isn't named properly. I would double check the names of the controls on your form, the form itself, the table, and the fields in the table. Look for simple mistakes, like tblPassword instead of tblPasswords.

Randy
 
Alright, figured my problem out with the code. I had the username and password text boxes labeled incorrectly. So that is working now, but I have a couple of other problems. Now, these are problem extremely basic questions, but here goes:

1. How do I stop the form from allowing someone to scroll through the usernames and passwords and just using them.

2. How do I make the table so that no other data can be entered into it via the form. Right now if I type an incorrect username and password, the first time it says invalid, but if I close and open the forms, since those values have been added to the table, they can use that username and password that they made up.

Thanks,
Travis
 
OK, figured out how to not let them scroll through the names, I just have the button that opens it do it in new mode instead of edit mode....Still dont know how to lock down the table though. Thank you guys so much for your help, I really do appreciate it.
 
You should not be adding anything to the table from this form. Sounds like you have your form/controls bound to the table. This form and the controls should be unbound (nothing in the control/record source).


Randy
 
Gotcha, works perfect now. Thanks for both of your help, I actually tried both ways, but Randys turned out being better for what I needed it for. You both get a star.

Thanks Again,
Travis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top