Link to home
Start Free TrialLog in
Avatar of urjudo
urjudoFlag for United States of America

asked on

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

Thanks
Avatar of urjudo
urjudo
Flag of United States of America image

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Nick67
Nick67
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of urjudo

ASKER

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
Me.PDNOTES
Me.Combo43
Me.PDRETURNED
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.