Link to home
Start Free TrialLog in
Avatar of marksmall
marksmall

asked on

code problem

the code below doesn't seem to work properly!  
if the user has "Admin" selected in the table then it works but
if "Admin" is not selected then none of the buttons are visible
that should be!

i am trying to create different types of access to a form. Ie
admin - has FULL access
DeleteAccess - where user can delete, add, update a record
WriteAccess - where a user can only add, update a record

Function AllowAccess()

   If IsAdmin = False Then
      cmdDelete.Visible = False
      cmdUpdate.Visible = False
      cmdNew.Visible = False
      Call LockRecords
      lblNotice.Caption = ""
      lblNotice.Visible = False

   Else
       
      If IsAdmin = True Then
        cmdDelete.Visible = True
        cmdUpdate.Visible = True
        cmdNew.Visible = True
        Call UnlockRecords
        lblNotice.Caption = "Administrator Access, Read, Write, Delete!"
        lblNotice.Visible = True
      Else

         If WriteAccess = False Then
            cmdDelete.Visible = False
            cmdUpdate.Visible = False
            cmdNew.Visible = False
            Call LockRecords
            lblNotice.Caption = "Read Access Only!"
            lblNotice.Visible = True

         Else
               
            If WriteAccess = True Then
               cmdDelete.Visible = False
               cmdUpdate.Visible = True
               cmdNew.Visible = True
               Call UnlockRecords
               lblNotice.Caption = "Read, Write, Update access!"
               lblNotice.Visible = True

            Else
                   
               If DeleteAccess = False Then
                  cmdDelete.Visible = False
                  cmdUpdate.Visible = True
                  cmdNew.Visible = True
                  Call UnlockRecords
                  lblNotice.Caption = "Read, Write, Update access!"
                  lblNotice.Visible = True

               Else
                       
                  If DeleteAccess = True Then
                     cmdDelete.Visible = True
                     cmdUpdate.Visible = True
                     cmdNew.Visible = True
                     Call UnlockRecords
                     lblNotice.Caption = "Read, Write, Update, Delete access!"
                     lblNotice.Visible = True
                  End If
               End If
            End If
         End If
      End If
   End If

End Function

the fields in the table are as follows, i have already connected to the table with the following variables

IsAdmin
WriteAccess
DeleteAccess

table fields

username
password
admin - checkbox - true/false
DeleteAccess - checkbox - true/false
WriteAccess - checkbox - true/false

cheers
Avatar of Mike McCracken
Mike McCracken

Are the buttons mutually exclusive?

Try this

Function AllowAccess()

     If IsAdmin = True Then
       cmdDelete.Visible = True
       cmdUpdate.Visible = True
       cmdNew.Visible = True
       Call UnlockRecords
       lblNotice.Caption = "Administrator Access, Read, Write, Delete!"
       lblNotice.Visible = True
 
     Else If WriteAccess = True Then
          cmdDelete.Visible = False
          cmdUpdate.Visible = True
          cmdNew.Visible = True
          Call UnlockRecords
          lblNotice.Caption = "Read, Write, Update access!"
          lblNotice.Visible = True

     Else If DeleteAccess = True Then
           cmdDelete.Visible = True
           cmdUpdate.Visible = True
           cmdNew.Visible = True
           Call UnlockRecords
           lblNotice.Caption = "Read, Write, Update, Delete access!"
           lblNotice.Visible = True
     End If

The way you have it If they don't have admin access then the first all are turned off but the others aren't checked

Remember

If  IsAdmin = False  then
   This gets done
Else  
   This is done only if isAdmin is true
endif

good luck
mlmcc

Avatar of marksmall

ASKER

what do you mean by mutually exclusive?

what about the, if IsAdmin  = false statements etc

do i have to include them with the code you specified?
Your if-nesting logic is somewhat screw'ed up.
Here is a sample logic :

If IsAdmin Then
  ' Admin
Else
  If WriteAccess Then
    If DeleteAccess Then
      ' Assume Delete access requires Write...
    EndIf
  Else
    ' Read access by default !
  EndIf
EndIf
If IsAdmin Then
 ' Admin
Else
 If WriteAccess Then
   If DeleteAccess Then
     ' Assume Delete access requires Write...
   Else
     ' Write access
   EndIf
 Else
   ' Read access by default !
 EndIf
EndIf
The (first) actual error in your code is

  If IsAdmin = False Then
    ' Well here we are if admin is false, ok
  Else
     If IsAdmin = True Then
       ' Here we will allways be since (admin wasnt false), and none of the other if's are executed...
Mutually exclusive means a record can have only one check.  For example if a person has Admin he doesn't have DeleteAccess or WriteAccess.

You don't have to include the tests for false because these turn off permissions that may be needed by a person with other permissiions.  For example

  If a person has admin then a test for WriteAccess=False will turn off the WriteAccess permissions.

What you should do is default permissions off and then test for granted permissions and turn on the permissions granted.

The order I tested in tests first for the greatest permissions then the next etc.  In this way if the permissiions aren't mutually exclusive the person will be granted the highest level he has.

If you need a better explanation just ask.

Hope this helps
mlmcc
first of all mlmcc , your code that you specified works ok, but i tried to add this code below it to check if BOTH Delete and Write access is selected but it will not work!

Else
                        If DeleteAccess = True And WriteAccess = True Then
                        cmdDelete.Visible = True
                        cmdUpdate.Visible = True
                        cmdNew.Visible = True
                        Call UnlockRecords
                        lblAdminNotice.Caption = "Read, Write, Update, Delete access!"
                        lblAdminNotice.Visible = True


here is what i am trying to do!


if Admin is selected then that user has BOTH Delete and Write access and other stuff (Don't need to worry about that in this form!)

if write access is seletced then all buttons are shown EXCEPT the delete one (cmdDelete)

if delete access is selected then all buttons are hiden EXCEPT the delete one (cmdDelete)

if BOTH delete access and write access are selected then ALL buttons are shown! (this is where i am having the PROBLEM!)

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

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
Hi marksmall,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mlmcc's comment(s) as an answer.

marksmall, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

Computer101
E-E Admin