Code on Current in form

Hi Experts,
I have a code on current in a form, but it does do part of my request not the whole requested, I could not figure out why.  Below is my code.

If ((Not IsNull(Me.PDNOTES) And Me.Combo43 <> "Y") And (Me.PDNOTES <> "" And Me.Combo43 <> "Y")) Or ((Not IsNull(Me.PDNOTES) And Me.PDRETURNED <> "Y") And (Me.PDNOTES <> "" And Me.PDRETURNED <> "Y")) Then
       If stSecurity > 1 Then
          Me.PDNOTES.Locked = False
          Me.Command126.Enabled = False
          Me.PDNOTES.Locked = True
          Me.Command126.Enabled = True
      End If
    End If

I have a form that have field:  Rejected (combo43), field : Returned (Returned), field: PDNotes (memo field), and a Button "add Additional Note"   Both Rejected and Returned are combo box with "Y" or "N"

I also assigned users in different level.  Level 1 users are limited entry.  above Level 1 then has full entry.

what I want to do is in this form, I would like to do is:
for Level 1 Users:
   a). if either Rejected or Returned is Null or "N" and PDNotes field is null then they can add note in the PDNotes field and the
         Button "Add Additional Notes" will be gray out.
   b). if either Rejected or Returned is Null or "N" and PDNotes field is not null then the PDNotes field should be lock and they have to
        click the "Add additional Notes" button to add notes
For Level 2 or above users:
       No matter the Rejected or Returned or PDNotes  is null or not null , they can always enter in the PDNotes field and the "Add
      Additional Notes should always gray out.

My code above only does  part of them not all.  
It does not work for Level 1 user is :  they still can type in the PDNotes fields when there is Notes already there previously.  It should be lock the PDnotes field but it does not.

it does not work for Level 2 User is :  the "Add Additional Notes" button still enable not gray out.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

urjudoAuthor Commented:
make is simple, the code I sent only does for stSecurity > 1 is PDnotes is fine but the command126 still enable
for stSecurity = 1 the command button is fine but the PDnotes did not lock
That's a gross bit of logic.
But first things first
Nz() is your friend

((Not IsNull(Me.PDNOTES) And Me.Combo43 <> "Y") And (Me.PDNOTES <> "" And Me.Combo43 <> "Y"))
(Nz(Me.PDNOTES,"") <>"" And Me.Combo43 <> "Y")

((Not IsNull(Me.PDNOTES) And Me.PDRETURNED <> "Y") And (Me.PDNOTES <> "" And Me.PDRETURNED <> "Y"))
(Nz(Me.PDNOTES,"")<>"" And Me.PDRETURNED <> "Y")

Which is simpler

But that really isn't the way to tackle stuff like this

Select Case True is extremely elegant.
You put your most specific cases at the top, and general cases at the bottom
The first thing that evaluates TRUE gets done

Dim MyBoolean as Boolean

Select Case True
    Case stSecurity = 1
          MyBoolean = true 'low level can't edit
    Case Me.Combo43 = "Y" AND Me.PDRETURNED = "Y" 'no edits permitted
          MyBoolean = true
    Case Nz(Me.PDNOTES,"") <> "" And Me.Combo43 <> "Y" ' this scenario exists
          MyBoolean = false
    Case Nz(Me.PDNOTES,"") <>"" And Me.PDRETURNED <> "Y" ' this scenario exists
          MyBoolean = false

'you need to create the cases for what you want when Nz(Me.PDNOTES,"") = "" and for Nz(Me.PDNOTES,"")  = ""
'and all the other possibilities
'most restrictive higher in the structure than the more general 
    Case Else
          MyBoolean = true
End Select
Me.PDNOTES.Locked = myBoolean
Me.Command126.Enabled = myBoolean

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
urjudoAuthor Commented:
so there is no way to use as simple as the one I sent?
so there is no way to use as simple as the one I sent?
It isn't simple
It is hideous.
You are trying to check four conditions, the values of
and stSecurity
In a single block
2^4 is 16 possibilities.
Even by removing stSecurity you still have 8 possibilities left.
The OR grabs some of them, but you have no default in the outer IF

You haven't specified what is to happen if
(Nz(Me.PDNOTES,"") <>"" And Me.Combo43 <> "Y")  OR (Nz(Me.PDNOTES,"")<>"" And Me.PDRETURNED <> "Y")  
is false.

You also haven't forced the controls to a default state before the code executes
What do you want to happen if an error prevents the complicated part of this code from running.

Big, ugly, nested, multiple-logical-operation are a bear to write, create, debug and maintain.
You are discovering that.

What I gave you is the simplest way to tackle a very complex logic.
I would also add to that, having fields named Combo43 and Command126 is sloppy.  ALWAYS give controls a proper Name property so that the code makes sense as you read it.  No points are awarded for making dense, complex, compound If statements.  By spreading out the logic and nesting the Ifs or using case statements, you can easily tell that you've missed a significant number of potential conditions.  Even the Case statement Nick created doesn't do it.  It just makes your If easier to read.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.