Isolating fields with password protection


K

K. Boomer

Hello:

I would greatly appreciate if someone could review my code below and let me
know what I need to change to make it work. I am not at all experienced in
code writing, but have pieced together what I could from various resources.
What I am trying to accomplish is this:

I have a form with approximately 30 fields. I need to isolate 10 of them by
locking for editing unless the correct password is entered. I'd like an
input box to pop up when the first field in the group of 10 is selected.
There will only be one or two people who are required to enter data is these
10 fields, so hardwiring a password in the code will work just fine. It's
not seriously confidential data, so I don't need anything complex - just a
way to keep certain users out of those fields.

BTW, I have entered the word Protected in the Tag property for all 10 fields.

Am I even close to being on the right track?
Thank you in advance for your help.
____________________________________________________
Private Sub Form_Current()

Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
If ctl.Tag = "Protected" Then
ctl.Locked = True
End If
End If

Next

End Sub

Private Sub UnLockControls_Click()

Dim strInput As String
Dim ctl As Control

' Check for password here, if passes Then
' show InputBox asking for password
strInput = InputBox("Please enter a password to access this field", _
"Restricted Access")

' Check if value is entered into InputBox
' If no value entered display MsgBox
If strInput = "" Or strInput = Empty Then
MsgBox "No Input Provided", , "Required Data"

Exit Sub
End If

' Check InputBox value and if value is a match
' allow editing
If strInput = "password" Then

For Each ctl In Me.Controls
If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
If ctl.Tag = "Protected" Then
ctl.Locked = False
End If
End If
Next

End Sub
 
Ad

Advertisements

L

Lord Kelvan

as john would say what is wrong it is like going to the doctor and
saying i am sick give me meds you cannot some here and say fix my
problem if we dont know what the problem is

what is happening or not happening which is the problem if the code
wont run click on debug and tell us what is highlited

Regards
Kelvan
 
K

K. Boomer

Thanks for the response.

The problem is that I'm not seeing the Input Box pop-up when I click on the
first field in the group of 10 that I have protected.

Obviously, I do not have the correct code, nor do I have experience writing
code. That's where I was hoping someone could assist me.

I'd like to password protect 10 fields on a form of 30. I'd like to click
on the first field named "Qty on Hold" and have an Input Box pop-up asking
for a password. Once the correct password is entered, the Qty on Hold field
is unlocked as well as the following 9 fields. Is that possible? Perhaps I
should have just asked that question instead of muddying the waters trying to
write code myself.

Is there someone who can tell me step-by-step how to accomplish what I've
explained above? Forgive my ineptness where Access is concerned. I'm simply
new and trying to learn.

Thanks very much to anyone who may be able to help me.
 
K

K. Boomer

Sorry, I forgot this in my second post.

The following is hightlighted in green in the code:


' Check for password here, if passes Then
' show InputBox asking for password

' Check if value is entered into InputBox
' If no value entered display MsgBox

' Check InputBox value and if value is a match
' allow editing
 
L

Lord Kelvan

i am taking it that UnLockControls is the name of the text box

ok first of all to get the click event to work you have to give the
box focus then click dont use textbox_click use gotfocus

you also need a public variable so the box wont display multiple times

also you need to use form_open not form_current

'--- code start -----'
public passwordgot as boolean

Private Sub Form_Open()
passwordgot = false

Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
If ctl.Tag = "Protected" Then
ctl.Locked = True
End If
End If
Next
End Sub

Private Sub UnLockControls_gotfocus()

Dim strInput As String
Dim ctl As Control
'wont run the code is the password is not correct
if passwordgot = false then
' Check for password here, if passes Then
' show InputBox asking for password
strInput = InputBox("Please enter a password to access this
field", _
"Restricted Access")

'you dont want to do this as it is not worth it
' Check if value is entered into InputBox
' If no value entered display MsgBox
' If strInput = "" Or strInput = Empty Then
' MsgBox "No Input Provided", , "Required Data"


' Exit Sub
'End If

' Check InputBox value and if value is a match
' allow editing
If strInput = "password" Then
passwordgot = true
For Each ctl In Me.Controls
If (TypeOf ctl Is TextBox) Or (TypeOf ctl Is ComboBox) Then
If ctl.Tag = "Protected" Then
ctl.Locked = False
End If
End If
Next
else
if not isnull(strinput) then
msgbox "the password you have entered is incorrect"
end if
end if
end if
End Sub

'--- end of code ---'

hope this helps

Regards
Kelvan
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top