Password Protecting Fields

D

DDrowe

I want signature blocks on my form only accessible to the person who signed
in. I have user level security so the person must sign in to have access to
the form but beyond that I only want that person to be able to fill his/her
name in, in their spot only to show agreement - electronic signature. I have
this on one form but cant duplicate it on the second. This is what was used
on the first - as best I can tell.

Private Sub Signature_BeforeUpdate(Cancel As Integer)
Dim Response As String
Response = InputBox("Enter Password", "Password Required")
If Response <> DLookup("[Password]", "tblSignaturePasswords",
"UserName=Forms!EHSRNew!Cuser") Then
Beep
MsgBox "Incorrect Password.", vbOKOnly, "Entry Denied"
Cancel = True
Signature.Undo
End If
End Sub

and

Private Sub Form_Current()
If CUser = "Drowe" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = True
Signature_6_.Visible = False
ElseIf CUser = "John Cefola" Then
Signature.Visible = True
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = False
Signature_6_.Visible = False
ElseIf CUser = "Jarod Craig" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = True
Signature_5_.Visible = False
Signature_6_.Visible = False
EndIf
EndSub
 
D

Douglas J. Steele

You need to take the reference to the form control outside of the quotes. As
well, since the UserName is (presumably) a Text field, you need to put
quotes around the value:

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName="""
& Forms!EHSRNew!Cuser & """") Then

That's four double quotes before the reference, and four double quotes
after. Ordinarily, I would use a single quote as the delimiter, but I wasn't
sure whether UserName was a real name (so that it might include apostrophes,
as in O'Reilly). If it can't include apostrophes, you can use

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName='"
& Forms!EHSRNew!Cuser & "'") Then

Exagerated for clarity, that's

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName= '
" & Forms!EHSRNew!Cuser & " ' ") Then
 
D

DDrowe

I guess my biggest confusion, is the way i have it below works on one Form
but does not on another. I made your changes and it still does not work on
the second.

Thanks

Douglas J. Steele said:
You need to take the reference to the form control outside of the quotes. As
well, since the UserName is (presumably) a Text field, you need to put
quotes around the value:

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName="""
& Forms!EHSRNew!Cuser & """") Then

That's four double quotes before the reference, and four double quotes
after. Ordinarily, I would use a single quote as the delimiter, but I wasn't
sure whether UserName was a real name (so that it might include apostrophes,
as in O'Reilly). If it can't include apostrophes, you can use

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName='"
& Forms!EHSRNew!Cuser & "'") Then

Exagerated for clarity, that's

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName= '
" & Forms!EHSRNew!Cuser & " ' ") Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DDrowe said:
I want signature blocks on my form only accessible to the person who signed
in. I have user level security so the person must sign in to have access
to
the form but beyond that I only want that person to be able to fill
his/her
name in, in their spot only to show agreement - electronic signature. I
have
this on one form but cant duplicate it on the second. This is what was
used
on the first - as best I can tell.

Private Sub Signature_BeforeUpdate(Cancel As Integer)
Dim Response As String
Response = InputBox("Enter Password", "Password Required")
If Response <> DLookup("[Password]", "tblSignaturePasswords",
"UserName=Forms!EHSRNew!Cuser") Then
Beep
MsgBox "Incorrect Password.", vbOKOnly, "Entry Denied"
Cancel = True
Signature.Undo
End If
End Sub

and

Private Sub Form_Current()
If CUser = "Drowe" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = True
Signature_6_.Visible = False
ElseIf CUser = "John Cefola" Then
Signature.Visible = True
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = False
Signature_6_.Visible = False
ElseIf CUser = "Jarod Craig" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = True
Signature_5_.Visible = False
Signature_6_.Visible = False
EndIf
EndSub
 
D

Douglas J. Steele

"does not work" doesn't give much to go by...

One thing I noticed is that you're comparing to the result of the DLookup.
If there isn't a password for the user, DLookup will return Null, and
comparing anything to Null results in False. You should use the Nz function
to handle the possibility of Null values:

If Response <> Nz(DLookup("[Password]", "tblSignaturePasswords",
"UserName=""" & Forms!EHSRNew!Cuser & """"), "") Then

Another alternative is just to concatenate a zero-length string to the
result of the DLookup so that it won't be Null:

If Response <> (DLookup("[Password]", "tblSignaturePasswords",
"UserName=""" & Forms!EHSRNew!Cuser & """") & vbNullString) Then



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DDrowe said:
I guess my biggest confusion, is the way i have it below works on one Form
but does not on another. I made your changes and it still does not work
on
the second.

Thanks

Douglas J. Steele said:
You need to take the reference to the form control outside of the quotes.
As
well, since the UserName is (presumably) a Text field, you need to put
quotes around the value:

If Response <> DLookup("[Password]", "tblSignaturePasswords",
"UserName="""
& Forms!EHSRNew!Cuser & """") Then

That's four double quotes before the reference, and four double quotes
after. Ordinarily, I would use a single quote as the delimiter, but I
wasn't
sure whether UserName was a real name (so that it might include
apostrophes,
as in O'Reilly). If it can't include apostrophes, you can use

If Response <> DLookup("[Password]", "tblSignaturePasswords",
"UserName='"
& Forms!EHSRNew!Cuser & "'") Then

Exagerated for clarity, that's

If Response <> DLookup("[Password]", "tblSignaturePasswords", "UserName=
'
" & Forms!EHSRNew!Cuser & " ' ") Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


DDrowe said:
I want signature blocks on my form only accessible to the person who
signed
in. I have user level security so the person must sign in to have
access
to
the form but beyond that I only want that person to be able to fill
his/her
name in, in their spot only to show agreement - electronic signature.
I
have
this on one form but cant duplicate it on the second. This is what was
used
on the first - as best I can tell.

Private Sub Signature_BeforeUpdate(Cancel As Integer)
Dim Response As String
Response = InputBox("Enter Password", "Password Required")
If Response <> DLookup("[Password]", "tblSignaturePasswords",
"UserName=Forms!EHSRNew!Cuser") Then
Beep
MsgBox "Incorrect Password.", vbOKOnly, "Entry Denied"
Cancel = True
Signature.Undo
End If
End Sub

and

Private Sub Form_Current()
If CUser = "Drowe" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = True
Signature_6_.Visible = False
ElseIf CUser = "John Cefola" Then
Signature.Visible = True
Signature_2_.Visible = False
Signature_3_.Visible = False
Signature_5_.Visible = False
Signature_6_.Visible = False
ElseIf CUser = "Jarod Craig" Then
Signature.Visible = False
Signature_2_.Visible = False
Signature_3_.Visible = True
Signature_5_.Visible = False
Signature_6_.Visible = False
EndIf
EndSub
 

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