Security/Editing fields

D

Doug_C

Hello,

I have a form that has 10 fields made up of Text and CBO's. How can I make
it where user are only allowed to edit 4 fields on the form for each record
but management can edit in all 10 fields? Is there a way to lock the fields I
don't want edited and have management click a button to prompt a pop up for a
password to open the fields or is there a easier way? Please note, I am a
novice so you will need to walk me through and simplify your response. your
help would be most appreciated.

Thank you in advance!
 
E

Eric D via AccessMonster.com

Yes, you can do exactly as you outline.
You can set the 4 fields you mention to Enabled=True, Locked=No and the
others to Enabled=False, Locked=Yes.
Create a button that prompts for a password. If entered correctly, code
changes the Enabled=False to Enabled=True and Locked=Yes to Locked=No.

This requires a hardcoded password and is not the best way of accomplishing
what you want, but it meets your criteria and would be the simplest to
perform. Note that anyone who has the know how could bypass this and anytime
a manager doesn't want to take on this task, if they give the password to
someone else, you security is bypassed.

If your users are required to log on and enter a password now, that would be
the better way to go... but you don't indicate that in your request.
 
K

Klatuu

In design mode of your form, set the Locked property to True for the controls
that only managers may edit. Then create a command button on your form to
allow managers to unlock them with a password. Lets call the command button
cmdUnLock. You will also need a text box to get the password. Let's call it
txtPwd. Set the Visible property to False and the Input Mask to "password".
Then in the Click Event of cmdUnLock, make the password text box visible and
set the focus to it. In the After Update event of txtPwd ask for a password,
validate it, and if you get a correct password, then unlock the controls and
make txtPwd invisible.

Private Sub cmdUnLock_Click()
Me.txtPwd.Visible = True
Me.txtPwd.SetFocus

Private Sub txtPwd_After_Update()
dim intTries as Integer
Do Until intTries = 3
If Me.txtPwd = "TheSecretPassWord" Then
Me.AnyLockedControl.Locked = False
Me.AnotherLockedControl.Locked = False
intTries = 3
Else
MsgBox "Incorrect Password"
intTries = IntTries + 1
End If
Loop
Me.SomeOtherControl.SetFocus
End Sub

Now, notice that we set the focus to Me.SomeOtherControl. This can be any
unlocked and enabled control. It should be one that non managers can edit.
The reason is, that we need to make txtPwd invisible, and you cannot set the
Visible property to False for a control that has the focus. So, in the
GotFocus event of the control you set the focus to:

Me.txtPwd.Visible = False

I think this will do it.
 
K

Klatuu

It is not necessary to set both the Enabled and Locked properties. The
Enabled property greys out the control so it is harder to read. The Locked
property leaved the back color alone, but disallows any changes to the
control.
 
K

Klatuu

No reason they should be any different than the others. What kind of
controls are they? text box, combo box, etc?
Are you getting an error? If so, what is it?
 
D

Doug_C

This is the code I enter in the commend Button:
Private Sub cmdUnLock_Click()
Me.txtPwd.Visible = True
Me.txtPwd.SetFocus
End Sub

This is for the Password Textbox:
Private Sub txtPwd_AfterUpdate()
Dim intTries As Integer
Do Until intTries = 3
If Me.txtPwd = "amegy" Then
Me.Requestor.Locked = False
Me.Project.Locked = False
Me.OnPoint.Locked = False
Me.RN.Locked = False
Me.DateReq.Locked = False
Me.TargetDate.Locked = False
Me.Action.Locked = False
Me.Item.Locked = False
Me.Method.Locked = False
Me.BUPOD.Locked = False
intTries = 3
Else
MsgBox "Incorrect Password"
intTries = intTries + 1
End If
Loop
Me.Delegate.SetFocus
End Sub

And this is in the Non Locked field:
Private Sub Delegate_GotFocus()
Me.txtPwd.Visible = False
End Sub

I am in the process of deleting the fields and remaking them as sometimes
Access has it's quirks I thought it would be worth a try.
 
K

Klatuu

Good for you! Save every little code trick you run accross. I always tell
people I have only ever written 3 programs. Everything else is copy/paste
from those :)
 
D

Doug_C

Hi Klatuu,

your code worked great!!! Only one thing though. For some reason, it is
giving me a problem unlocking two fields. Every time I run the code it stop
on only those two. When I remove them, the code works find and everything but
those two fields are unlocked. Do you have any ideas?

Thank you!
 
D

Doug_C

They are both a cbo and the error states "Compile Error: Method or Data
Member Not Found" and the part of the code that is highlighted is .Locked =
If I remove these two fields from the code, it works perfect.
 
D

Doug_C

Klatuu, I am very sorry. I found the problem it was a rookie error. In the
name field of the cbo I had a space between the two words. I took the space
out and the code works like a gem. I want to thank you very much for your
help and staying with me on this and also for the simplifying the steps for
me. I am going to save this code so in the future I can using again and
retain it.

Have a great day!!!!!
 
Top