If then statements

G

Guest

I have been working on the one problem all day and am ready to pull my hair
out. If I comment out the if stetements it works fine. But when I leave them
in it will not validate [usertemp]. The field is being populated by
=User.column(2) which displays either "admin" or "Support". Any suggestions?

Private Sub PW_AfterUpdate()
'Check value of password in PW to see if this matches value chosen in combo
box

If Me.PW.Value = DLookup("PW", "PW", "[Key]=" & Me.User.Value) Then

User = Me.PW.Value

'Complete required procedure
If [usertemp] = "Support" Then

Forms![Personnel]![SSN].Visible = True
Forms![Personnel]!AddMember.Visible = True
Support.Visible = True
[Authorize Purchase].Visible = True
End If

If Forms![Personnel].PW = "Admin" Then
EPR.Visible = True
Me.AllowDeletions = True
End If

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid
Entry!"
Me.PW.SetFocus
End If

End Sub
 
C

Crystal

Hi Darrin,

Is KEY a text field? If so, you need delimiters here:

DLookup("PW", "PW", "[Key]='" & Me.User & "'")

(Value is the default property, you don't need to specify it)

also, since you are making assignments to another form, ie:
Forms![Personnel]![SSN].Visible = True

you may need to follow the statements with
DoEvents

that will make changes show up right away

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
G

Guest

Thanks for the tip. The strange thing is everything is on the same form. I do
have a tab control and several sub forms included on it. I will try the
doevents.

Crystal said:
Hi Darrin,

Is KEY a text field? If so, you need delimiters here:

DLookup("PW", "PW", "[Key]='" & Me.User & "'")

(Value is the default property, you don't need to specify it)

also, since you are making assignments to another form, ie:
Forms![Personnel]![SSN].Visible = True

you may need to follow the statements with
DoEvents

that will make changes show up right away

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com


I have been working on the one problem all day and am ready to pull my hair
out. If I comment out the if stetements it works fine. But when I leave them
in it will not validate [usertemp]. The field is being populated by
=User.column(2) which displays either "admin" or "Support". Any suggestions?

Private Sub PW_AfterUpdate()
'Check value of password in PW to see if this matches value chosen in combo
box

If Me.PW.Value = DLookup("PW", "PW", "[Key]=" & Me.User.Value) Then

User = Me.PW.Value

'Complete required procedure
If [usertemp] = "Support" Then

Forms![Personnel]![SSN].Visible = True
Forms![Personnel]!AddMember.Visible = True
Support.Visible = True
[Authorize Purchase].Visible = True
End If

If Forms![Personnel].PW = "Admin" Then
EPR.Visible = True
Me.AllowDeletions = True
End If

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid
Entry!"
Me.PW.SetFocus
End If

End Sub
 
C

Crystal

Hi Darrin,

if you are in the code behind the form, you can do this:

me.[SSN].Visible = True

this is a more direct way

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com


Thanks for the tip. The strange thing is everything is on the same form. I do
have a tab control and several sub forms included on it. I will try the
doevents.

:

Hi Darrin,

Is KEY a text field? If so, you need delimiters here:

DLookup("PW", "PW", "[Key]='" & Me.User & "'")

(Value is the default property, you don't need to specify it)

also, since you are making assignments to another form, ie:
Forms![Personnel]![SSN].Visible = True

you may need to follow the statements with
DoEvents

that will make changes show up right away

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com


I have been working on the one problem all day and am ready to pull my hair
out. If I comment out the if stetements it works fine. But when I leave them
in it will not validate [usertemp]. The field is being populated by
=User.column(2) which displays either "admin" or "Support". Any suggestions?

Private Sub PW_AfterUpdate()
'Check value of password in PW to see if this matches value chosen in combo
box

If Me.PW.Value = DLookup("PW", "PW", "[Key]=" & Me.User.Value) Then

User = Me.PW.Value

'Complete required procedure
If [usertemp] = "Support" Then

Forms![Personnel]![SSN].Visible = True
Forms![Personnel]!AddMember.Visible = True
Support.Visible = True
[Authorize Purchase].Visible = True
End If

If Forms![Personnel].PW = "Admin" Then
EPR.Visible = True
Me.AllowDeletions = True
End If

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid
Entry!"
Me.PW.SetFocus
End If

End Sub
 

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

Similar Threads

Show all records event 1
ByPass key ms access 2016 0
Two if statements in Form Current code 4
changing password to **** 4
Unprotect entire sheet 1
Users log 4
Lock records against edits 3
Can't get code to run 3

Top