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
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